mirror of
https://github.com/composewell/streamly.git
synced 2024-09-11 11:37:22 +03:00
Use assertM instead of assert in Parser code
This commit is contained in:
parent
95fc1d2d05
commit
63ba027ce4
@ -196,11 +196,12 @@ module Streamly.Internal.Data.Parser.ParserD
|
||||
)
|
||||
where
|
||||
|
||||
import Control.Exception (assert, Exception)
|
||||
import Control.Exception (Exception)
|
||||
import Control.Monad (when)
|
||||
import Control.Monad.Catch (MonadCatch, MonadThrow(..))
|
||||
import Data.Bifunctor (first)
|
||||
import Fusion.Plugin.Types (Fuse(..))
|
||||
import Streamly.Internal.Control.Exception (assertM)
|
||||
import Streamly.Internal.Data.Fold.Type (Fold(..))
|
||||
import Streamly.Internal.Data.SVar.Type (defState)
|
||||
import Streamly.Internal.Data.Either.Strict (Either'(..))
|
||||
@ -1704,17 +1705,17 @@ takeP lim (Parser pstep pinitial pextract) = Parser step initial extract
|
||||
IError e -> return $ IError e
|
||||
|
||||
step (Tuple' cnt r) a = do
|
||||
assert (cnt < lim) (return ())
|
||||
assertM (cnt < lim)
|
||||
res <- pstep r a
|
||||
let cnt1 = cnt + 1
|
||||
case res of
|
||||
Partial 0 s -> do
|
||||
assert (cnt1 >= 0) (return ())
|
||||
assertM (cnt1 >= 0)
|
||||
if cnt1 < lim
|
||||
then return $ Partial 0 $ Tuple' cnt1 s
|
||||
else Done 0 <$> pextract s
|
||||
Continue 0 s -> do
|
||||
assert (cnt1 >= 0) (return ())
|
||||
assertM (cnt1 >= 0)
|
||||
if cnt1 < lim
|
||||
then return $ Continue 0 $ Tuple' cnt1 s
|
||||
-- XXX This should error out?
|
||||
@ -1731,11 +1732,11 @@ takeP lim (Parser pstep pinitial pextract) = Parser step initial extract
|
||||
else Done 0 <$> pextract s
|
||||
Partial n s -> do
|
||||
let taken = cnt1 - n
|
||||
assert (taken >= 0) (return ())
|
||||
assertM (taken >= 0)
|
||||
return $ Partial n $ Tuple' taken s
|
||||
Continue n s -> do
|
||||
let taken = cnt1 - n
|
||||
assert (taken >= 0) (return ())
|
||||
assertM (taken >= 0)
|
||||
return $ Continue n $ Tuple' taken s
|
||||
Done n b -> return $ Done n b
|
||||
Error str -> return $ Error str
|
||||
@ -2130,7 +2131,7 @@ manyTill (Fold fstep finitial fextract)
|
||||
case r of
|
||||
Partial n s -> return $ Partial n (ManyTillR 0 fs s)
|
||||
Continue n s -> do
|
||||
assert (cnt + 1 - n >= 0) (return ())
|
||||
assertM (cnt + 1 - n >= 0)
|
||||
return $ Continue n (ManyTillR (cnt + 1 - n) fs s)
|
||||
Done n _ -> do
|
||||
b <- fextract fs
|
||||
@ -2156,7 +2157,7 @@ manyTill (Fold fstep finitial fextract)
|
||||
case r of
|
||||
Partial n s -> return $ Partial n (ManyTillL 0 fs s)
|
||||
Continue n s -> do
|
||||
assert (cnt + 1 - n >= 0) (return ())
|
||||
assertM (cnt + 1 - n >= 0)
|
||||
return $ Continue n (ManyTillL (cnt + 1 - n) fs s)
|
||||
Done n b -> do
|
||||
fs1 <- fstep fs b
|
||||
|
@ -208,7 +208,7 @@ module Streamly.Internal.Data.Parser.ParserD.Type
|
||||
where
|
||||
|
||||
import Control.Applicative (Alternative(..), liftA2)
|
||||
import Control.Exception (assert, Exception(..))
|
||||
import Control.Exception (Exception(..))
|
||||
import Control.Monad (MonadPlus(..), (>=>))
|
||||
import Control.Monad.IO.Class (MonadIO, liftIO)
|
||||
import Control.Monad.Reader.Class (MonadReader, ask, local)
|
||||
@ -505,15 +505,15 @@ parseDToK pstep initial extract leftover (level, count) cont = do
|
||||
pRes <- pstep r x
|
||||
case pRes of
|
||||
Done n b -> do
|
||||
assert (n <= cnt1) (return ())
|
||||
assertM (n <= cnt1)
|
||||
cont (level, cnt1 - n) (K.Success n b)
|
||||
Error err ->
|
||||
cont (level, cnt1) (K.Failure err)
|
||||
Partial n pst1 -> do
|
||||
assert (n <= cnt1) (return ())
|
||||
assertM (n <= cnt1)
|
||||
return $ K.Partial n (parseCont (cnt1 - n) (return pst1))
|
||||
Continue n pst1 -> do
|
||||
assert (n <= cnt1) (return ())
|
||||
assertM (n <= cnt1)
|
||||
return $ K.Continue n (parseCont (cnt1 - n) (return pst1))
|
||||
parseCont cnt acc Nothing = do
|
||||
pst <- acc
|
||||
@ -981,7 +981,7 @@ alt (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
|
||||
case r of
|
||||
Partial n s -> return $ Partial n (AltParseL 0 s)
|
||||
Continue n s -> do
|
||||
assert (cnt + 1 - n >= 0) (return ())
|
||||
assertM (cnt + 1 - n >= 0)
|
||||
return $ Continue n (AltParseL (cnt + 1 - n) s)
|
||||
Done n b -> return $ Done n b
|
||||
Error _ -> do
|
||||
@ -1038,13 +1038,13 @@ splitMany (Parser step1 initial1 extract1) (Fold fstep finitial fextract) =
|
||||
let cnt1 = cnt + 1
|
||||
case r of
|
||||
Partial n s -> do
|
||||
assert (cnt1 - n >= 0) (return ())
|
||||
assertM (cnt1 - n >= 0)
|
||||
return $ Continue n (Tuple3' s (cnt1 - n) fs)
|
||||
Continue n s -> do
|
||||
assert (cnt1 - n >= 0) (return ())
|
||||
assertM (cnt1 - n >= 0)
|
||||
return $ Continue n (Tuple3' s (cnt1 - n) fs)
|
||||
Done n b -> do
|
||||
assert (cnt1 - n >= 0) (return ())
|
||||
assertM (cnt1 - n >= 0)
|
||||
fstep fs b >>= handleCollect (Partial n) (Done n)
|
||||
Error _ -> do
|
||||
xs <- fextract fs
|
||||
@ -1098,13 +1098,13 @@ splitManyPost (Parser step1 initial1 extract1) (Fold fstep finitial fextract) =
|
||||
let cnt1 = cnt + 1
|
||||
case r of
|
||||
Partial n s -> do
|
||||
assert (cnt1 - n >= 0) (return ())
|
||||
assertM (cnt1 - n >= 0)
|
||||
return $ Continue n (Tuple3' s (cnt1 - n) fs)
|
||||
Continue n s -> do
|
||||
assert (cnt1 - n >= 0) (return ())
|
||||
assertM (cnt1 - n >= 0)
|
||||
return $ Continue n (Tuple3' s (cnt1 - n) fs)
|
||||
Done n b -> do
|
||||
assert (cnt1 - n >= 0) (return ())
|
||||
assertM (cnt1 - n >= 0)
|
||||
fstep fs b >>= handleCollect (Partial n) (Done n)
|
||||
Error _ -> do
|
||||
xs <- fextract fs
|
||||
@ -1171,13 +1171,13 @@ splitSome (Parser step1 initial1 extract1) (Fold fstep finitial fextract) =
|
||||
let cnt1 = cnt + 1
|
||||
case r of
|
||||
Partial n s -> do
|
||||
assert (cnt1 - n >= 0) (return ())
|
||||
assertM (cnt1 - n >= 0)
|
||||
return $ Continue n (Tuple3' s (cnt1 - n) (Left fs))
|
||||
Continue n s -> do
|
||||
assert (cnt1 - n >= 0) (return ())
|
||||
assertM (cnt1 - n >= 0)
|
||||
return $ Continue n (Tuple3' s (cnt1 - n) (Left fs))
|
||||
Done n b -> do
|
||||
assert (cnt1 - n >= 0) (return ())
|
||||
assertM (cnt1 - n >= 0)
|
||||
fstep fs b >>= handleCollect (Partial n) (Done n)
|
||||
Error err -> return $ Error err
|
||||
step (Tuple3' st cnt (Right fs)) a = do
|
||||
@ -1185,13 +1185,13 @@ splitSome (Parser step1 initial1 extract1) (Fold fstep finitial fextract) =
|
||||
let cnt1 = cnt + 1
|
||||
case r of
|
||||
Partial n s -> do
|
||||
assert (cnt1 - n >= 0) (return ())
|
||||
assertM (cnt1 - n >= 0)
|
||||
return $ Partial n (Tuple3' s (cnt1 - n) (Right fs))
|
||||
Continue n s -> do
|
||||
assert (cnt1 - n >= 0) (return ())
|
||||
assertM (cnt1 - n >= 0)
|
||||
return $ Continue n (Tuple3' s (cnt1 - n) (Right fs))
|
||||
Done n b -> do
|
||||
assert (cnt1 - n >= 0) (return ())
|
||||
assertM (cnt1 - n >= 0)
|
||||
fstep fs b >>= handleCollect (Partial n) (Done n)
|
||||
Error _ -> Done cnt1 <$> fextract fs
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user