@@ -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,