I want to write a concrete grammar to parse BNF-like syntax definitions.
Looking at the EXP Concrete Syntax recipe I created this very simple first version:
module BNFParser
lexical Identifier = [a-z]+ ;
syntax GrammarRule = left RuleHead ":" RuleCase* ";" ;
syntax RuleHead = Identifier ;
syntax RuleCase = Identifier ;
and invoked it in the Repl like this:
import BNFParser;
import ParseTree;
parse(#GrammarRule, "foo : bar baz ;");
But this results in a rather arcane error message:
|std:///ParseTree.rsc|(13035,1963,<393,0>,<439,114>): ParseError(|unknown:///|(3,1,<1,3>,<1,4>))
at *** somewhere ***(|std:///ParseTree.rsc|(13035,1963,<393,0>,<439,114>))
at parse(|std:///ParseTree.rsc|(14991,5,<439,107>,<439,112>))
ok
I also tried using the start
keyword ahead of GrammarRule, but that didn't help. What am I doing wrong?
Ambiquity
error on the Kleene starRuleCase*
. Same with+
. Leaving both away I can parsefoo : bar;
ok. – ThomasH Feb 7 '20 at 15:08!>> [a-z]
to the end of the Identifier lexical rule. It says that the rule should not reduce unless there is no more a's to z's to consume. Rascal does no heuristic or implicit disambiguation like other parser/lexer generators do. You've to declare it all, but then you know exactly what you're dealing with 👍 – Jurgen Vinju Feb 7 '20 at 15:23SyntaxDefinition
concept page :-) . - Go ahead and make a 2-line answer, so I can upvote and accept it. – ThomasH Feb 7 '20 at 15:30