@@ -510,6 +510,14 @@ parseDToK pstep initial extract leftover (0, _) cont = do
510510 Partial _ _ -> error "Bug: parseDToK Partial unreachable"
511511 Continue n pst1 -> return $ K.Continue n (parseCont (return pst1))
512512
513+-- XXX Pass on the stream to parserK and inside parserK drive the parserD
514+-- directly from the stream. That way we can feed full chunks efficiently to
515+-- parserD with fusion. The remaining stream can be passed on to the
516+-- continuation and at the end the leftover stream can be returned.
517+--
518+-- contification of parserD completely breaks fusion. We can avoid that by
519+-- fusing the parserD with the source stream.
520+
513521-- 'Alternative' case. Used count needs to be maintained when inside an
514522-- Alternative.
515523parseDToK pstep initial extract leftover (level, count) cont = do
@@ -569,9 +577,9 @@ toParserK (Parser step initial extract) =
569577{-# INLINE parserDone #-}
570578parserDone :: Monad m => (Int, Int) -> K.Parse b -> m (K.Step m a b)
571579parserDone (0,_) (K.Success n b) = return $ K.Done n b
572−parserDone st (K.Success _ _) =
573− error $ "Bug: fromParserK: inside alternative: " ++ show st
574−parserDone _ (K.Failure e) = return $ K.Error e
580+parserDone (0,_) (K.Failure e) = return $ K.Error e
581+parserDone st _ =
582+ error $ "Bug: fromParserK: parser done inside alternative: " ++ show st
575583
576584-- | Convert a CPS style 'K.Parser' to a direct style 'Parser'.
577585--
@@ -1025,7 +1033,7 @@ alt (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
10251033 IPartial rR -> Continue cnt (AltParseR rR)
10261034 IDone b -> Done cnt b
10271035 IError err -> Error err
1028− Partial _ _ -> error "Bug: serialWith extract 'Partial'"
1036+ Partial _ _ -> error "Bug: alt: extractL 'Partial'"
10291037 Continue n s -> do
10301038 assertM(n == cnt)
10311039 return $ Continue n (AltParseL 0 s)