git.iko.soy/typeable/attoparsec
on master help sign in
Clarify docs about use of 'try' combinator
commitdca4dc788eb75f1fa34146896e9a271e041d3897 authorDavid Luposchainsky <dluposchainsky@gmail.com> dateThu 6 Feb 2014, 22:49 (13 years ago) parent7e7dc1f
1 file changed+8−3
Data/Attoparsec/Combinator.hs+8−3
Data/Attoparsec/Combinator.hs+8−3
@@ -167,7 +167,9 @@ sepBy1' p s = scan
167167-- > simpleComment = string "<!--" *> manyTill anyChar (try (string "-->"))
168168--
169169-- Note the overlapping parsers @anyChar@ and @string \"<!--\"@, and
170−-- therefore the use of the 'try' combinator.
170+-- therefore the use of the 'try' combinator. (This is not strictly required
171+-- because Attoparsec backtracks automatically, but recommended anyway for
172+-- compatibility with Parsec.)
171173manyTill :: Alternative f => f a -> f b -> f [a]
172174manyTill p end = scan
173175 where scan = (end *> pure []) <|> liftA2 (:) p scan
@@ -185,8 +187,11 @@ manyTill p end = scan
185187-- > simpleComment = string "<!--" *> manyTill' anyChar (try (string "-->"))
186188--
187189-- Note the overlapping parsers @anyChar@ and @string \"<!--\"@, and
188−-- therefore the use of the 'try' combinator. The value returned by @p@
189−-- is forced to WHNF.
190+-- therefore the use of the 'try' combinator. (This is not strictly required
191+-- because Attoparsec backtracks automatically, but recommended anyway for
192+-- compatibility with Parsec.)
193+--
194+-- The value returned by @p@ is forced to WHNF.
190195manyTill' :: (MonadPlus m) => m a -> m b -> m [a]
191196manyTill' p end = scan
192197 where scan = (end >> return []) `mplus` liftM2' (:) p scan