[Haskell-cafe] Why is Megaparsec treating these two operators differently?

Brandon Allbery allbery.b at gmail.com
Sun Oct 23 21:03:06 UTC 2016


On Sun, Oct 23, 2016 at 4:15 PM, Jeffrey Brown <jeffbrown.the at gmail.com>
wrote:

>       [ [ InfixN # symbol "#" *> pure (Pair) ]
>       , [ InfixN # symbol "##" *> pure (Pair) ]
>       ]
>

Combinator parsers can't rearrange themselves to do longest token matching.
So the ## operator will take the first case, match against `symbol "#"` and
aOperator will succeed; the the next token match will hit the unconsumed
"#" and fail. If you place "##" first then it will match "##" but not "#",
which would the match the second rule.

-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20161023/87c6b4fa/attachment.html>


More information about the Haskell-Cafe mailing list