@@ -201,9 +201,7 @@ where
202#include "assert.hs"
202#include "assert.hs"
204−import Control.Exception (Exception)
205import Control.Monad (when)
204import Control.Monad (when)
206−import Control.Monad.Catch (MonadThrow(..))
207import Data.Bifunctor (first)
205import Data.Bifunctor (first)
208import Fusion.Plugin.Types (Fuse(..))
206import Fusion.Plugin.Types (Fuse(..))
209import Streamly.Internal.Data.Fold.Type (Fold(..))
207import Streamly.Internal.Data.Fold.Type (Fold(..))
@@ -237,22 +235,12 @@ import Streamly.Internal.Data.Parser.ParserD.Type
237-- Downgrade a parser to a Fold
235-- Downgrade a parser to a Fold
238-------------------------------------------------------------------------------
236-------------------------------------------------------------------------------
240−data ParserToFoldError =
248−instance Exception ParserToFoldError
250-- | See 'Streamly.Internal.Data.Parser.toFold'.
238-- | See 'Streamly.Internal.Data.Parser.toFold'.
252-- /Internal/
240-- /Internal/
254{-# INLINE toFold #-}
242{-# 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
256toFold (Parser pstep pinitial pextract) = Fold step initial extract
244toFold (Parser pstep pinitial pextract) = Fold step initial extract
@@ -262,7 +250,13 @@ toFold (Parser pstep pinitial pextract) = Fold step initial extract
262 case r of
250 case r of
263 IPartial s -> return $ FL.Partial s
251 IPartial s -> return $ FL.Partial s
264 IDone b -> return $ FL.Done b
252 IDone b -> return $ FL.Done b
265− IError err -> throwM $ InitialError err
253+ IError err ->
254+ error $ "toFold: parser throws error in initial" ++ err
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
267 step st a = do
261 step st a = do
268 r <- pstep st a
262 r <- pstep st a
@@ -270,19 +264,19 @@ toFold (Parser pstep pinitial pextract) = Fold step initial extract
270 Partial 0 s -> return $ FL.Partial s
264 Partial 0 s -> return $ FL.Partial s
271 Continue 0 s -> return $ FL.Partial s
265 Continue 0 s -> return $ FL.Partial s
272 Done 0 b -> return $ FL.Done b
266 Done 0 b -> return $ FL.Done b
273− Partial n _ -> throwM $ PartialError n
267+ Partial n _ -> perror n
274− Continue n _ -> throwM $ ContinueError n
268+ Continue n _ -> cerror n
275− Done n _ -> throwM $ DoneError n
269+ Done n _ -> derror n
276− Error err -> throwM $ ErrorError err
270+ Error err -> eerror err
278 extract st = do
272 extract st = do
279 r <- pextract st
273 r <- pextract st
280 case r of
274 case r of
281 Done 0 b -> return b
275 Done 0 b -> return b
282− Partial n _ -> throwM $ PartialError n
276+ Partial n _ -> perror n
283− Continue n _ -> throwM $ ContinueError n
277+ Continue n _ -> cerror n
284− Done n _ -> throwM $ DoneError n
278+ Done n _ -> derror n
285− Error err -> throwM $ ErrorError err
279+ Error err -> eerror err
287-------------------------------------------------------------------------------
281-------------------------------------------------------------------------------
288-- Upgrade folds to parses
282-- Upgrade folds to parses