[Haskell-cafe] Why is Megaparsec treating these two operators differently?
allbery.b at gmail.com
Sun Oct 23 21:50:16 UTC 2016
Aha. I had forgotten some details.
If you want to have an operator that is a prefix of another operator in the
> table, use the following (or similar) wrapper instead of plain symbol:
> op n = (lexeme . try) (string n <* notFollowedBy punctuationChar)
So you actually need to be a little clever for those two operators to work;
it's not as simple as I had recalled it (which would have been correct for
a basic manual combinator setup). I am going to guess that something in
there is not using `try` and silently consuming the extra "#", but I'd have
to study the `makeExprParser` code in Megaparsec to be certain.
On Sun, Oct 23, 2016 at 5:38 PM, Jeffrey Brown <jeffbrown.the at gmail.com>
> Thanks, Brandon! How did you know that?
> I changed them to "#1" and "#2" and now it works.
> But before making that change, why would "a # b ## c # d" evaluate, even
> though "a ## b" would not?
>  https://github.com/JeffreyBenjaminBrown/digraphs-
> The corrected file is called "experim.hs"; the old one, uncorrected, is
> called "experim.buggy.hs".
> On Sun, Oct 23, 2016 at 2:03 PM, Brandon Allbery <allbery.b at gmail.com>
>> On Sun, Oct 23, 2016 at 4:15 PM, Jeffrey Brown <jeffbrown.the at gmail.com>
>>> [ [ 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
>> allbery.b at gmail.com
>> ballbery at sinenomine.net
>> unix, openafs, kerberos, infrastructure, xmonad
> Jeff Brown | Jeffrey Benjamin Brown
> Website <https://msu.edu/~brown202/> | Facebook
> <https://www.facebook.com/mejeff.younotjeff> | LinkedIn
> <https://www.linkedin.com/in/jeffreybenjaminbrown>(I often miss messages
> here) | Github <https://github.com/jeffreybenjaminbrown>
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...
More information about the Haskell-Cafe