[Haskell-cafe] parsec manyTill documentation question

Peter Schmitz ps.haskell at gmail.com
Mon Sep 27 17:22:19 EDT 2010

On Fri, Sep 24, 2010 at 9:28 PM, Evan Laforge <qdunkan at gmail.com> wrote:
>>> 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
> http://hackage.haskell.org/packages/archive/parsec/3.1.0/doc/html/Text-Parsec-Combinator.html

Thanks very much for the typo confirmation, the explanation about
backtracking below, and the tip about the source distribution for the
I need to remember that multiple char strings imply backtracking, and
that backtracking is not the default, hence "try". Thanks.
-- Peter

>> 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