@@ -40,6 +40,7 @@ import qualified Control.Monad.Fail as Fail
40#if !(MIN_VERSION_base(4,10,0))
40#if !(MIN_VERSION_base(4,10,0))
41import Data.Semigroup ((<>))
41import Data.Semigroup ((<>))
43+import Streamly.Internal.Control.Exception
44import qualified Streamly.Internal.Data.Parser.ParserD.Types as D
45import qualified Streamly.Internal.Data.Parser.ParserD.Types as D
@@ -205,6 +206,9 @@ data FromParserK b e c = FPKDone !Int !b | FPKError !e | FPKCont c
206-- | Convert a CPS style 'Parser' to a direct style 'D.Parser'.
207-- | Convert a CPS style 'Parser' to a direct style 'D.Parser'.
209+-- "initial" returns a continuation which can be called one input at a time
210+-- using the "step" function.
208-- /Internal/
212-- /Internal/
210{-# INLINE_LATE fromParserK #-}
214{-# INLINE_LATE fromParserK #-}
@@ -221,7 +225,12 @@ fromParserK parser = D.Parser step initial extract
221 Partial _ cont -> FPKCont cont -- XXX can we get this?
225 Partial _ cont -> FPKCont cont -- XXX can we get this?
222 Continue _ cont -> FPKCont cont
226 Continue _ cont -> FPKCont cont
228+ -- Note, we can only reach FPKDone and FPKError from "initial". FPKCont
229+ -- always transitions to only FPKCont. The input remains unconsumed in
230+ -- this case so we use "n + 1".
231+ step (FPKDone n b) _ = do
224− step (FPKDone n b) _ = return $ D.Done (n + 1) b
233+ return $ D.Done (n + 1) b
225 step (FPKError e) _ = return $ D.Error e
234 step (FPKError e) _ = return $ D.Error e
226 step (FPKCont cont) a = do
235 step (FPKCont cont) a = do
227 r <- cont (Just a)
236 r <- cont (Just a)