on master help sign in
Remove the Single constructor in chunked parser
83f1738Harendra Kumar
cabal.project+1
@@ -3,3 +3,4 @@ packages: streamly.cabal
3 , test/streamly-tests.cabal
3 , test/streamly-tests.cabal
4 , benchmark/streamly-benchmarks.cabal
4 , benchmark/streamly-benchmarks.cabal
5 , docs/streamly-docs.cabal
5 , docs/streamly-docs.cabal
6+write-ghc-environment-files: always
core/src/Streamly/Data/Parser/ParserK.hs+1−1
@@ -21,7 +21,7 @@ module Streamly.Data.Parser.ParserK
21 -- ** Conversions
21 -- ** Conversions
22 , fromFold
22 , fromFold
23 , fromParser
23 , fromParser
24− , toParser
24+ -- , toParser
25
25
26 -- ** Without Input
26 -- ** Without Input
27 , fromPure
27 , fromPure
core/src/Streamly/Internal/Data/Parser/ParserK/Type.hs+5−13
@@ -24,7 +24,7 @@ module Streamly.Internal.Data.Parser.ParserK.Type
24 , Parser (..)
24 , Parser (..)
25 , ParserK
25 , ParserK
26 , fromParser
26 , fromParser
27− , toParser
27+ -- , toParser
28 , fromPure
28 , fromPure
29 , fromEffect
29 , fromEffect
30 , die
30 , die
@@ -48,7 +48,7 @@ import qualified Control.Monad.Fail as Fail
48import qualified Streamly.Internal.Data.Array.Type as Array
48import qualified Streamly.Internal.Data.Array.Type as Array
49import qualified Streamly.Internal.Data.Parser.ParserD.Type as ParserD
49import qualified Streamly.Internal.Data.Parser.ParserD.Type as ParserD
50
50
51−data Input a = None | Single a | Chunk (Array a)
51+data Input a = None | Chunk {-# UNPACK #-} !(Array a)
52
52
53-- | The intermediate result of running a parser step. The parser driver may
53-- | The intermediate result of running a parser step. The parser driver may
54-- stop with a final result, pause with a continuation to resume, or fail with
54-- stop with a final result, pause with a continuation to resume, or fail with
@@ -127,6 +127,7 @@ newtype Parser a m b = MkParser
127 -- The second argument is the used count as described above. The
127 -- The second argument is the used count as described above. The
128 -- current input position is carried as part of 'Success'
128 -- current input position is carried as part of 'Success'
129 -- constructor of 'ParseResult'.
129 -- constructor of 'ParseResult'.
130+ -- XXX Use Array a, determine eof by using a nil array
130 -> Input a
131 -> Input a
131 -> (ParseResult b -> Int -> Input a -> m (Step a m r))
132 -> (ParseResult b -> Int -> Input a -> m (Step a m r))
132 -> m (Step a m r)
133 -> m (Step a m r)
@@ -432,7 +433,6 @@ parseDToK pstep initial extract offset usedCount input cont = do
432 ParserD.IPartial pst -> do
433 ParserD.IPartial pst -> do
433 case input of
434 case input of
434 Chunk arr -> parseContChunk usedCount offset pst arr
435 Chunk arr -> parseContChunk usedCount offset pst arr
435− Single x -> parseContSingle usedCount offset pst x
436 None -> parseContNothing usedCount pst
436 None -> parseContNothing usedCount pst
437 ParserD.IDone b -> cont (Success offset b) usedCount input
437 ParserD.IDone b -> cont (Success offset b) usedCount input
438 ParserD.IError err -> cont (Failure offset err) usedCount input
438 ParserD.IError err -> cont (Failure offset err) usedCount input
@@ -459,15 +459,6 @@ parseDToK pstep initial extract offset usedCount input cont = do
459 ChunkError n err ->
459 ChunkError n err ->
460 cont (Failure n err) (count + n - off) (Chunk arr)
460 cont (Failure n err) (count + n - off) (Chunk arr)
461
461
462− -- XXX This is not yet finished
463− {-# NOINLINE parseContSingle #-}
464− parseContSingle _count off pst x = do
465− pRes <- pstep pst x
466− case pRes of
467− ParserD.Done _n b -> do
468− cont (Success (off + 1) b) undefined undefined
469− _ -> undefined
470−
471 {-# NOINLINE parseContNothing #-}
462 {-# NOINLINE parseContNothing #-}
472 parseContNothing count pst = do
463 parseContNothing count pst = do
473 r <- extract pst
464 r <- extract pst
@@ -492,7 +483,6 @@ parseDToK pstep initial extract offset usedCount input cont = do
492 -- function call.
483 -- function call.
493 {-# INLINE parseCont #-}
484 {-# INLINE parseCont #-}
494 parseCont cnt pst (Chunk arr) = parseContChunk cnt 0 pst arr
485 parseCont cnt pst (Chunk arr) = parseContChunk cnt 0 pst arr
495− parseCont cnt pst (Single x) = parseContSingle cnt 0 pst x
496 parseCont cnt pst None = parseContNothing cnt pst
486 parseCont cnt pst None = parseContNothing cnt pst
497
487
498-- | Convert a raw byte 'Parser' to a chunked parser.
488-- | Convert a raw byte 'Parser' to a chunked parser.
@@ -504,6 +494,7 @@ fromParser :: (MonadIO m, Unbox a) => ParserD.Parser a m b -> ParserK a m b
504fromParser (ParserD.Parser step initial extract) =
494fromParser (ParserD.Parser step initial extract) =
505 MkParser $ parseDToK step initial extract
495 MkParser $ parseDToK step initial extract
506
496
497+{-
507-------------------------------------------------------------------------------
498-------------------------------------------------------------------------------
508-- Convert CPS style 'Parser' to direct style 'D.Parser'
499-- Convert CPS style 'Parser' to direct style 'D.Parser'
509-------------------------------------------------------------------------------
500-------------------------------------------------------------------------------
@@ -549,3 +540,4 @@ toParser parser = ParserD.Parser step initial extract
549{-# RULES "toParser/fromParser fusion" [2]
540{-# RULES "toParser/fromParser fusion" [2]
550 forall s. fromParser (toParser s) = s #-}
541 forall s. fromParser (toParser s) = s #-}
551#endif
542#endif
543+ -}
src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs+3−1
@@ -29,7 +29,7 @@ module Streamly.Internal.Data.Stream.IsStream.Eliminate {-# DEPRECATED "Please u
29 -- * Running a 'Parser'
29 -- * Running a 'Parser'
30 -- "Streamly.Internal.Data.Parser".
30 -- "Streamly.Internal.Data.Parser".
31 , parse
31 , parse
32− , parseK
32+ -- , parseK
33 , parseD
33 , parseD
34
34
35 -- * Stream Deconstruction
35 -- * Stream Deconstruction
@@ -377,12 +377,14 @@ runSink = fold . toFold
377parseD :: Monad m => PRD.Parser a m b -> SerialT m a -> m (Either PRD.ParseError b)
377parseD :: Monad m => PRD.Parser a m b -> SerialT m a -> m (Either PRD.ParseError b)
378parseD p = D.parseD p . toStreamD
378parseD p = D.parseD p . toStreamD
379
379
380+{-
380-- | Parse a stream using the supplied ParserK 'PRK.Parser'.
381-- | Parse a stream using the supplied ParserK 'PRK.Parser'.
381--
382--
382-- /Internal/
383-- /Internal/
383{-# INLINE parseK #-}
384{-# INLINE parseK #-}
384parseK :: Monad m => PRK.Parser a m b -> SerialT m a -> m (Either PRD.ParseError b)
385parseK :: Monad m => PRK.Parser a m b -> SerialT m a -> m (Either PRD.ParseError b)
385parseK p = parse (PRK.toParser p)
386parseK p = parse (PRK.toParser p)
387+-}
386
388
387-- | Parse a stream using the supplied 'Parser'.
389-- | Parse a stream using the supplied 'Parser'.
388--
390--