[Haskell-cafe] parsec manyTill documentation question

Evan Laforge qdunkan at gmail.com
Sat Sep 25 00:30:18 EDT 2010

[ sorry, forgot reply to all ]

>> simpleComment = do{ string "<!--"
>>                   ; manyTill anyChar (try (string "-->"))
>>                   }
>> Note the overlapping parsers anyChar and string "<!--", and
>> therefore the use of the try combinator.
> First, I would have expected it to instead say:
> Note the overlapping parsers anyChar and string "-->", ...

Yes, I think the doc just made a mistake there.  In fact, it looks
like the same mistake is in the current doc at

> Second, manyTill, by definition, keeps applying p (anyChar) until
> end (string "-->") is satisfied, so I would expect one could just
> write:
> manyTill anyChar (string "-->")

The problem is that "-->" has multiple characters.  So if you have
"-not end comment", it will match the '-' against the (string "-->").
Since it doesn't backtrack by default, it's committed now and will
fail when it hits the 'n'.  The 'try' will make it backtrack to
'anyChar' when the second '-' fails to match.

> (If anyone knows of a collection of parsec demos or good examples, I
> would appreciate a link; thanks)

I thought the parsec source included some example parsers for simple
languages?  In any case, there is lots of material floating around,
though I found parsec so intuitive and the docs so good that I just
started hacking.  I think the 'build scheme in haskell' tutorial uses
parsec for the parsing.

More information about the Haskell-Cafe mailing list