@@ -109,6 +109,7 @@ instance Functor ParseResult where
110newtype Parser a m b = MkParser
110newtype Parser a m b = MkParser
111 { runParser :: forall r.
111 { runParser :: forall r.
112+ (ParseResult b -> Int -> Input a -> m (Step a m r))
112 -- XXX Maintain and pass the original position in the stream. that
113 -- XXX Maintain and pass the original position in the stream. that
113 -- way we can also report better errors. Use a Context structure for
114 -- way we can also report better errors. Use a Context structure for
114 -- passing the state.
115 -- passing the state.
@@ -120,7 +121,7 @@ newtype Parser a m b = MkParser
120 -- backtrack buffer. Positive value cannot be beyond array length.
121 -- backtrack buffer. Positive value cannot be beyond array length.
121 -- If the parser needs to advance beyond the array length it should
122 -- If the parser needs to advance beyond the array length it should
122 -- use "Continue +n".
123 -- use "Continue +n".
124 -- used elem count, a count of elements consumed by the parser. If
125 -- used elem count, a count of elements consumed by the parser. If
125 -- an Alternative fails we need to backtrack by this amount.
126 -- an Alternative fails we need to backtrack by this amount.
@@ -129,7 +130,6 @@ newtype Parser a m b = MkParser
129 -- constructor of 'ParseResult'.
130 -- constructor of 'ParseResult'.
130 -- XXX Use Array a, determine eof by using a nil array
131 -- XXX Use Array a, determine eof by using a nil array
131 -> Input a
132 -> Input a
132− -> (ParseResult b -> Int -> Input a -> m (Step a m r))
133 -> m (Step a m r)
133 -> m (Step a m r)
@@ -144,9 +144,9 @@ type ParserK = Parser
145instance Functor m => Functor (Parser a m) where
145instance Functor m => Functor (Parser a m) where
146 {-# INLINE fmap #-}
146 {-# INLINE fmap #-}
147− fmap f parser = MkParser $ \n st arr pk ->
147+ fmap f parser = MkParser $ \k n st arr ->
148− let pk1 res = pk (fmap f res)
148+ let k1 res = k (fmap f res)
149− in runParser parser n st arr pk1
149+ in runParser parser k1 n st arr
151-------------------------------------------------------------------------------
151-------------------------------------------------------------------------------
152-- Sequential applicative
152-- Sequential applicative
@@ -160,7 +160,7 @@ instance Functor m => Functor (Parser a m) where
161{-# INLINE fromPure #-}
161{-# INLINE fromPure #-}
162fromPure :: b -> Parser a m b
162fromPure :: b -> Parser a m b
163−fromPure b = MkParser $ \n st arr pk -> pk (Success n b) st arr
163+fromPure b = MkParser $ \k n st arr -> k (Success n b) st arr
165-- | See 'Streamly.Internal.Data.Parser.fromEffect'.
165-- | See 'Streamly.Internal.Data.Parser.fromEffect'.
@@ -169,7 +169,7 @@ fromPure b = MkParser $ \n st arr pk -> pk (Success n b) st arr
169{-# INLINE fromEffect #-}
169{-# INLINE fromEffect #-}
170fromEffect :: Monad m => m b -> Parser a m b
170fromEffect :: Monad m => m b -> Parser a m b
171fromEffect eff =
171fromEffect eff =
172− MkParser $ \n st arr pk -> eff >>= \b -> pk (Success n b) st arr
172+ MkParser $ \k n st arr -> eff >>= \b -> k (Success n b) st arr
174-- | 'Applicative' form of 'Streamly.Internal.Data.Parser.splitWith'. Note that
174-- | 'Applicative' form of 'Streamly.Internal.Data.Parser.splitWith'. Note that
175-- this operation does not fuse, use 'Streamly.Internal.Data.Parser.splitWith'
175-- this operation does not fuse, use 'Streamly.Internal.Data.Parser.splitWith'
@@ -183,19 +183,19 @@ instance Monad m => Applicative (Parser a m) where
183 (<*>) = ap
183 (<*>) = ap
185 {-# INLINE (*>) #-}
185 {-# INLINE (*>) #-}
186− p1 *> p2 = MkParser $ \n st arr k ->
186+ p1 *> p2 = MkParser $ \k n st arr ->
187− let k1 (Success n1 _) s input = runParser p2 n1 s input k
187+ let k1 (Success n1 _) s input = runParser p2 k n1 s input
188 k1 (Failure n1 e) s input = k (Failure n1 e) s input
188 k1 (Failure n1 e) s input = k (Failure n1 e) s input
189− in runParser p1 n st arr k1
189+ in runParser p1 k1 n st arr
191 {-# INLINE (<*) #-}
191 {-# INLINE (<*) #-}
192− p1 <* p2 = MkParser $ \n st arr k ->
192+ p1 <* p2 = MkParser $ \k n st arr ->
193 let k1 (Success n1 b) s1 input =
193 let k1 (Success n1 b) s1 input =
194 let k2 (Success n2 _) = k (Success n2 b)
194 let k2 (Success n2 _) = k (Success n2 b)
195 k2 (Failure n2 e) = k (Failure n2 e)
195 k2 (Failure n2 e) = k (Failure n2 e)
196− in runParser p2 n1 s1 input k2
196+ in runParser p2 k2 n1 s1 input
197 k1 (Failure n1 e) s1 input = k (Failure n1 e) s1 input
197 k1 (Failure n1 e) s1 input = k (Failure n1 e) s1 input
198− in runParser p1 n st arr k1
198+ in runParser p1 k1 n st arr
200 {-# INLINE liftA2 #-}
200 {-# INLINE liftA2 #-}
201 liftA2 f p = (<*>) (fmap f p)
201 liftA2 f p = (<*>) (fmap f p)
@@ -213,7 +213,7 @@ instance Monad m => Applicative (Parser a m) where
214{-# INLINE die #-}
214{-# INLINE die #-}
215die :: String -> Parser a m b
215die :: String -> Parser a m b
216−die err = MkParser (\n st arr pk -> pk (Failure n err) st arr)
216+die err = MkParser (\k n st arr -> k (Failure n err) st arr)
218-- | Monad composition can be used for lookbehind parsers, we can make the
218-- | Monad composition can be used for lookbehind parsers, we can make the
219-- future parses depend on the previously parsed values.
219-- future parses depend on the previously parsed values.
@@ -262,10 +262,10 @@ instance Monad m => Monad (Parser a m) where
262 return = pure
262 return = pure
264 {-# INLINE (>>=) #-}
264 {-# INLINE (>>=) #-}
265− p >>= f = MkParser $ \n st arr pk ->
265+ p >>= f = MkParser $ \k n st arr ->
266− let pk1 (Success n1 b) s1 inp = runParser (f b) n1 s1 inp pk
266+ let k1 (Success n1 b) s1 inp = runParser (f b) k n1 s1 inp
267− pk1 (Failure n1 e) s1 inp = pk (Failure n1 e) s1 inp
267+ k1 (Failure n1 e) s1 inp = k (Failure n1 e) s1 inp
268− in runParser p n st arr pk1
268+ in runParser p k1 n st arr
270 {-# INLINE (>>) #-}
270 {-# INLINE (>>) #-}
271 (>>) = (*>)
271 (>>) = (*>)
@@ -306,11 +306,11 @@ instance Monad m => Alternative (Parser a m) where
306 empty = die "empty"
306 empty = die "empty"
308 {-# INLINE (<|>) #-}
308 {-# INLINE (<|>) #-}
309− p1 <|> p2 = MkParser $ \n _ arr k ->
309+ p1 <|> p2 = MkParser $ \k n _ arr ->
311− k1 (Failure pos _) used input = runParser p2 (pos - used) 0 input k
311+ k1 (Failure pos _) used input = runParser p2 k (pos - used) 0 input
312 k1 success _ input = k success 0 input
312 k1 success _ input = k success 0 input
313− in runParser p1 n 0 arr k1
313+ in runParser p1 k1 n 0 arr
315 -- some and many are implemented here instead of using default definitions
315 -- some and many are implemented here instead of using default definitions
316 -- so that we can use INLINE on them. It gives 50% performance improvement.
316 -- so that we can use INLINE on them. It gives 50% performance improvement.
@@ -422,12 +422,12 @@ parseDToK
422 => (s -> a -> m (ParserD.Step s b))
422 => (s -> a -> m (ParserD.Step s b))
423 -> m (ParserD.Initial s b)
423 -> m (ParserD.Initial s b)
424 -> (s -> m (ParserD.Step s b))
424 -> (s -> m (ParserD.Step s b))
425+ -> (ParseResult b -> Int -> Input a -> m (Step a m r))
427 -> Input a
428 -> Input a
428− -> (ParseResult b -> Int -> Input a -> m (Step a m r))
429 -> m (Step a m r)
429 -> m (Step a m r)
430−parseDToK pstep initial extract !offset !usedCount !input cont = do
430+parseDToK pstep initial extract cont !offset !usedCount !input = do
431 res <- initial
431 res <- initial
432 case res of
432 case res of
433 ParserD.IPartial pst -> do
433 ParserD.IPartial pst -> do