@@ -24,7 +24,7 @@ module Streamly.Internal.Data.Parser.ParserK.Type
24 , Parser (..)
24 , Parser (..)
26 , fromParser
26 , fromParser
27− , toParser
27+ -- , toParser
28 , fromPure
28 , fromPure
29 , fromEffect
29 , fromEffect
@@ -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
51−data Input a = None | Single a | Chunk (Array a)
51+data Input a = None | Chunk {-# UNPACK #-} !(Array a)
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)
462− -- XXX This is not yet finished
463− {-# NOINLINE parseContSingle #-}
464− parseContSingle _count off pst x = do
467− ParserD.Done _n b -> do
468− cont (Success (off + 1) b) undefined undefined
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
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
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 #-}