The documentation for Parsec.Expr.buildExpressionParser
says:
Prefix and postfix operators of the same precedence can only occur once (i.e. --2 is not allowed if - is prefix negate).
and indeed, this is biting me, since the language I am trying to parse allows arbitrary repetition of its prefix and postfix operators (think of a C expression like **a[1][2]
).
So, why does Parsec
make this restriction, and how can I work around it?
I think I can move my prefix/postfix parsers down into the term
parser since they have the highest precedence.
i.e.
**a + 1
is parsed as
(*(*(a)))+(1)
but what could I have done if I wanted it to parse as
*(*((a)+(1)))
if buildExpressionParser
did what I want, I could simply have rearranged the order of the operators in the table.
Note See here for a better solution