[Haskell-cafe] Re: Parsec lookahead and <|>
Christian Maeder
Christian.Maeder at dfki.de
Fri Aug 21 07:51:42 EDT 2009
Daniel Fischer wrote:
>>> Bad bug in Parsec (from the beginning, the same happens in parsec-2), I'd
>>> say.
>> I'd say, its a feature. lookAhead returns whatever its argument returns.
>> So in this case it returns "Consumed" without consuming.
>
> In that case, the comment
>
> "lookAhead p parses p without consuming any input."
>
> from the parsec-3 docs is highly misleading.
Yes, it isn't even documented in http://legacy.cs.uu.nl/daan/parsec.html
I'ld say not consuming something after a successful lookAhead is an
error (and if the argument of lookAhead consumes nothing, that is also odd.)
In most cases "try" is the better alternative, where the result of try
should be used as input for the following parser:
(try identifierStart >>= indentifierRest) <|> constant
> But lookAhead returning Consumed is not only counterintuitive, try
>
> parseTest (many la) "a"
>
> for a nice memory bomb.
It's as dangerous as using "setInput" and making the input longer (for
recursive calls).
But I don't see any disadvantages if "lookAhead" would return "Empty (Ok
...)", so I'ld also propose to change it (as you did).
Cheers Christian
More information about the Haskell-Cafe
mailing list