[Haskell-cafe] Infix and postfix operators in Parsec

Xinyu Jiang fnnirvana at gmail.com
Fri Feb 12 11:30:23 EST 2010


I'm writing a parser for a Haskell-style language, and when I need to use
the same symbol for infix, prefix and postfix operators, the combinator
"buildExpressionParser" seems not to work as intended. For example, in:

(1)x + y
(2)x +
(3)+ x

If I set the priority of the postfix version of "+" to be higher than the
infix version, the parser cannot recognize (1), for it stops at the end of
"x +". And if the priority of postfix "+" is lower, Parsec complains about
(2) by returning an error message which expects something after "+".

Is there some way to get over this problem, and let me be able to still
benifit from the expression mechanism in Parsec. Or should I write these
stuff from scratch? Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100212/1b2c9409/attachment.html


More information about the Haskell-Cafe mailing list