Peter Schmitz
2010-09-25 03:46:43 UTC
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.)
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)
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.)
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
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:(manyTill p end) applies parser p zero or more times until parser
end succeeds. Returns the list of values returned by p . This parser
simpleComment = do{ string "<!--"
; manyTill anyChar (try (string "-->"))
}
Note the overlapping parsers anyChar and string "<!--", and
therefore the use of the try combinator.
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)