I am introducing a new DSL in Marpa and (from Regexp :: Grammars), I am more than satisfied. My language supports a bunch of unary and binary operators, objects with C style identifiers, and method calls using familiar dot notation. For instance:
foo.has(bar == 42 AND baz == 23)
I found the priority rules offered by the grammatical description of the Marpa grammar language, and many of them rely on this, so I have almost one G1 Expression Rule. Excerpt (many alternatives and semantic actions are omitted for brevity):
Expression ::= NumLiteral | '(' Expression ')' assoc => group || Expression ('.') Identifier || Expression ('.') Identifier Args | Expression ('==') Expression || Expression ('AND') Expression Args ::= ('(') ArgsList (')') ArgsList ::= Expression+ separator => [,] Identifier ~ IdentifierHeadChar IdentifierBody IdentifierBody ~ IdentifierBodyChar* IdentifierHeadChar ~ [a-zA-Z_] IdentifierBodyChar ~ [a-zA-Z0-9_] NumLiteral ~ [0-9]+
As you can see, I am using the Scanless interface (SLIF). My problem is that it also parses, for example:
foo.AND(5)
Marpa knows that there can only be an identifier after a period, so he does not even think that AND can be a keyword. I know that I can avoid this problem by doing a separate lexing step that uniquely identifies AND as a keyword, but this tiny papercut is not worth the effort.
Is there a way in SLIF to restrict an Identifier rule to only identifiers without a keyword?
source share