on master help sign in
Move toParserK and fromParserK routines from ParserK to the ParserD module
commitf31f28c0d8d4ab81b5eac72e7d31bc75778b64aa authorRanjeet Kumar Ranjan <ranjeetr@composewell.com> dateTue 8 Mar 2022, 21:27 (5 years ago) parentcbe6eb1
11 files changed+252−249
benchmark/Streamly/Benchmark/Data/Parser/ParserK.hs+3−3 core/src/Streamly/Internal/Data/Array/Stream/Fold/Foreign.hs+1−2 core/src/Streamly/Internal/Data/Parser.hs+47−47 core/src/Streamly/Internal/Data/Parser/ParserD.hs+4 core/src/Streamly/Internal/Data/Parser/ParserD/Type.hs+172−2 core/src/Streamly/Internal/Data/Parser/ParserK/Type.hs+12−179 core/src/Streamly/Internal/Data/Producer/Source.hs+2−2 src/Streamly/Internal/Data/Binary/Decode.hs+6−7 src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs+2−2 src/Streamly/Internal/Data/Stream/IsStream/Reduce.hs+2−3 src/Streamly/Internal/Unicode/Stream.hs+1−2
benchmark/Streamly/Benchmark/Data/Parser/ParserK.hs+3−3
@@ -60,18 +60,18 @@ benchIOSink value name f =
6060-------------------------------------------------------------------------------
6161
6262#ifdef FROM_PARSERK
63−#define PARSE_OP (IP.parseD . PR.fromParserK)
63+#define PARSE_OP (IP.parseD . PRD.fromParserK)
6464#else
6565#define PARSE_OP IP.parseK
6666#endif
6767
6868{-# INLINE satisfy #-}
6969satisfy :: MonadCatch m => (a -> Bool) -> PR.Parser m a a
70−satisfy = PR.toParserK . PRD.satisfy
70+satisfy = PRD.toParserK . PRD.satisfy
7171
7272{-# INLINE takeWhile #-}
7373takeWhile :: MonadCatch m => (a -> Bool) -> PR.Parser m a ()
74−takeWhile p = PR.toParserK $ PRD.takeWhile p FL.drain
74+takeWhile p = PRD.toParserK $ PRD.takeWhile p FL.drain
7575
7676{-# INLINE takeWhileK #-}
7777takeWhileK :: MonadCatch m => Int -> SerialT m Int -> m ()
core/src/Streamly/Internal/Data/Array/Stream/Fold/Foreign.hs+1−2
@@ -70,7 +70,6 @@ import qualified Streamly.Internal.Data.Array.Foreign as Array
7070import qualified Streamly.Internal.Data.Fold as Fold
7171import qualified Streamly.Internal.Data.Parser.ParserD as ParserD
7272import qualified Streamly.Internal.Data.Parser.ParserD.Type as ParserD
73−import qualified Streamly.Internal.Data.Parser.ParserK.Type as ParserK
7473import qualified Streamly.Internal.Data.Parser as Parser
7574
7675import Prelude hiding (concatMap, take)
@@ -180,7 +179,7 @@ fromParserD (ParserD.Parser step1 initial1 extract1) =
180179{-# INLINE fromParser #-}
181180fromParser :: forall m a b. (MonadThrow m, MonadIO m, Storable a) =>
182181 Parser.Parser m a b -> Fold m a b
183−fromParser = fromParserD . ParserK.fromParserK
182+fromParser = fromParserD . ParserD.fromParserK
184183
185184-- | Adapt an array stream fold.
186185--
core/src/Streamly/Internal/Data/Parser.hs+47−47
@@ -237,7 +237,7 @@ import qualified Streamly.Internal.Data.Parser.ParserK.Type as K
237237--
238238{-# INLINE toFold #-}
239239toFold :: MonadThrow m => Parser m a b -> Fold m a b
240−toFold p = D.toFold $ K.fromParserK p
240+toFold p = D.toFold $ D.fromParserK p
241241
242242-------------------------------------------------------------------------------
243243-- Upgrade folds to parses
@@ -249,7 +249,7 @@ toFold p = D.toFold $ K.fromParserK p
249249--
250250{-# INLINE fromFold #-}
251251fromFold :: MonadCatch m => Fold m a b -> Parser m a b
252−fromFold = K.toParserK . D.fromFold
252+fromFold = D.toParserK . D.fromFold
253253
254254-------------------------------------------------------------------------------
255255-- Terminating but not failing folds
@@ -263,9 +263,9 @@ fromFold = K.toParserK . D.fromFold
263263--
264264{-# INLINE [3] fromPure #-}
265265fromPure :: MonadCatch m => b -> Parser m a b
266−fromPure = K.toParserK . D.fromPure
266+fromPure = D.toParserK . D.fromPure
267267{-# RULES "fromPure fallback to CPS" [2]
268− forall a. K.toParserK (D.fromPure a) = K.fromPure a #-}
268+ forall a. D.toParserK (D.fromPure a) = K.fromPure a #-}
269269
270270-- This is the dual of stream "fromEffect".
271271--
@@ -276,7 +276,7 @@ fromPure = K.toParserK . D.fromPure
276276--
277277{-# INLINE fromEffect #-}
278278fromEffect :: MonadCatch m => m b -> Parser m a b
279−fromEffect = K.fromEffect -- K.toParserK . D.fromEffect
279+fromEffect = K.fromEffect -- D.toParserK . D.fromEffect
280280
281281-- This is the dual of "nil".
282282--
@@ -287,9 +287,9 @@ fromEffect = K.fromEffect -- K.toParserK . D.fromEffect
287287--
288288{-# INLINE [3] die #-}
289289die :: MonadCatch m => String -> Parser m a b
290−die = K.toParserK . D.die
290+die = D.toParserK . D.die
291291{-# RULES "die fallback to CPS" [2]
292− forall a. K.toParserK (D.die a) = K.die a #-}
292+ forall a. D.toParserK (D.die a) = K.die a #-}
293293
294294-- This is the dual of "nilM".
295295--
@@ -300,7 +300,7 @@ die = K.toParserK . D.die
300300--
301301{-# INLINE dieM #-}
302302dieM :: MonadCatch m => m String -> Parser m a b
303−dieM = K.toParserK . D.dieM
303+dieM = D.toParserK . D.dieM
304304
305305-------------------------------------------------------------------------------
306306-- Failing Parsers
@@ -320,7 +320,7 @@ dieM = K.toParserK . D.dieM
320320--
321321{-# INLINE peek #-}
322322peek :: MonadCatch m => Parser m a a
323−peek = K.toParserK D.peek
323+peek = D.toParserK D.peek
324324
325325-- | Succeeds if we are at the end of input, fails otherwise.
326326--
@@ -331,7 +331,7 @@ peek = K.toParserK D.peek
331331--
332332{-# INLINE eof #-}
333333eof :: MonadCatch m => Parser m a ()
334−eof = K.toParserK D.eof
334+eof = D.toParserK D.eof
335335
336336-- | Returns the next element if it passes the predicate, fails otherwise.
337337--
@@ -342,7 +342,7 @@ eof = K.toParserK D.eof
342342--
343343{-# INLINE satisfy #-}
344344satisfy :: MonadCatch m => (a -> Bool) -> Parser m a a
345−satisfy = K.toParserK . D.satisfy
345+satisfy = D.toParserK . D.satisfy
346346
347347-- | Return the next element of the input. Returns 'Nothing'
348348-- on end of input. Also known as 'head'.
@@ -351,7 +351,7 @@ satisfy = K.toParserK . D.satisfy
351351--
352352{-# INLINE next #-}
353353next :: MonadCatch m => Parser m a (Maybe a)
354−next = K.toParserK D.next
354+next = D.toParserK D.next
355355
356356-- | Map a 'Maybe' returning function on the next element in the stream. The
357357-- parser fails if the function returns 'Nothing' otherwise returns the 'Just'
@@ -361,7 +361,7 @@ next = K.toParserK D.next
361361--
362362{-# INLINE maybe #-}
363363maybe :: MonadCatch m => (a -> Maybe b) -> Parser m a b
364−maybe = K.toParserK . D.maybe
364+maybe = D.toParserK . D.maybe
365365
366366-- | Map an 'Either' returning function on the next element in the stream. If
367367-- the function returns 'Left err', the parser fails with the error message
@@ -371,7 +371,7 @@ maybe = K.toParserK . D.maybe
371371--
372372{-# INLINE either #-}
373373either :: MonadCatch m => (a -> Either String b) -> Parser m a b
374−either = K.toParserK . D.either
374+either = D.toParserK . D.either
375375
376376-------------------------------------------------------------------------------
377377-- Taking elements
@@ -423,7 +423,7 @@ either = K.toParserK . D.either
423423{-# INLINE takeBetween #-}
424424takeBetween :: MonadCatch m =>
425425 Int -> Int -> Fold m a b -> Parser m a b
426−takeBetween m n = K.toParserK . D.takeBetween m n
426+takeBetween m n = D.toParserK . D.takeBetween m n
427427
428428-- | Stops after taking exactly @n@ input elements.
429429--
@@ -438,7 +438,7 @@ takeBetween m n = K.toParserK . D.takeBetween m n
438438--
439439{-# INLINE takeEQ #-}
440440takeEQ :: MonadCatch m => Int -> Fold m a b -> Parser m a b
441−takeEQ n = K.toParserK . D.takeEQ n
441+takeEQ n = D.toParserK . D.takeEQ n
442442
443443-- | Take at least @n@ input elements, but can collect more.
444444--
@@ -456,7 +456,7 @@ takeEQ n = K.toParserK . D.takeEQ n
456456--
457457{-# INLINE takeGE #-}
458458takeGE :: MonadCatch m => Int -> Fold m a b -> Parser m a b
459−takeGE n = K.toParserK . D.takeGE n
459+takeGE n = D.toParserK . D.takeGE n
460460
461461-- $takeWhile
462462-- Note: This is called @takeWhileP@ and @munch@ in some parser libraries.
@@ -480,7 +480,7 @@ takeGE n = K.toParserK . D.takeGE n
480480{-# INLINE takeWhileP #-}
481481takeWhileP :: -- MonadCatch m =>
482482 (a -> Bool) -> Parser m a b -> Parser m a b
483−takeWhileP _cond = undefined -- K.toParserK . D.takeWhileP cond
483+takeWhileP _cond = undefined -- D.toParserK . D.takeWhileP cond
484484
485485-- | Collect stream elements until an element fails the predicate. The element
486486-- on which the predicate fails is returned back to the input stream.
@@ -501,7 +501,7 @@ takeWhileP _cond = undefined -- K.toParserK . D.takeWhileP cond
501501--
502502{-# INLINE takeWhile #-}
503503takeWhile :: MonadCatch m => (a -> Bool) -> Fold m a b -> Parser m a b
504−takeWhile cond = K.toParserK . D.takeWhile cond
504+takeWhile cond = D.toParserK . D.takeWhile cond
505505
506506-- | Like 'takeWhile' but takes at least one element otherwise fails.
507507--
@@ -509,7 +509,7 @@ takeWhile cond = K.toParserK . D.takeWhile cond
509509--
510510{-# INLINE takeWhile1 #-}
511511takeWhile1 :: MonadCatch m => (a -> Bool) -> Fold m a b -> Parser m a b
512−takeWhile1 cond = K.toParserK . D.takeWhile1 cond
512+takeWhile1 cond = D.toParserK . D.takeWhile1 cond
513513
514514-- | Drain the input as long as the predicate succeeds, running the effects and
515515-- discarding the results.
@@ -539,7 +539,7 @@ drainWhile p = takeWhile p FL.drain
539539sliceSepByP ::
540540 MonadCatch m =>
541541 (a -> Bool) -> Parser m a b -> Parser m a b
542−sliceSepByP cond = K.toParserK . D.sliceSepByP cond . K.fromParserK
542+sliceSepByP cond = D.toParserK . D.sliceSepByP cond . D.fromParserK
543543
544544-- | Like 'sliceSepBy' but does not drop the separator element, instead
545545-- separator is emitted as a separate element in the output.
@@ -548,7 +548,7 @@ sliceSepByP cond = K.toParserK . D.sliceSepByP cond . K.fromParserK
548548{-# INLINE sliceSepWith #-}
549549sliceSepWith :: -- MonadCatch m =>
550550 (a -> Bool) -> Fold m a b -> Parser m a b
551−sliceSepWith _cond = undefined -- K.toParserK . D.sliceSepBy cond
551+sliceSepWith _cond = undefined -- D.toParserK . D.sliceSepBy cond
552552
553553-- | Collect stream elements until an elements passes the predicate, return the
554554-- last element on which the predicate succeeded back to the input stream. If
@@ -588,7 +588,7 @@ sliceSepWith _cond = undefined -- K.toParserK . D.sliceSepBy cond
588588sliceBeginWith ::
589589 MonadCatch m =>
590590 (a -> Bool) -> Fold m a b -> Parser m a b
591−sliceBeginWith cond = K.toParserK . D.sliceBeginWith cond
591+sliceBeginWith cond = D.toParserK . D.sliceBeginWith cond
592592
593593-- | Like 'sliceSepBy' but the separator elements can be escaped using an
594594-- escape char determined by the second predicate.
@@ -598,7 +598,7 @@ sliceBeginWith cond = K.toParserK . D.sliceBeginWith cond
598598escapedSliceSepBy :: -- MonadCatch m =>
599599 (a -> Bool) -> (a -> Bool) -> Fold m a b -> Parser m a b
600600escapedSliceSepBy _cond _esc = undefined
601− -- K.toParserK . D.escapedSliceSepBy cond esc
601+ -- D.toParserK . D.escapedSliceSepBy cond esc
602602
603603-- | @escapedFrameBy begin end escape@ parses a string framed using @begin@ and
604604-- @end@ as the frame begin and end marker elements and @escape@ as an escaping
@@ -627,7 +627,7 @@ escapedSliceSepBy _cond _esc = undefined
627627escapedFrameBy :: -- MonadCatch m =>
628628 (a -> Bool) -> (a -> Bool) -> (a -> Bool) -> Fold m a b -> Parser m a b
629629escapedFrameBy _begin _end _escape _p = undefined
630− -- K.toParserK . D.frameBy begin end escape p
630+ -- D.toParserK . D.frameBy begin end escape p
631631
632632-- | Like 'splitOn' but strips leading, trailing, and repeated separators.
633633-- Therefore, @".a..b."@ having '.' as the separator would be parsed as
@@ -643,7 +643,7 @@ escapedFrameBy _begin _end _escape _p = undefined
643643--
644644{-# INLINE wordBy #-}
645645wordBy :: MonadCatch m => (a -> Bool) -> Fold m a b -> Parser m a b
646−wordBy f = K.toParserK . D.wordBy f
646+wordBy f = D.toParserK . D.wordBy f
647647
648648-- | Given an input stream @[a,b,c,...]@ and a comparison function @cmp@, the
649649-- parser assigns the element @a@ to the first group, then if @a \`cmp` b@ is
@@ -675,7 +675,7 @@ wordBy f = K.toParserK . D.wordBy f
675675--
676676{-# INLINE groupBy #-}
677677groupBy :: MonadCatch m => (a -> a -> Bool) -> Fold m a b -> Parser m a b
678−groupBy eq = K.toParserK . D.groupBy eq
678+groupBy eq = D.toParserK . D.groupBy eq
679679
680680-- | Unlike 'groupBy' this combinator performs a rolling comparison of two
681681-- successive elements in the input stream. Assuming the input stream to the
@@ -709,7 +709,7 @@ groupBy eq = K.toParserK . D.groupBy eq
709709--
710710{-# INLINE groupByRolling #-}
711711groupByRolling :: MonadCatch m => (a -> a -> Bool) -> Fold m a b -> Parser m a b
712−groupByRolling eq = K.toParserK . D.groupByRolling eq
712+groupByRolling eq = D.toParserK . D.groupByRolling eq
713713
714714-- | Like 'groupByRolling', but if the predicate is 'True' then collects using
715715-- the first fold as long as the predicate holds 'True', if the predicate is
@@ -724,7 +724,7 @@ groupByRolling eq = K.toParserK . D.groupByRolling eq
724724{-# INLINE groupByRollingEither #-}
725725groupByRollingEither :: MonadCatch m =>
726726 (a -> a -> Bool) -> Fold m a b -> Fold m a c -> Parser m a (Either b c)
727−groupByRollingEither eq f1 = K.toParserK . D.groupByRollingEither eq f1
727+groupByRollingEither eq f1 = D.toParserK . D.groupByRollingEither eq f1
728728
729729-- | Match the given sequence of elements using the given comparison function.
730730--
@@ -737,7 +737,7 @@ groupByRollingEither eq f1 = K.toParserK . D.groupByRollingEither eq f1
737737--
738738{-# INLINE eqBy #-}
739739eqBy :: MonadCatch m => (a -> a -> Bool) -> [a] -> Parser m a ()
740−eqBy cmp = K.toParserK . D.eqBy cmp
740+eqBy cmp = D.toParserK . D.eqBy cmp
741741
742742-------------------------------------------------------------------------------
743743-- nested parsers
@@ -789,7 +789,7 @@ eqBy cmp = K.toParserK . D.eqBy cmp
789789serialWith :: MonadCatch m
790790 => (a -> b -> c) -> Parser m x a -> Parser m x b -> Parser m x c
791791serialWith f p1 p2 =
792− K.toParserK $ D.serialWith f (K.fromParserK p1) (K.fromParserK p2)
792+ D.toParserK $ D.serialWith f (D.fromParserK p1) (D.fromParserK p2)
793793
794794-- | Sequential parser application ignoring the output of the first parser.
795795-- Apply two parsers sequentially to an input stream. The input is provided to
@@ -813,7 +813,7 @@ serialWith f p1 p2 =
813813--
814814{-# INLINE split_ #-}
815815split_ :: MonadCatch m => Parser m x a -> Parser m x b -> Parser m x b
816−split_ p1 p2 = K.toParserK $ D.split_ (K.fromParserK p1) (K.fromParserK p2)
816+split_ p1 p2 = D.toParserK $ D.split_ (D.fromParserK p1) (D.fromParserK p2)
817817
818818-- | @teeWith f p1 p2@ distributes its input to both @p1@ and @p2@ until both
819819-- of them succeed or anyone of them fails and combines their output using @f@.
@@ -825,7 +825,7 @@ split_ p1 p2 = K.toParserK $ D.split_ (K.fromParserK p1) (K.fromParserK p2)
825825teeWith :: MonadCatch m
826826 => (a -> b -> c) -> Parser m x a -> Parser m x b -> Parser m x c
827827teeWith f p1 p2 =
828− K.toParserK $ D.teeWith f (K.fromParserK p1) (K.fromParserK p2)
828+ D.toParserK $ D.teeWith f (D.fromParserK p1) (D.fromParserK p2)
829829
830830-- | Like 'teeWith' but ends parsing and zips the results, if available,
831831-- whenever the first parser ends.
@@ -836,7 +836,7 @@ teeWith f p1 p2 =
836836teeWithFst :: MonadCatch m
837837 => (a -> b -> c) -> Parser m x a -> Parser m x b -> Parser m x c
838838teeWithFst f p1 p2 =
839− K.toParserK $ D.teeWithFst f (K.fromParserK p1) (K.fromParserK p2)
839+ D.toParserK $ D.teeWithFst f (D.fromParserK p1) (D.fromParserK p2)
840840
841841-- | Like 'teeWith' but ends parsing and zips the results, if available,
842842-- whenever any of the parsers ends or fails.
@@ -847,7 +847,7 @@ teeWithFst f p1 p2 =
847847teeWithMin :: MonadCatch m
848848 => (a -> b -> c) -> Parser m x a -> Parser m x b -> Parser m x c
849849teeWithMin f p1 p2 =
850− K.toParserK $ D.teeWithMin f (K.fromParserK p1) (K.fromParserK p2)
850+ D.toParserK $ D.teeWithMin f (D.fromParserK p1) (D.fromParserK p2)
851851
852852-- | Sequential alternative. Apply the input to the first parser and return the
853853-- result if the parser succeeds. If the first parser fails then backtrack and
@@ -868,7 +868,7 @@ teeWithMin f p1 p2 =
868868--
869869{-# INLINE alt #-}
870870alt :: MonadCatch m => Parser m x a -> Parser m x a -> Parser m x a
871−alt p1 p2 = K.toParserK $ D.alt (K.fromParserK p1) (K.fromParserK p2)
871+alt p1 p2 = D.toParserK $ D.alt (D.fromParserK p1) (D.fromParserK p2)
872872
873873-- | Shortest alternative. Apply both parsers in parallel but choose the result
874874-- from the one which consumed least input i.e. take the shortest succeeding
@@ -879,7 +879,7 @@ alt p1 p2 = K.toParserK $ D.alt (K.fromParserK p1) (K.fromParserK p2)
879879{-# INLINE shortest #-}
880880shortest :: MonadCatch m
881881 => Parser m x a -> Parser m x a -> Parser m x a
882−shortest p1 p2 = K.toParserK $ D.shortest (K.fromParserK p1) (K.fromParserK p2)
882+shortest p1 p2 = D.toParserK $ D.shortest (D.fromParserK p1) (D.fromParserK p2)
883883
884884-- | Longest alternative. Apply both parsers in parallel but choose the result
885885-- from the one which consumed more input i.e. take the longest succeeding
@@ -890,7 +890,7 @@ shortest p1 p2 = K.toParserK $ D.shortest (K.fromParserK p1) (K.fromParserK p2)
890890{-# INLINE longest #-}
891891longest :: MonadCatch m
892892 => Parser m x a -> Parser m x a -> Parser m x a
893−longest p1 p2 = K.toParserK $ D.longest (K.fromParserK p1) (K.fromParserK p2)
893+longest p1 p2 = D.toParserK $ D.longest (D.fromParserK p1) (D.fromParserK p2)
894894
895895-- | Run a parser without consuming the input.
896896--
@@ -898,7 +898,7 @@ longest p1 p2 = K.toParserK $ D.longest (K.fromParserK p1) (K.fromParserK p2)
898898--
899899{-# INLINE lookAhead #-}
900900lookAhead :: MonadCatch m => Parser m a b -> Parser m a b
901−lookAhead p = K.toParserK $ D.lookAhead $ K.fromParserK p
901+lookAhead p = D.toParserK $ D.lookAhead $ D.fromParserK p
902902
903903-- | Takes at-most @n@ input elements.
904904--
@@ -914,7 +914,7 @@ lookAhead p = K.toParserK $ D.lookAhead $ K.fromParserK p
914914-- /Internal/
915915{-# INLINE takeP #-}
916916takeP :: MonadCatch m => Int -> Parser m a b -> Parser m a b
917−takeP i p = K.toParserK $ D.takeP i $ K.fromParserK p
917+takeP i p = D.toParserK $ D.takeP i $ D.fromParserK p
918918
919919-------------------------------------------------------------------------------
920920-- Interleaving
@@ -982,7 +982,7 @@ concatSequence _f _p = undefined
982982{-# INLINE concatMap #-}
983983concatMap :: MonadCatch m
984984 => (b -> Parser m a c) -> Parser m a b -> Parser m a c
985−concatMap f p = K.toParserK $ D.concatMap (K.fromParserK . f) (K.fromParserK p)
985+concatMap f p = D.toParserK $ D.concatMap (D.fromParserK . f) (D.fromParserK p)
986986
987987-------------------------------------------------------------------------------
988988-- Alternative Collection
@@ -998,7 +998,7 @@ concatMap f p = K.toParserK $ D.concatMap (K.fromParserK . f) (K.fromParserK p)
998998{-# INLINE choice #-}
999999choice ::
10001000 (Functor t, Foldable t, MonadCatch m) => t (Parser m a b) -> Parser m a b
1001−choice ps = K.toParserK $ D.choice $ K.fromParserK <$> ps
1001+choice ps = D.toParserK $ D.choice $ D.fromParserK <$> ps
10021002
10031003-------------------------------------------------------------------------------
10041004-- Sequential Repetition
@@ -1017,7 +1017,7 @@ choice ps = K.toParserK $ D.choice $ K.fromParserK <$> ps
10171017{-# INLINE manyP #-}
10181018manyP :: -- MonadCatch m =>
10191019 Parser m a b -> Parser m b c -> Parser m a c
1020−manyP _p _f = undefined -- K.toParserK $ D.manyP (K.fromParserK p) f
1020+manyP _p _f = undefined -- D.toParserK $ D.manyP (D.fromParserK p) f
10211021
10221022-- | Collect zero or more parses. Apply the supplied parser repeatedly on the
10231023-- input stream and push the parse results to a downstream fold.
@@ -1031,7 +1031,7 @@ manyP _p _f = undefined -- K.toParserK $ D.manyP (K.fromParserK p) f
10311031--
10321032{-# INLINE many #-}
10331033many :: MonadCatch m => Parser m a b -> Fold m b c -> Parser m a c
1034−many p f = K.toParserK $ D.many (K.fromParserK p) f
1034+many p f = D.toParserK $ D.many (D.fromParserK p) f
10351035-- many = countBetween 0 maxBound
10361036
10371037-- Note: many1 would perhaps be a better name for this and consistent with
@@ -1052,7 +1052,7 @@ many p f = K.toParserK $ D.many (K.fromParserK p) f
10521052--
10531053{-# INLINE some #-}
10541054some :: MonadCatch m => Parser m a b -> Fold m b c -> Parser m a c
1055−some p f = K.toParserK $ D.some (K.fromParserK p) f
1055+some p f = D.toParserK $ D.some (D.fromParserK p) f
10561056-- some p f = manyP p (takeGE 1 f)
10571057-- many = countBetween 1 maxBound
10581058
@@ -1097,7 +1097,7 @@ count n = countBetween n n
10971097manyTillP :: -- MonadCatch m =>
10981098 Parser m a b -> Parser m a x -> Parser m b c -> Parser m a c
10991099manyTillP _p1 _p2 _f = undefined
1100− -- K.toParserK $ D.manyTillP (K.fromParserK p1) (K.fromParserK p2) f
1100+ -- D.toParserK $ D.manyTillP (D.fromParserK p1) (D.fromParserK p2) f
11011101
11021102-- | @manyTill f collect test@ tries the parser @test@ on the input, if @test@
11031103-- fails it backtracks and tries @collect@, after @collect@ succeeds @test@ is
@@ -1113,7 +1113,7 @@ manyTillP _p1 _p2 _f = undefined
11131113manyTill :: MonadCatch m
11141114 => Parser m a b -> Parser m a x -> Fold m b c -> Parser m a c
11151115manyTill p1 p2 f =
1116− K.toParserK $ D.manyTill f (K.fromParserK p1) (K.fromParserK p2)
1116+ D.toParserK $ D.manyTill f (D.fromParserK p1) (D.fromParserK p2)
11171117
11181118-- | @manyThen f collect recover@ repeats the parser @collect@ on the input and
11191119-- collects the output in the supplied fold. If the the parser @collect@ fails,
core/src/Streamly/Internal/Data/Parser/ParserD.hs+4
@@ -18,6 +18,10 @@ module Streamly.Internal.Data.Parser.ParserD
1818 , Initial (..)
1919 , rmapM
2020
21+ -- * Conversion to/from ParserK
22+ , fromParserK
23+ , toParserK
24+
2125 -- * Downgrade to Fold
2226 , toFold
2327
core/src/Streamly/Internal/Data/Parser/ParserD/Type.hs+172−2
@@ -119,6 +119,10 @@ module Streamly.Internal.Data.Parser.ParserD.Type
119119 , ParseError (..)
120120 , rmapM
121121
122+ -- * Conversion to/from ParserK
123+ , fromParserK
124+ , toParserK
125+
122126 -- * Constructors
123127 , parser
124128 , parserM
@@ -151,10 +155,12 @@ import Control.Monad.State.Class (MonadState, get, put)
151155import Control.Monad.Catch (MonadCatch, try, throwM, MonadThrow)
152156import Data.Bifunctor (Bifunctor(..))
153157import Fusion.Plugin.Types (Fuse(..))
158+import Streamly.Internal.Control.Exception (assertM)
154159import Streamly.Internal.Data.Fold.Type (Fold(..), toList)
155160import Streamly.Internal.Data.Tuple.Strict (Tuple3'(..))
156161
157162import qualified Streamly.Internal.Data.Fold.Type as FL
163+import qualified Streamly.Internal.Data.Parser.ParserK.Type as K
158164
159165import Prelude hiding (concatMap)
160166--
@@ -355,6 +361,170 @@ instance Functor m => Functor (Parser m a) where
355361 step s b = fmap2 f (step1 s b)
356362 fmap2 g = fmap (fmap g)
357363
364+-------------------------------------------------------------------------------
365+-- Convert direct style 'Parser' to CPS style 'K.Parser'
366+-------------------------------------------------------------------------------
367+
368+-- XXX Unlike the direct style folds/parsers, the initial action in CPS parsers
369+-- is not performed when the fold is initialized. It is performed when the
370+-- first element is processed by the fold or if no elements are processed then
371+-- at the extraction. We should either make the direct folds like this or make
372+-- the CPS folds behavior also like the direct ones.
373+--
374+-- | Convert a direct style parser ('D.Parser') to a CPS style parser
375+-- ('Parser').
376+--
377+{-# INLINE_NORMAL parseDToK #-}
378+parseDToK
379+ :: MonadCatch m
380+ => (s -> a -> m (Step s b))
381+ -> m (Initial s b)
382+ -> (s -> m b)
383+ -> Int
384+ -> (Int, Int)
385+ -> ((Int, Int) -> K.Parse b -> m (K.Driver m a r))
386+ -> m (K.Driver m a r)
387+
388+parseDToK pstep initial extract leftover (0, _) cont = do
389+ res <- initial
390+ case res of
391+ IPartial r -> return $ K.Continue leftover (parseCont (return r))
392+ IDone b -> cont (0,0) (K.Done 0 b)
393+ IError err -> cont (0,0) (K.Error err)
394+
395+ where
396+
397+ parseCont pst (Just x) = do
398+ r <- pst
399+ pRes <- pstep r x
400+ case pRes of
401+ Done n b -> cont (0,0) (K.Done n b)
402+ Error err -> cont (0,0) (K.Error err)
403+ Partial n pst1 -> return $ K.Partial n (parseCont (return pst1))
404+ Continue n pst1 -> return $ K.Continue n (parseCont (return pst1))
405+
406+ parseCont acc Nothing = do
407+ pst <- acc
408+ r <- try $ extract pst
409+ case r of
410+ Left (e :: ParseError) -> cont (0,0) (K.Error (displayException e))
411+ Right b -> cont (0,0) (K.Done 0 b)
412+
413+parseDToK pstep initial extract leftover (level, count) cont = do
414+ res <- initial
415+ case res of
416+ IPartial r -> return $ K.Continue leftover (parseCont count (return r))
417+ IDone b -> cont (level,count) (K.Done 0 b)
418+ IError err -> cont (level,count) (K.Error err)
419+
420+ where
421+
422+ parseCont !cnt pst (Just x) = do
423+ let !cnt1 = cnt + 1
424+ r <- pst
425+ pRes <- pstep r x
426+ case pRes of
427+ Done n b -> do
428+ assert (n <= cnt1) (return ())
429+ cont (level, cnt1 - n) (K.Done n b)
430+ Error err ->
431+ cont (level, cnt1) (K.Error err)
432+ Partial n pst1 -> do
433+ assert (n <= cnt1) (return ())
434+ return $ K.Partial n (parseCont (cnt1 - n) (return pst1))
435+ Continue n pst1 -> do
436+ assert (n <= cnt1) (return ())
437+ return $ K.Continue n (parseCont (cnt1 - n) (return pst1))
438+ parseCont cnt acc Nothing = do
439+ pst <- acc
440+ r <- try $ extract pst
441+ let s = (level, cnt)
442+ case r of
443+ Left (e :: ParseError) -> cont s (K.Error (displayException e))
444+ Right b -> cont s (K.Done 0 b)
445+
446+-- | Convert a direct style 'Parser' to a CPS style 'K.Parser'.
447+--
448+-- /Pre-release/
449+--
450+{-# INLINE_LATE toParserK #-}
451+toParserK :: MonadCatch m => Parser m a b -> K.Parser m a b
452+toParserK (Parser step initial extract) =
453+ K.MkParser $ parseDToK step initial extract
454+
455+-------------------------------------------------------------------------------
456+-- Convert CPS style 'Parser' to direct style 'D.Parser'
457+-------------------------------------------------------------------------------
458+
459+-- | A continuation to extract the result when a CPS parser is done.
460+{-# INLINE parserDone #-}
461+parserDone :: Monad m => (Int, Int) -> K.Parse b -> m (K.Driver m a b)
462+parserDone (0,_) (K.Done n b) = return $ K.Stop n b
463+parserDone st (K.Done _ _) =
464+ error $ "Bug: fromParserK: inside alternative: " ++ show st
465+parserDone _ (K.Error e) = return $ K.Failed e
466+
467+-- | When there is no more input to feed, extract the result from the Parser.
468+--
469+-- /Pre-release/
470+--
471+extractParse :: MonadThrow m => (Maybe a -> m (K.Driver m a b)) -> m b
472+extractParse cont = do
473+ r <- cont Nothing
474+ case r of
475+ K.Stop _ b -> return b
476+ K.Partial _ _ -> error "Bug: extractParse got Partial"
477+ K.Continue _ cont1 -> extractParse cont1
478+ K.Failed e -> throwM $ ParseError e
479+
480+data FromParserK b c = FPKDone !Int !b | FPKCont c
481+
482+-- | Convert a CPS style 'K.Parser' to a direct style 'Parser'.
483+--
484+-- "initial" returns a continuation which can be called one input at a time
485+-- using the "step" function.
486+--
487+-- /Pre-release/
488+--
489+{-# INLINE_LATE fromParserK #-}
490+fromParserK :: MonadThrow m => K.Parser m a b -> Parser m a b
491+fromParserK parser0 = Parser step initial extract
492+
493+ where
494+
495+ initial = do
496+ r <- K.runParser parser0 0 (0,0) parserDone
497+ return $ case r of
498+ K.Stop n b -> IPartial $ FPKDone n b
499+ K.Failed e -> IError e
500+ K.Partial _ cont -> IPartial $ FPKCont cont -- XXX can we get this?
501+ K.Continue _ cont -> IPartial $ FPKCont cont
502+
503+ -- Note, we can only reach FPKDone and FPKError from "initial". FPKCont
504+ -- always transitions to only FPKCont. The input remains unconsumed in
505+ -- this case so we use "n + 1".
506+ step (FPKDone n b) _ = do
507+ assertM (n == 0)
508+ return $ Done (n + 1) b
509+ step (FPKCont cont) a = do
510+ r <- cont (Just a)
511+ return $ case r of
512+ K.Stop n b -> Done n b
513+ K.Failed e -> Error e
514+ K.Partial n cont1 -> Partial n (FPKCont cont1)
515+ K.Continue n cont1 -> Continue n (FPKCont cont1)
516+
517+ -- Note, we can only reach FPKDone and FPKError from "initial".
518+ extract (FPKDone _ b) = return b
519+ extract (FPKCont cont) = extractParse cont
520+
521+#ifndef DISABLE_FUSION
522+{-# RULES "fromParserK/toParserK fusion" [2]
523+ forall s. toParserK (fromParserK s) = s #-}
524+{-# RULES "toParserK/fromParserK fusion" [2]
525+ forall s. fromParserK (toParserK s) = s #-}
526+#endif
527+
358528------------------------------------------------------------------------------
359529-- General parser constructors
360530------------------------------------------------------------------------------
@@ -1160,20 +1330,20 @@ instance MonadCatch m => MonadPlus (Parser m a) where
11601330instance (MonadThrow m, MonadReader r m, MonadCatch m) => MonadReader r (Parser m a) where
11611331 {-# INLINE ask #-}
11621332 ask = fromEffect ask
1333+
11631334 {-# INLINE local #-}
11641335 local f (Parser step init' extract) =
11651336 Parser ((local f .) . step)
11661337 (local f init')
11671338 (local f . extract)
11681339
1169−
11701340instance (MonadThrow m, MonadState s m) => MonadState s (Parser m a) where
11711341 {-# INLINE get #-}
11721342 get = fromEffect get
1343+
11731344 {-# INLINE put #-}
11741345 put = fromEffect . put
11751346
1176−
11771347instance (MonadThrow m, MonadIO m) => MonadIO (Parser m a) where
11781348 {-# INLINE liftIO #-}
11791349 liftIO = fromEffect . liftIO
core/src/Streamly/Internal/Data/Parser/ParserK/Type.hs+12−179
@@ -21,21 +21,18 @@
2121
2222module Streamly.Internal.Data.Parser.ParserK.Type
2323 (
24− Parser (..)
24+ Driver (..)
25+ , Parse (..)
26+ , Parser (..)
2527 , fromPure
2628 , fromEffect
2729 , die
28−
29− -- * Conversion
30− , toParserK
31− , fromParserK
3230 )
3331where
3432
3533import Control.Applicative (Alternative(..), liftA2)
36−import Control.Exception (assert, Exception(..))
3734import Control.Monad (MonadPlus(..), ap)
38−import Control.Monad.Catch (MonadCatch, MonadThrow(..), try)
35+import Control.Monad.Catch (MonadCatch, MonadThrow(..))
3936import Control.Monad.IO.Class (MonadIO, liftIO)
4037import Control.Monad.Reader.Class (MonadReader, ask, local)
4138import Control.Monad.State.Class (MonadState, get, put)
@@ -45,9 +42,6 @@ import qualified Control.Monad.Fail as Fail
4542#if !(MIN_VERSION_base(4,10,0))
4643import Data.Semigroup ((<>))
4744#endif
48−import Streamly.Internal.Control.Exception
49−
50−import qualified Streamly.Internal.Data.Parser.ParserD.Type as D
5145
5246-- | The parse driver result. The driver may stop with a final result, pause
5347-- with a continuation to resume, or fail with an error.
@@ -103,170 +97,6 @@ newtype Parser m a b = MkParser
10397 -> m (Driver m a r)
10498 }
10599
106−-------------------------------------------------------------------------------
107−-- Convert direct style 'D.Parser' to CPS style 'Parser'
108−-------------------------------------------------------------------------------
109−
110−-- XXX Unlike the direct style folds/parsers, the initial action in CPS parsers
111−-- is not performed when the fold is initialized. It is performed when the
112−-- first element is processed by the fold or if no elements are processed then
113−-- at the extraction. We should either make the direct folds like this or make
114−-- the CPS folds behavior also like the direct ones.
115−--
116−-- | Convert a direct style parser ('D.Parser') to a CPS style parser
117−-- ('Parser').
118−--
119−{-# INLINE_NORMAL parseDToK #-}
120−parseDToK
121− :: MonadCatch m
122− => (s -> a -> m (D.Step s b))
123− -> m (D.Initial s b)
124− -> (s -> m b)
125− -> Int
126− -> (Int, Int)
127− -> ((Int, Int) -> Parse b -> m (Driver m a r))
128− -> m (Driver m a r)
129−
130−parseDToK pstep initial extract leftover (0, _) cont = do
131− res <- initial
132− case res of
133− D.IPartial r -> return $ Continue leftover (parseCont (return r))
134− D.IDone b -> cont (0,0) (Done 0 b)
135− D.IError err -> cont (0,0) (Error err)
136−
137− where
138−
139− parseCont pst (Just x) = do
140− r <- pst
141− pRes <- pstep r x
142− case pRes of
143− D.Done n b -> cont (0,0) (Done n b)
144− D.Error err -> cont (0,0) (Error err)
145− D.Partial n pst1 -> return $ Partial n (parseCont (return pst1))
146− D.Continue n pst1 -> return $ Continue n (parseCont (return pst1))
147−
148− parseCont acc Nothing = do
149− pst <- acc
150− r <- try $ extract pst
151− case r of
152− Left (e :: D.ParseError) -> cont (0,0) (Error (displayException e))
153− Right b -> cont (0,0) (Done 0 b)
154−
155−parseDToK pstep initial extract leftover (level, count) cont = do
156− res <- initial
157− case res of
158− D.IPartial r -> return $ Continue leftover (parseCont count (return r))
159− D.IDone b -> cont (level,count) (Done 0 b)
160− D.IError err -> cont (level,count) (Error err)
161−
162− where
163−
164− parseCont !cnt pst (Just x) = do
165− let !cnt1 = cnt + 1
166− r <- pst
167− pRes <- pstep r x
168− case pRes of
169− D.Done n b -> do
170− assert (n <= cnt1) (return ())
171− cont (level, cnt1 - n) (Done n b)
172− D.Error err ->
173− cont (level, cnt1) (Error err)
174− D.Partial n pst1 -> do
175− assert (n <= cnt1) (return ())
176− return $ Partial n (parseCont (cnt1 - n) (return pst1))
177− D.Continue n pst1 -> do
178− assert (n <= cnt1) (return ())
179− return $ Continue n (parseCont (cnt1 - n) (return pst1))
180− parseCont cnt acc Nothing = do
181− pst <- acc
182− r <- try $ extract pst
183− let s = (level, cnt)
184− case r of
185− Left (e :: D.ParseError) -> cont s (Error (displayException e))
186− Right b -> cont s (Done 0 b)
187−
188−-- | Convert a direct style 'D.Parser' to a CPS style 'Parser'.
189−--
190−-- /Pre-release/
191−--
192−{-# INLINE_LATE toParserK #-}
193−toParserK :: MonadCatch m => D.Parser m a b -> Parser m a b
194−toParserK (D.Parser step initial extract) =
195− MkParser $ parseDToK step initial extract
196−
197−-------------------------------------------------------------------------------
198−-- Convert CPS style 'Parser' to direct style 'D.Parser'
199−-------------------------------------------------------------------------------
200−
201−-- | A continuation to extract the result when a CPS parser is done.
202−{-# INLINE parserDone #-}
203−parserDone :: Monad m => (Int, Int) -> Parse b -> m (Driver m a b)
204−parserDone (0,_) (Done n b) = return $ Stop n b
205−parserDone st (Done _ _) =
206− error $ "Bug: fromParserK: inside alternative: " ++ show st
207−parserDone _ (Error e) = return $ Failed e
208−
209−-- | When there is no more input to feed, extract the result from the Parser.
210−--
211−-- /Pre-release/
212−--
213−extractParse :: MonadThrow m => (Maybe a -> m (Driver m a b)) -> m b
214−extractParse cont = do
215− r <- cont Nothing
216− case r of
217− Stop _ b -> return b
218− Partial _ _ -> error "Bug: extractParse got Partial"
219− Continue _ cont1 -> extractParse cont1
220− Failed e -> throwM $ D.ParseError e
221−
222−data FromParserK b c = FPKDone !Int !b | FPKCont c
223−
224−-- | Convert a CPS style 'Parser' to a direct style 'D.Parser'.
225−--
226−-- "initial" returns a continuation which can be called one input at a time
227−-- using the "step" function.
228−--
229−-- /Pre-release/
230−--
231−{-# INLINE_LATE fromParserK #-}
232−fromParserK :: MonadThrow m => Parser m a b -> D.Parser m a b
233−fromParserK parser = D.Parser step initial extract
234−
235− where
236−
237− initial = do
238− r <- runParser parser 0 (0,0) parserDone
239− return $ case r of
240− Stop n b -> D.IPartial $ FPKDone n b
241− Failed e -> D.IError e
242− Partial _ cont -> D.IPartial $ FPKCont cont -- XXX can we get this?
243− Continue _ cont -> D.IPartial $ FPKCont cont
244−
245− -- Note, we can only reach FPKDone and FPKError from "initial". FPKCont
246− -- always transitions to only FPKCont. The input remains unconsumed in
247− -- this case so we use "n + 1".
248− step (FPKDone n b) _ = do
249− assertM (n == 0)
250− return $ D.Done (n + 1) b
251− step (FPKCont cont) a = do
252− r <- cont (Just a)
253− return $ case r of
254− Stop n b -> D.Done n b
255− Failed e -> D.Error e
256− Partial n cont1 -> D.Partial n (FPKCont cont1)
257− Continue n cont1 -> D.Continue n (FPKCont cont1)
258−
259− -- Note, we can only reach FPKDone and FPKError from "initial".
260− extract (FPKDone _ b) = return b
261− extract (FPKCont cont) = extractParse cont
262−
263−#ifndef DISABLE_FUSION
264−{-# RULES "fromParserK/toParserK fusion" [2]
265− forall s. toParserK (fromParserK s) = s #-}
266−{-# RULES "toParserK/fromParserK fusion" [2]
267− forall s. fromParserK (toParserK s) = s #-}
268−#endif
269−
270100-------------------------------------------------------------------------------
271101-- Functor
272102-------------------------------------------------------------------------------
@@ -415,21 +245,24 @@ instance Monad m => Fail.MonadFail (Parser m a) where
415245 fail = die
416246#endif
417247
418−instance (MonadThrow m, MonadReader r m, MonadCatch m) => MonadReader r (Parser m a) where
248+instance (MonadThrow m, MonadReader r m, MonadCatch m) =>
249+ MonadReader r (Parser m a) where
250+
419251 {-# INLINE ask #-}
420252 ask = fromEffect ask
421− {-# INLINE local #-}
422− local f (fromParserK -> dp) =
423− toParserK $ local f dp
424253
254+ {-# INLINE local #-}
255+ local f dp =
256+ MkParser $ \lo st yieldk ->
257+ local f $ runParser dp lo st yieldk
425258
426259instance (MonadThrow m, MonadState s m) => MonadState s (Parser m a) where
427260 {-# INLINE get #-}
428261 get = fromEffect get
262+
429263 {-# INLINE put #-}
430264 put = fromEffect . put
431265
432−
433266instance (MonadThrow m, MonadIO m) => MonadIO (Parser m a) where
434267 {-# INLINE liftIO #-}
435268 liftIO = fromEffect . liftIO
core/src/Streamly/Internal/Data/Producer/Source.hs+2−2
@@ -202,7 +202,7 @@ parse
202202 -> Producer m (Source s a) a
203203 -> Source s a
204204 -> m (b, Source s a)
205−parse = parseD . ParserK.fromParserK
205+parse = parseD . ParserD.fromParserK
206206
207207-------------------------------------------------------------------------------
208208-- Nested parsing
@@ -234,4 +234,4 @@ parseMany :: MonadThrow m =>
234234 ParserK.Parser m a b
235235 -> Producer m (Source x a) a
236236 -> Producer m (Source x a) b
237−parseMany parser = parseManyD (ParserK.fromParserK parser)
237+parseMany parser = parseManyD (ParserD.fromParserK parser)
src/Streamly/Internal/Data/Binary/Decode.hs+6−7
@@ -35,7 +35,6 @@ import Streamly.Internal.Data.Tuple.Strict (Tuple' (..))
3535import qualified Streamly.Internal.Data.Array.Foreign as A
3636import qualified Streamly.Internal.Data.Parser as PR
3737import qualified Streamly.Internal.Data.Parser.ParserD as PRD
38−import qualified Streamly.Internal.Data.Parser.ParserK.Type as PRK
3938
4039-- | A value of type '()' is encoded as @0@ in binary encoding.
4140--
@@ -131,7 +130,7 @@ word16beD = PRD.Parser step initial extract
131130--
132131{-# INLINE word16be #-}
133132word16be :: MonadCatch m => Parser m Word8 Word16
134−word16be = PRK.toParserK word16beD
133+word16be = PRD.toParserK word16beD
135134
136135-- | Little endian (LSB first) Word16
137136{-# INLINE word16leD #-}
@@ -156,7 +155,7 @@ word16leD = PRD.Parser step initial extract
156155--
157156{-# INLINE word16le #-}
158157word16le :: MonadCatch m => Parser m Word8 Word16
159−word16le = PRK.toParserK word16leD
158+word16le = PRD.toParserK word16leD
160159
161160-- | Big endian (MSB first) Word32
162161{-# INLINE word32beD #-}
@@ -183,7 +182,7 @@ word32beD = PRD.Parser step initial extract
183182--
184183{-# INLINE word32be #-}
185184word32be :: MonadCatch m => Parser m Word8 Word32
186−word32be = PRK.toParserK word32beD
185+word32be = PRD.toParserK word32beD
187186
188187-- | Little endian (LSB first) Word32
189188{-# INLINE word32leD #-}
@@ -209,7 +208,7 @@ word32leD = PRD.Parser step initial extract
209208--
210209{-# INLINE word32le #-}
211210word32le :: MonadCatch m => Parser m Word8 Word32
212−word32le = PRK.toParserK word32leD
211+word32le = PRD.toParserK word32leD
213212
214213-- | Big endian (MSB first) Word64
215214{-# INLINE word64beD #-}
@@ -236,7 +235,7 @@ word64beD = PRD.Parser step initial extract
236235--
237236{-# INLINE word64be #-}
238237word64be :: MonadCatch m => Parser m Word8 Word64
239−word64be = PRK.toParserK word64beD
238+word64be = PRD.toParserK word64beD
240239
241240-- | Little endian (LSB first) Word64
242241{-# INLINE word64leD #-}
@@ -262,7 +261,7 @@ word64leD = PRD.Parser step initial extract
262261--
263262{-# INLINE word64le #-}
264263word64le :: MonadCatch m => Parser m Word8 Word64
265−word64le = PRK.toParserK word64leD
264+word64le = PRD.toParserK word64leD
266265
267266-------------------------------------------------------------------------------
268267-- Host byte order
src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs+2−2
@@ -403,7 +403,7 @@ parseK = parse
403403--
404404{-# INLINE [3] parse #-}
405405parse :: MonadThrow m => Parser m a b -> SerialT m a -> m b
406−parse = parseD . PRK.fromParserK
406+parse = parseD . PRD.fromParserK
407407
408408{-# INLINE_NORMAL parseD_ #-}
409409parseD_ :: MonadThrow m => PRD.Parser m a b -> SerialT m a -> m (b, SerialT m a)
@@ -417,7 +417,7 @@ parseD_ parser strm = do
417417--
418418{-# INLINE [3] parse_ #-}
419419parse_ :: MonadThrow m => Parser m a b -> SerialT m a -> m (b, SerialT m a)
420−parse_ = parseD_ . PRK.fromParserK
420+parse_ = parseD_ . PRD.fromParserK
421421
422422------------------------------------------------------------------------------
423423-- Specific Fold Functions
src/Streamly/Internal/Data/Stream/IsStream/Reduce.hs+2−3
@@ -180,7 +180,6 @@ import qualified Data.Heap as H
180180import qualified Data.Map.Strict as Map
181181import qualified Streamly.Internal.Data.Array.Foreign.Type as A
182182import qualified Streamly.Internal.Data.Fold as FL
183−import qualified Streamly.Internal.Data.Parser.ParserK.Type as PRK
184183import qualified Streamly.Internal.Data.Parser.ParserD as PRD
185184import qualified Streamly.Internal.Data.Stream.IsStream.Type as IsStream
186185import qualified Streamly.Internal.Data.Stream.StreamD as D
@@ -384,7 +383,7 @@ parseMany
384383 -> t m a
385384 -> t m b
386385parseMany p m =
387− fromStreamD $ D.parseMany (PRK.fromParserK p) (toStreamD m)
386+ fromStreamD $ D.parseMany (PRD.fromParserK p) (toStreamD m)
388387
389388{-# INLINE parseManyD #-}
390389parseManyD
@@ -448,7 +447,7 @@ parseIterate
448447 -> t m a
449448 -> t m b
450449parseIterate f i m = fromStreamD $
451− D.parseIterate (PRK.fromParserK . f) i (toStreamD m)
450+ D.parseIterate (PRD.fromParserK . f) i (toStreamD m)
452451
453452------------------------------------------------------------------------------
454453-- Generalized grouping
src/Streamly/Internal/Unicode/Stream.hs+1−2
@@ -107,7 +107,6 @@ import Streamly.Internal.System.IO (unsafeInlineIO)
107107import qualified Streamly.Internal.Data.Unfold as Unfold
108108import qualified Streamly.Internal.Data.Parser as Parser
109109import qualified Streamly.Internal.Data.Parser.ParserD as ParserD
110−import qualified Streamly.Internal.Data.Parser.ParserK.Type as ParserK
111110import qualified Streamly.Internal.Data.Stream.Serial as Serial
112111import qualified Streamly.Internal.Data.Array.Foreign as Array
113112import qualified Streamly.Internal.Data.Array.Foreign.Type as A
@@ -518,7 +517,7 @@ writeCharUtf8' = ParserD.toFold (parseCharUtf8WithD ErrorOnCodingFailure)
518517{-# INLINE parseCharUtf8With #-}
519518parseCharUtf8With ::
520519 MonadCatch m => CodingFailureMode -> Parser.Parser m Word8 Char
521−parseCharUtf8With = ParserK.toParserK . parseCharUtf8WithD
520+parseCharUtf8With = ParserD.toParserK . parseCharUtf8WithD
522521
523522-- XXX write it as a parser and use parseMany to decode a stream, need to check
524523-- if that preserves the same performance. Or we can use a resumable parser