@@ -21,8 +21,7 @@ module Streamly.Internal.Data.Parser.ParserK.Type
22 , Input (..)
22 , Input (..)
23 , ParseResult (..)
23 , ParseResult (..)
24− , Parser (..)
24+ , ParserK (..)
26 , fromParser
25 , fromParser
27 -- , toParser
26 -- , toParser
28 , fromPure
27 , fromPure
@@ -111,7 +110,7 @@ instance Functor ParseResult where
111-- input without a result or return a result with no further input to be
110-- input without a result or return a result with no further input to be
112-- consumed.
111-- consumed.
114−newtype Parser a m b = MkParser
113+newtype ParserK a m b = MkParser
115 { runParser :: forall r.
114 { runParser :: forall r.
116 -- Using "Input" in runParser is not necessary but it avoids making
115 -- Using "Input" in runParser is not necessary but it avoids making
117 -- one more function call to get the input. This could be helpful
116 -- one more function call to get the input. This could be helpful
@@ -143,8 +142,6 @@ newtype Parser a m b = MkParser
143 -> m (Step a m r)
142 -> m (Step a m r)
146−type ParserK = Parser
148-------------------------------------------------------------------------------
145-------------------------------------------------------------------------------
149-- Functor
146-- Functor
150-------------------------------------------------------------------------------
147-------------------------------------------------------------------------------
@@ -152,7 +149,7 @@ type ParserK = Parser
152-- XXX rewrite this using ParserD, expose rmapM from ParserD.
149-- XXX rewrite this using ParserD, expose rmapM from ParserD.
153-- | Maps a function over the output of the parser.
150-- | Maps a function over the output of the parser.
155−instance Functor m => Functor (Parser a m) where
152+instance Functor m => Functor (ParserK a m) where
156 {-# INLINE fmap #-}
153 {-# INLINE fmap #-}
157 fmap f parser = MkParser $ \k n st arr ->
154 fmap f parser = MkParser $ \k n st arr ->
158 let k1 res = k (fmap f res)
155 let k1 res = k (fmap f res)
@@ -169,7 +166,7 @@ instance Functor m => Functor (Parser a m) where
169-- /Pre-release/
166-- /Pre-release/
171{-# INLINE fromPure #-}
168{-# INLINE fromPure #-}
172−fromPure :: b -> Parser a m b
169+fromPure :: b -> ParserK a m b
173fromPure b = MkParser $ \k n st arr -> k (Success n b) st arr
170fromPure b = MkParser $ \k n st arr -> k (Success n b) st arr
175-- | See 'Streamly.Internal.Data.Parser.fromEffect'.
172-- | See 'Streamly.Internal.Data.Parser.fromEffect'.
@@ -177,7 +174,7 @@ fromPure b = MkParser $ \k n st arr -> k (Success n b) st arr
177-- /Pre-release/
174-- /Pre-release/
179{-# INLINE fromEffect #-}
176{-# INLINE fromEffect #-}
180−fromEffect :: Monad m => m b -> Parser a m b
177+fromEffect :: Monad m => m b -> ParserK a m b
181fromEffect eff =
178fromEffect eff =
182 MkParser $ \k n st arr -> eff >>= \b -> k (Success n b) st arr
179 MkParser $ \k n st arr -> eff >>= \b -> k (Success n b) st arr
@@ -185,7 +182,7 @@ fromEffect eff =
185-- this operation does not fuse, use 'Streamly.Internal.Data.Parser.splitWith'
182-- this operation does not fuse, use 'Streamly.Internal.Data.Parser.splitWith'
186-- when fusion is important.
183-- when fusion is important.
188−instance Monad m => Applicative (Parser a m) where
185+instance Monad m => Applicative (ParserK a m) where
189 {-# INLINE pure #-}
186 {-# INLINE pure #-}
190 pure = fromPure
187 pure = fromPure
@@ -222,7 +219,7 @@ instance Monad m => Applicative (Parser a m) where
222-- /Pre-release/
219-- /Pre-release/
224{-# INLINE die #-}
221{-# INLINE die #-}
225−die :: String -> Parser a m b
222+die :: String -> ParserK a m b
226die err = MkParser (\k n st arr -> k (Failure n err) st arr)
223die err = MkParser (\k n st arr -> k (Failure n err) st arr)
228-- | Monad composition can be used for lookbehind parsers, we can make the
225-- | Monad composition can be used for lookbehind parsers, we can make the
@@ -267,7 +264,7 @@ die err = MkParser (\k n st arr -> k (Failure n err) st arr)
267-- does not fuse, use 'Streamly.Internal.Data.Parser.concatMap' when you need
264-- does not fuse, use 'Streamly.Internal.Data.Parser.concatMap' when you need
268-- fusion.
265-- fusion.
270−instance Monad m => Monad (Parser a m) where
267+instance Monad m => Monad (ParserK a m) where
271 {-# INLINE return #-}
268 {-# INLINE return #-}
272 return = pure
269 return = pure
@@ -286,11 +283,11 @@ instance Monad m => Monad (Parser a m) where
286 {-# INLINE fail #-}
283 {-# INLINE fail #-}
287 fail = die
284 fail = die
289−instance Monad m => Fail.MonadFail (Parser a m) where
286+instance Monad m => Fail.MonadFail (ParserK a m) where
290 {-# INLINE fail #-}
287 {-# INLINE fail #-}
291 fail = die
288 fail = die
293−instance MonadIO m => MonadIO (Parser a m) where
290+instance MonadIO m => MonadIO (ParserK a m) where
294 {-# INLINE liftIO #-}
291 {-# INLINE liftIO #-}
295 liftIO = fromEffect . liftIO
292 liftIO = fromEffect . liftIO
@@ -311,7 +308,7 @@ instance MonadIO m => MonadIO (Parser a m) where
311-- does not fuse, use 'Streamly.Internal.Data.Parser.alt' when you need
308-- does not fuse, use 'Streamly.Internal.Data.Parser.alt' when you need
312-- fusion.
309-- fusion.
314−instance Monad m => Alternative (Parser a m) where
311+instance Monad m => Alternative (ParserK a m) where
315 {-# INLINE empty #-}
312 {-# INLINE empty #-}
316 empty = die "empty"
313 empty = die "empty"
@@ -344,7 +341,7 @@ instance Monad m => Alternative (Parser a m) where
344-- | 'mzero' is same as 'empty', it aborts the parser. 'mplus' is same as
341-- | 'mzero' is same as 'empty', it aborts the parser. 'mplus' is same as
345-- '<|>', it selects the first succeeding parser.
342-- '<|>', it selects the first succeeding parser.
347−instance Monad m => MonadPlus (Parser a m) where
344+instance Monad m => MonadPlus (ParserK a m) where
348 {-# INLINE mzero #-}
345 {-# INLINE mzero #-}
349 mzero = die "mzero"
346 mzero = die "mzero"
@@ -352,7 +349,7 @@ instance Monad m => MonadPlus (Parser a m) where
352 mplus = (<|>)
349 mplus = (<|>)
355−instance MonadTrans (Parser a) where
352+instance MonadTrans (ParserK a) where
356 {-# INLINE lift #-}
353 {-# INLINE lift #-}
357 lift = fromEffect
354 lift = fromEffect
@@ -521,7 +518,7 @@ parserDone _ _ _ = error "Bug: toParser: called with input"
521-- /Pre-release/
518-- /Pre-release/
523{-# INLINE_LATE toParser #-}
520{-# INLINE_LATE toParser #-}
524−toParser :: Monad m => Parser a m b -> ParserD.Parser a m b
521+toParser :: Monad m => ParserK a m b -> ParserD.Parser a m b
525toParser parser = ParserD.Parser step initial extract
522toParser parser = ParserD.Parser step initial extract