Helllo, I have the following syntax:
<attribute_value> ::= <spec_constant> | <symbol> | ( <s_expr>*)
<attribute> ::= <keyword> | <keyword> <attribute_value>
by reading a tutorial, it says it's possible to use buildExpressionParser
and it will perform Left-factoring, but there isn't an example.
Can someone give me an example on how i should parse the above syntax using Parsec or just point me in the right direction ?
Thank you for any help you can give.
<attribute>
how does the parser knows which path to take between<keyword>
and<keyword> <attribute_value>
? – Rogerp062try
to allow the parser to backtrack over the<keyword>
if it doesn't find the<attribute_value>
, or make the<attribute_value>
optional, and remove the<keyword>
-only branch. – patattribute = keyword *> (attributeValue <|> pure defaultValue)
. See the section entitled Backtracking and its discontents in chapter 16 of Real World Haskell for an example of this. – jub0bs