@@ -240,7 +240,7 @@ import qualified Streamly.Internal.Data.Parser.ParserK.Type as K
240-- >>> import Control.Applicative ((<|>))
240-- >>> import Control.Applicative ((<|>))
241-- >>> import qualified Streamly.Prelude as Stream
241-- >>> import qualified Streamly.Prelude as Stream
242-- >>> import qualified Streamly.Internal.Data.Stream.IsStream as Stream (parse, parseMany)
242-- >>> import qualified Streamly.Internal.Data.Stream.IsStream as Stream (parse, parseMany)
243−-- >>> import qualified Streamly.Data.Fold as Fold
243+-- >>> import qualified Streamly.Internal.Data.Fold as Fold
244-- >>> import qualified Streamly.Internal.Data.Parser as Parser
244-- >>> import qualified Streamly.Internal.Data.Parser as Parser
246-------------------------------------------------------------------------------
246-------------------------------------------------------------------------------
@@ -1257,22 +1257,26 @@ manyThen _parser _recover _f = undefined
1257-- front of the pattern. When a match occurs we need to emit the accumulator of
1257-- front of the pattern. When a match occurs we need to emit the accumulator of
1258-- all the three parsers. One parser can count the line numbers to provide the
1258-- all the three parsers. One parser can count the line numbers to provide the
1259-- line number info.
1259-- line number info.
1261+-- XXX rename this to intercalate
1261-- | Apply two parsers alternately to an input stream. The input stream is
1262-- | Apply two parsers alternately to an input stream. The input stream is
1262-- considered an interleaving of two patterns. The two parsers represent the
1263-- considered an interleaving of two patterns. The two parsers represent the
1263-- two patterns.
1264-- two patterns.
1265-- This undoes a "gintercalate" of two streams.
1266-- This undoes a "gintercalate" of two streams.
1267−-- /Unimplemented/
1268+-- /Pre-release/
1269{-# INLINE deintercalate #-}
1270{-# INLINE deintercalate #-}
1270−deintercalate ::
1271+deintercalate :: MonadCatch m =>
1271− -- Monad m =>
1272+ Fold m (Either x y) z
1272− Fold m a y -> Parser m x a
1273+ -> Parser m a x
1273− -> Fold m b z -> Parser m x b
1274+ -> Parser m a y
1274− -> Parser m x (y, z)
1275+ -> Parser m a z
1275−deintercalate = undefined
1276+deintercalate sink contentL contentR =
1279+ sink (D.fromParserK contentL) (D.fromParserK contentR)
1277-- | Parse items separated by a separator parsed by the supplied parser. At
1281-- | Parse items separated by a separator parsed by the supplied parser. At
1278-- least one item must be present for the parser to succeed.
1282-- least one item must be present for the parser to succeed.
@@ -1293,6 +1297,7 @@ sepBy1 sink p sep = do
1293-- run, when it is done content parser is run again and so on. If none of the
1297-- run, when it is done content parser is run again and so on. If none of the
1294-- parsers consumes an input then parser returns a failure.
1298-- parsers consumes an input then parser returns a failure.
1300+-- >>> sepBy sink = Parser.deintercalate (Fold.lefts sink)
1296-- >>> sepBy sink content sep = Parser.sepBy1 sink content sep <|> return mempty
1301-- >>> sepBy sink content sep = Parser.sepBy1 sink content sep <|> return mempty
1298{-# INLINE sepBy #-}
1303{-# INLINE sepBy #-}
@@ -1300,6 +1305,7 @@ sepBy :: MonadCatch m =>
1300 Fold m b c -> Parser m a b -> Parser m a x -> Parser m a c
1305 Fold m b c -> Parser m a b -> Parser m a x -> Parser m a c
1301sepBy sink content sep =
1306sepBy sink content sep =
1302 D.toParserK $ D.sepBy sink (D.fromParserK content) (D.fromParserK sep)
1307 D.toParserK $ D.sepBy sink (D.fromParserK content) (D.fromParserK sep)
1308+-- sepBy sink = deintercalate (FL.lefts sink)
1304-------------------------------------------------------------------------------
1310-------------------------------------------------------------------------------
1305-- Interleaving a collection of parsers
1311-- Interleaving a collection of parsers