[Haskell-cafe] parsec manyTill documentation question

Peter Schmitz ps.haskell at gmail.com
Fri Sep 24 23:46:43 EDT 2010


I am new to parsec and having difficulty understanding the
explanation of manyTill in
http://legacy.cs.uu.nl/daan/download/parsec/parsec.html.

(I really appreciate having this doc by the way; great reference.)

I.e.:

> manyTill :: GenParser tok st a -> GenParser tok st end -> GenParser tok st [a]
>
> (manyTill p end) applies parser p zero or more times until parser
> end succeeds. Returns the list of values returned by p . This parser
> can be used to scan comments:
>
> 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 "-->", ...

since anyChar begins reading input beginning with the char *after*
string "<!--". Use of anyChar here will potentially overlap with
what it is reading towards: (string "-->").

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

manyTill anyChar (string "-->")

Assuming the documentation is correct on both counts, I would really
appreciate any explanation someone could offer.

Thanks very much,  (really like Haskell & parsec)
-- Peter


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


More information about the Haskell-Cafe mailing list