[Haskell-cafe] An irritating Parsec problem

Jonathan Cast jonathanccast at fastmail.fm
Wed Oct 15 15:20:39 EDT 2008


On Wed, 2008-10-15 at 20:22 +0100, Andrew Coppin wrote:
> I like Parsec. I use it for everything. But it does have one irritating 
> problem.
> 
> Consider the following parser:
> 
>   expressions = many1 expression
> 
> Suppose this is the top-level parser for my language.

I always wrap my top-level parsers in

  return const `ap` parser `ap` eof

to express that they have to match the entire input.  (This is a bit
easier if you supply the missing Applicative instance:

  const <$> parser <*> eof

).  I think Parsec should either do this itself or tell you what the
un-consumed input tokens were, but it doesn't.

jcc




More information about the Haskell-Cafe mailing list