@@ -112,12 +112,17 @@
113module Streamly.Internal.Data.Parser.ParserD.Type
113module Streamly.Internal.Data.Parser.ParserD.Type
115 Initial (..)
116 Initial (..)
116 , Step (..)
117 , Step (..)
117 , Parser (..)
118 , Parser (..)
118 , ParseError (..)
119 , ParseError (..)
121 , fromPure
126 , fromPure
122 , fromEffect
127 , fromEffect
123 , serialWith
128 , serialWith
@@ -160,6 +165,7 @@ import Prelude hiding (concatMap)
160-- >>> import qualified Streamly.Prelude as Stream
165-- >>> import qualified Streamly.Prelude as Stream
161-- >>> import qualified Streamly.Internal.Data.Stream.IsStream as Stream (parse)
166-- >>> import qualified Streamly.Internal.Data.Stream.IsStream as Stream (parse)
162-- >>> import qualified Streamly.Internal.Data.Parser as Parser
167-- >>> import qualified Streamly.Internal.Data.Parser as Parser
168+-- >>> import qualified Streamly.Internal.Data.Parser.ParserD as ParserD
164-- XXX The only differences between Initial and Step types are:
170-- XXX The only differences between Initial and Step types are:
@@ -348,6 +354,30 @@ instance Functor m => Functor (Parser m a) where
348 step s b = fmap2 f (step1 s b)
354 step s b = fmap2 f (step1 s b)
349 fmap2 g = fmap (fmap g)
355 fmap2 g = fmap (fmap g)
357+------------------------------------------------------------------------------
358+-- General parser constructors
359+------------------------------------------------------------------------------
361+-- | Make a parser using a parsing step and a starting value.
365+{-# INLINE parser #-}
366+parser :: Monad m => (b -> a -> Step b b) -> Initial b b -> Parser m a b
367+parser step initial =
368+ Parser (\s a -> return $ step s a) (return initial) return
370+-- | Like 'parser' but with a monadic step function.
372+-- >>> parserM step initial = ParserD.Parser step initial return
376+{-# INLINE parserM #-}
378+ Monad m => (b -> a -> m (Step b b)) -> m (Initial b b) -> Parser m a b
379+parserM step initial = Parser step initial return
351------------------------------------------------------------------------------
381------------------------------------------------------------------------------
352-- Mapping on the output
382-- Mapping on the output
353------------------------------------------------------------------------------
383------------------------------------------------------------------------------