on master help sign in
Remove the Single constructor in chunked parser
commit83f173802b77479fb60fc2b8f08a254655e64817 authorHarendra Kumar <harendra@composewell.com> dateWed 15 Feb 2023, 10:28 (4 years ago) parent4840f43
4 files changed+10−15
cabal.project+1 core/src/Streamly/Data/Parser/ParserK.hs+1−1 core/src/Streamly/Internal/Data/Parser/ParserK/Type.hs+5−13 src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs+3−1
cabal.project+1
@@ -3,3 +3,4 @@ packages: streamly.cabal
33 , test/streamly-tests.cabal
44 , benchmark/streamly-benchmarks.cabal
55 , 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
2121 -- ** Conversions
2222 , fromFold
2323 , fromParser
24− , toParser
24+ -- , toParser
2525
2626 -- ** Without Input
2727 , fromPure
core/src/Streamly/Internal/Data/Parser/ParserK/Type.hs+5−13
@@ -24,7 +24,7 @@ module Streamly.Internal.Data.Parser.ParserK.Type
2424 , Parser (..)
2525 , ParserK
2626 , fromParser
27− , toParser
27+ -- , toParser
2828 , fromPure
2929 , fromEffect
3030 , die
@@ -48,7 +48,7 @@ import qualified Control.Monad.Fail as Fail
4848import qualified Streamly.Internal.Data.Array.Type as Array
4949import qualified Streamly.Internal.Data.Parser.ParserD.Type as ParserD
5050
51−data Input a = None | Single a | Chunk (Array a)
51+data Input a = None | Chunk {-# UNPACK #-} !(Array a)
5252
5353-- | The intermediate result of running a parser step. The parser driver may
5454-- stop with a final result, pause with a continuation to resume, or fail with
@@ -127,6 +127,7 @@ newtype Parser a m b = MkParser
127127 -- The second argument is the used count as described above. The
128128 -- current input position is carried as part of 'Success'
129129 -- constructor of 'ParseResult'.
130+ -- XXX Use Array a, determine eof by using a nil array
130131 -> Input a
131132 -> (ParseResult b -> Int -> Input a -> m (Step a m r))
132133 -> m (Step a m r)
@@ -432,7 +433,6 @@ parseDToK pstep initial extract offset usedCount input cont = do
432433 ParserD.IPartial pst -> do
433434 case input of
434435 Chunk arr -> parseContChunk usedCount offset pst arr
435− Single x -> parseContSingle usedCount offset pst x
436436 None -> parseContNothing usedCount pst
437437 ParserD.IDone b -> cont (Success offset b) usedCount input
438438 ParserD.IError err -> cont (Failure offset err) usedCount input
@@ -459,15 +459,6 @@ parseDToK pstep initial extract offset usedCount input cont = do
459459 ChunkError n err ->
460460 cont (Failure n err) (count + n - off) (Chunk arr)
461461
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−
471462 {-# NOINLINE parseContNothing #-}
472463 parseContNothing count pst = do
473464 r <- extract pst
@@ -492,7 +483,6 @@ parseDToK pstep initial extract offset usedCount input cont = do
492483 -- function call.
493484 {-# INLINE parseCont #-}
494485 parseCont cnt pst (Chunk arr) = parseContChunk cnt 0 pst arr
495− parseCont cnt pst (Single x) = parseContSingle cnt 0 pst x
496486 parseCont cnt pst None = parseContNothing cnt pst
497487
498488-- | 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
504494fromParser (ParserD.Parser step initial extract) =
505495 MkParser $ parseDToK step initial extract
506496
497+{-
507498-------------------------------------------------------------------------------
508499-- Convert CPS style 'Parser' to direct style 'D.Parser'
509500-------------------------------------------------------------------------------
@@ -549,3 +540,4 @@ toParser parser = ParserD.Parser step initial extract
549540{-# RULES "toParser/fromParser fusion" [2]
550541 forall s. fromParser (toParser s) = s #-}
551542#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
2929 -- * Running a 'Parser'
3030 -- "Streamly.Internal.Data.Parser".
3131 , parse
32− , parseK
32+ -- , parseK
3333 , parseD
3434
3535 -- * Stream Deconstruction
@@ -377,12 +377,14 @@ runSink = fold . toFold
377377parseD :: Monad m => PRD.Parser a m b -> SerialT m a -> m (Either PRD.ParseError b)
378378parseD p = D.parseD p . toStreamD
379379
380+{-
380381-- | Parse a stream using the supplied ParserK 'PRK.Parser'.
381382--
382383-- /Internal/
383384{-# INLINE parseK #-}
384385parseK :: Monad m => PRK.Parser a m b -> SerialT m a -> m (Either PRD.ParseError b)
385386parseK p = parse (PRK.toParser p)
387+-}
386388
387389-- | Parse a stream using the supplied 'Parser'.
388390--