@@ -201,9 +201,7 @@ where
201201
202202#include "assert.hs"
203203
204−import Control.Exception (Exception)
205204import Control.Monad (when)
206−import Control.Monad.Catch (MonadThrow(..))
207205import Data.Bifunctor (first)
208206import Fusion.Plugin.Types (Fuse(..))
209207import Streamly.Internal.Data.Fold.Type (Fold(..))
@@ -237,22 +235,12 @@ import Streamly.Internal.Data.Parser.ParserD.Type
237235-- Downgrade a parser to a Fold
238236-------------------------------------------------------------------------------
239237
240−data ParserToFoldError =
241− InitialError String
242− | PartialError Int
243− | ContinueError Int
244− | DoneError Int
245− | ErrorError String
246− deriving Show
247−
248−instance Exception ParserToFoldError
249−
250238-- | See 'Streamly.Internal.Data.Parser.toFold'.
251239--
252240-- /Internal/
253241--
254242{-# INLINE toFold #-}
255−toFold :: MonadThrow m => Parser m a b -> Fold m a b
243+toFold :: Monad m => Parser m a b -> Fold m a b
256244toFold (Parser pstep pinitial pextract) = Fold step initial extract
257245
258246 where
@@ -262,7 +250,13 @@ toFold (Parser pstep pinitial pextract) = Fold step initial extract
262250 case r of
263251 IPartial s -> return $ FL.Partial s
264252 IDone b -> return $ FL.Done b
265− IError err -> throwM $ InitialError err
253+ IError err ->
254+ error $ "toFold: parser throws error in initial" ++ err
255+
256+ perror n = error $ "toFold: parser backtracks in Partial: " ++ show n
257+ cerror n = error $ "toFold: parser backtracks in Continue: " ++ show n
258+ derror n = error $ "toFold: parser backtracks in Done: " ++ show n
259+ eerror err = error $ "toFold: parser throws error: " ++ err
266260
267261 step st a = do
268262 r <- pstep st a
@@ -270,19 +264,19 @@ toFold (Parser pstep pinitial pextract) = Fold step initial extract
270264 Partial 0 s -> return $ FL.Partial s
271265 Continue 0 s -> return $ FL.Partial s
272266 Done 0 b -> return $ FL.Done b
273− Partial n _ -> throwM $ PartialError n
274− Continue n _ -> throwM $ ContinueError n
275− Done n _ -> throwM $ DoneError n
276− Error err -> throwM $ ErrorError err
267+ Partial n _ -> perror n
268+ Continue n _ -> cerror n
269+ Done n _ -> derror n
270+ Error err -> eerror err
277271
278272 extract st = do
279273 r <- pextract st
280274 case r of
281275 Done 0 b -> return b
282− Partial n _ -> throwM $ PartialError n
283− Continue n _ -> throwM $ ContinueError n
284− Done n _ -> throwM $ DoneError n
285− Error err -> throwM $ ErrorError err
276+ Partial n _ -> perror n
277+ Continue n _ -> cerror n
278+ Done n _ -> derror n
279+ Error err -> eerror err
286280
287281-------------------------------------------------------------------------------
288282-- Upgrade folds to parses