git.iko.soy/typeable/attoparsec
on master help sign in
Merge pull request #54 from quchen/master

Clarify docs about use of 'try' combinator

commit987c707ebbd164c079d6ac15d6a1032f9bba465e authorBryan O'Sullivan <bos@serpentine.com> dateFri 14 Feb 2014, 16:38 (13 years ago) parentc4bfb52dca4dc7
1 file changed+8−3
Data/Attoparsec/Combinator.hs+8−3
Data/Attoparsec/Combinator.hs+8−3
@@ -182,7 +182,9 @@ sepBy1' p s = scan
182182-- > simpleComment = string "<!--" *> manyTill anyChar (try (string "-->"))
183183--
184184-- Note the overlapping parsers @anyChar@ and @string \"<!--\"@, and
185−-- therefore the use of the 'try' combinator.
185+-- therefore the use of the 'try' combinator. (This is not strictly required
186+-- because Attoparsec backtracks automatically, but recommended anyway for
187+-- compatibility with Parsec.)
186188manyTill :: Alternative f => f a -> f b -> f [a]
187189manyTill p end = scan
188190 where scan = (end *> pure []) <|> liftA2 (:) p scan
@@ -198,8 +200,11 @@ manyTill p end = scan
198200-- > simpleComment = string "<!--" *> manyTill' anyChar (try (string "-->"))
199201--
200202-- Note the overlapping parsers @anyChar@ and @string \"<!--\"@, and
201−-- therefore the use of the 'try' combinator. The value returned by @p@
202−-- is forced to WHNF.
203+-- therefore the use of the 'try' combinator. (This is not strictly required
204+-- because Attoparsec backtracks automatically, but recommended anyway for
205+-- compatibility with Parsec.)
206+--
207+-- The value returned by @p@ is forced to WHNF.
203208manyTill' :: (MonadPlus m) => m a -> m b -> m [a]
204209manyTill' p end = scan
205210 where scan = (end >> return []) `mplus` liftM2' (:) p scan