@@ -73,7 +73,7 @@ import Streamly.Internal.Data.Parser.ParserD.Types
73-- source for individual parser backtracking. Problem arises when both the
73-- source for individual parser backtracking. Problem arises when both the
74-- parsers backtrack and they do not need any input from the driver rather they
74-- parsers backtrack and they do not need any input from the driver rather they
75-- must consume from their buffers. For such situation we may need a
75-- must consume from their buffers. For such situation we may need a
76−-- "Skip/Continue" style driver command from the tee so that the driver runs
76+-- "Continue" style driver command from the tee so that the driver runs
77-- the tee without providing it any input. Or we may need a local driver loop
77-- the tee without providing it any input. Or we may need a local driver loop
78-- until new input is to be demanded from the input stream.
78-- until new input is to be demanded from the input stream.
@@ -137,19 +137,19 @@ teeWith zf (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
137 useStream buf inp1 inp2 stp st y = do
137 useStream buf inp1 inp2 stp st y = do
138 (buf1, r, inp11, inp21) <- consume buf inp1 inp2 stp st y
138 (buf1, r, inp11, inp21) <- consume buf inp1 inp2 stp st y
139 case r of
139 case r of
140− Yield 0 s ->
140+ Partial 0 s ->
141 let state = ([], StepState s, inp11, inp21)
141 let state = ([], StepState s, inp11, inp21)
142 in return (state, Yld 0)
142 in return (state, Yld 0)
143− Yield n s ->
143+ Partial n s ->
144 let src0 = Prelude.take n buf1
144 let src0 = Prelude.take n buf1
145 src = Prelude.reverse src0
145 src = Prelude.reverse src0
146 state = ([], StepState s, src ++ inp11, inp21)
146 state = ([], StepState s, src ++ inp11, inp21)
147 in assert (n <= length buf1) (return (state, Yld n))
147 in assert (n <= length buf1) (return (state, Yld n))
148− Stop n b ->
148+ Done n b ->
149 let state = (Prelude.take n buf1, StepResult b, inp11, inp21)
149 let state = (Prelude.take n buf1, StepResult b, inp11, inp21)
150 in assert (n <= length buf1) (return (state, Stp n))
150 in assert (n <= length buf1) (return (state, Stp n))
151− -- Skip 0 s -> (buf1, Right s, inp11, inp21)
151+ -- Continue 0 s -> (buf1, Right s, inp11, inp21)
152− Skip n s ->
152+ Continue n s ->
153 let (src0, buf2) = splitAt n buf1
153 let (src0, buf2) = splitAt n buf1
154 src = Prelude.reverse src0
154 src = Prelude.reverse src0
155 state = (buf2, StepState s, src ++ inp11, inp21)
155 state = (buf2, StepState s, src ++ inp11, inp21)
@@ -163,18 +163,18 @@ teeWith zf (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
163 (r,stR) <- useStream bufR inpR1 inpR2 stepR sR x
163 (r,stR) <- useStream bufR inpR1 inpR2 stepR sR x
164 let next = TeePair l r
164 let next = TeePair l r
165 return $ case (stL,stR) of
165 return $ case (stL,stR) of
166− (Yld n1, Yld n2) -> Yield (min n1 n2) next
166+ (Yld n1, Yld n2) -> Partial (min n1 n2) next
167− (Yld n1, Stp n2) -> Yield (min n1 n2) next
167+ (Yld n1, Stp n2) -> Partial (min n1 n2) next
168− (Stp n1, Yld n2) -> Yield (min n1 n2) next
168+ (Stp n1, Yld n2) -> Partial (min n1 n2) next
169 (Stp n1, Stp n2) ->
169 (Stp n1, Stp n2) ->
170 -- Uni-pattern match results in better optimized code compared
170 -- Uni-pattern match results in better optimized code compared
171 -- to a case match.
171 -- to a case match.
172 let (_, StepResult rL, _, _) = l
172 let (_, StepResult rL, _, _) = l
173 (_, StepResult rR, _, _) = r
173 (_, StepResult rR, _, _) = r
174− in Stop (min n1 n2) (zf rL rR)
174+ in Done (min n1 n2) (zf rL rR)
175 (Err err, _) -> Error err
175 (Err err, _) -> Error err
176 (_, Err err) -> Error err
176 (_, Err err) -> Error err
177− _ -> Skip 0 next
177+ _ -> Continue 0 next
179 step (TeePair (bufL, StepState sL, inpL1, inpL2)
179 step (TeePair (bufL, StepState sL, inpL1, inpL2)
180 r@(_, StepResult rR, _, _)) x = do
180 r@(_, StepResult rR, _, _)) x = do
@@ -185,11 +185,11 @@ teeWith zf (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
185 -- to fix the other case. We need to keep incrementing the unused count
185 -- to fix the other case. We need to keep incrementing the unused count
186 -- of the stopped stream and take the min of the two.
186 -- of the stopped stream and take the min of the two.
187 return $ case stL of
187 return $ case stL of
188− Yld n -> Yield n next
188+ Yld n -> Partial n next
190 let (_, StepResult rL, _, _) = l
190 let (_, StepResult rL, _, _) = l
191− in Stop n (zf rL rR)
191+ in Done n (zf rL rR)
192− Skp -> Skip 0 next
192+ Skp -> Continue 0 next
193 Err err -> Error err
193 Err err -> Error err
195 step (TeePair l@(_, StepResult rL, _, _)
195 step (TeePair l@(_, StepResult rL, _, _)
@@ -201,11 +201,11 @@ teeWith zf (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
201 -- to fix the other case. We need to keep incrementing the unused count
201 -- to fix the other case. We need to keep incrementing the unused count
202 -- of the stopped stream and take the min of the two.
202 -- of the stopped stream and take the min of the two.
203 return $ case stR of
203 return $ case stR of
204− Yld n -> Yield n next
204+ Yld n -> Partial n next
206 let (_, StepResult rR, _, _) = r
206 let (_, StepResult rR, _, _) = r
207− in Stop n (zf rL rR)
207+ in Done n (zf rL rR)
208− Skp -> Skip 0 next
208+ Skp -> Continue 0 next
209 Err err -> Error err
209 Err err -> Error err
211 step _ _ = undefined
211 step _ _ = undefined
@@ -261,15 +261,15 @@ teeWithFst zf (Parser stepL initialL extractL)
261 useStream buf inp1 inp2 stp st y = do
261 useStream buf inp1 inp2 stp st y = do
262 (buf1, r, inp11, inp21) <- consume buf inp1 inp2 stp st y
262 (buf1, r, inp11, inp21) <- consume buf inp1 inp2 stp st y
263 case r of
263 case r of
264− Yield 0 s ->
264+ Partial 0 s ->
265 let state = ([], StepState s, inp11, inp21)
265 let state = ([], StepState s, inp11, inp21)
266 in return (state, Yld 0)
266 in return (state, Yld 0)
267− Yield n _ -> return (undefined, Yld n) -- Not implemented
267+ Partial n _ -> return (undefined, Yld n) -- Not implemented
268− Stop n b ->
268+ Done n b ->
269 let state = (Prelude.take n buf1, StepResult b, inp11, inp21)
269 let state = (Prelude.take n buf1, StepResult b, inp11, inp21)
270 in assert (n <= length buf1) (return (state, Stp n))
270 in assert (n <= length buf1) (return (state, Stp n))
271− -- Skip 0 s -> (buf1, Right s, inp11, inp21)
271+ -- Continue 0 s -> (buf1, Right s, inp11, inp21)
272− Skip n s ->
272+ Continue n s ->
273 let (src0, buf2) = splitAt n buf1
273 let (src0, buf2) = splitAt n buf1
274 src = Prelude.reverse src0
274 src = Prelude.reverse src0
275 state = (buf2, StepState s, src ++ inp11, inp21)
275 state = (buf2, StepState s, src ++ inp11, inp21)
@@ -293,18 +293,18 @@ teeWithFst zf (Parser stepL initialL extractL)
293 -- to a case match.
293 -- to a case match.
294 let (_, StepResult rL, _, _) = l
294 let (_, StepResult rL, _, _) = l
295 (_, StepResult rR, _, _) = r
295 (_, StepResult rR, _, _) = r
296− in return $ Stop n1 (zf rL rR)
296+ in return $ Done n1 (zf rL rR)
297 (Stp n1, Yld _) ->
297 (Stp n1, Yld _) ->
298 let (_, StepResult rL, _, _) = l
298 let (_, StepResult rL, _, _) = l
299 (_, StepState ssR, _, _) = r
299 (_, StepState ssR, _, _) = r
301 rR <- extractR ssR
301 rR <- extractR ssR
302− return $ Stop n1 (zf rL rR)
302+ return $ Done n1 (zf rL rR)
303− (Yld n1, Yld n2) -> return $ Yield (min n1 n2) next
303+ (Yld n1, Yld n2) -> return $ Partial (min n1 n2) next
304− (Yld n1, Stp n2) -> return $ Yield (min n1 n2) next
304+ (Yld n1, Stp n2) -> return $ Partial (min n1 n2) next
305 (Err err, _) -> return $ Error err
305 (Err err, _) -> return $ Error err
306 (_, Err err) -> return $ Error err
306 (_, Err err) -> return $ Error err
307− _ -> return $ Skip 0 next
307+ _ -> return $ Continue 0 next
309 step (TeePair (bufL, StepState sL, inpL1, inpL2)
309 step (TeePair (bufL, StepState sL, inpL1, inpL2)
310 r@(_, StepResult rR, _, _)) x = do
310 r@(_, StepResult rR, _, _)) x = do
@@ -315,11 +315,11 @@ teeWithFst zf (Parser stepL initialL extractL)
315 -- to fix the other case. We need to keep incrementing the unused count
315 -- to fix the other case. We need to keep incrementing the unused count
316 -- of the stopped stream and take the min of the two.
316 -- of the stopped stream and take the min of the two.
317 return $ case stL of
317 return $ case stL of
318− Yld n -> Yield n next
318+ Yld n -> Partial n next
320 let (_, StepResult rL, _, _) = l
320 let (_, StepResult rL, _, _) = l
321− in Stop n (zf rL rR)
321+ in Done n (zf rL rR)
322− Skp -> Skip 0 next
322+ Skp -> Continue 0 next
323 Err err -> Error err
323 Err err -> Error err
325 step _ _ = undefined
325 step _ _ = undefined
@@ -383,15 +383,15 @@ shortest (Parser stepL initialL extractL) (Parser stepR initialR _) =
383 useStream buf inp1 inp2 stp st y = do
383 useStream buf inp1 inp2 stp st y = do
384 (buf1, r, inp11, inp21) <- consume buf inp1 inp2 stp st y
384 (buf1, r, inp11, inp21) <- consume buf inp1 inp2 stp st y
385 case r of
385 case r of
386− Yield 0 s ->
386+ Partial 0 s ->
387 let state = ([], StepState s, inp11, inp21)
387 let state = ([], StepState s, inp11, inp21)
388 in return (state, Yld 0)
388 in return (state, Yld 0)
389− Yield n _ -> return (undefined, Yld n) -- Not implemented
389+ Partial n _ -> return (undefined, Yld n) -- Not implemented
390− Stop n b ->
390+ Done n b ->
391 let state = (Prelude.take n buf1, StepResult b, inp11, inp21)
391 let state = (Prelude.take n buf1, StepResult b, inp11, inp21)
392 in assert (n <= length buf1) (return (state, Stp n))
392 in assert (n <= length buf1) (return (state, Stp n))
393− -- Skip 0 s -> (buf1, Right s, inp11, inp21)
393+ -- Continue 0 s -> (buf1, Right s, inp11, inp21)
394− Skip n s ->
394+ Continue n s ->
395 let (src0, buf2) = splitAt n buf1
395 let (src0, buf2) = splitAt n buf1
396 src = Prelude.reverse src0
396 src = Prelude.reverse src0
397 state = (buf2, StepState s, src ++ inp11, inp21)
397 state = (buf2, StepState s, src ++ inp11, inp21)
@@ -410,14 +410,14 @@ shortest (Parser stepL initialL extractL) (Parser stepR initialR _) =
410 return $ case (stL,stR) of
410 return $ case (stL,stR) of
411 (Stp n1, _) ->
411 (Stp n1, _) ->
412 let (_, StepResult rL, _, _) = l
412 let (_, StepResult rL, _, _) = l
413− in Stop n1 rL
413+ in Done n1 rL
414 (_, Stp n2) ->
414 (_, Stp n2) ->
415 let (_, StepResult rR, _, _) = r
415 let (_, StepResult rR, _, _) = r
416− in Stop n2 rR
416+ in Done n2 rR
417− (Yld n1, Yld n2) -> Yield (min n1 n2) next
417+ (Yld n1, Yld n2) -> Partial (min n1 n2) next
418 (Err err, _) -> Error err
418 (Err err, _) -> Error err
419 (_, Err err) -> Error err
419 (_, Err err) -> Error err
420− _ -> Skip 0 next
420+ _ -> Continue 0 next
422 step _ _ = undefined
422 step _ _ = undefined
@@ -460,15 +460,15 @@ longest (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
460 useStream buf inp1 inp2 stp st y = do
460 useStream buf inp1 inp2 stp st y = do
461 (buf1, r, inp11, inp21) <- consume buf inp1 inp2 stp st y
461 (buf1, r, inp11, inp21) <- consume buf inp1 inp2 stp st y
462 case r of
462 case r of
463− Yield 0 s ->
463+ Partial 0 s ->
464 let state = ([], StepState s, inp11, inp21)
464 let state = ([], StepState s, inp11, inp21)
465 in return (state, Yld 0)
465 in return (state, Yld 0)
466− Yield n _ -> return (undefined, Yld n) -- Not implemented
466+ Partial n _ -> return (undefined, Yld n) -- Not implemented
467− Stop n b ->
467+ Done n b ->
468 let state = (Prelude.take n buf1, StepResult b, inp11, inp21)
468 let state = (Prelude.take n buf1, StepResult b, inp11, inp21)
469 in assert (n <= length buf1) (return (state, Stp n))
469 in assert (n <= length buf1) (return (state, Stp n))
470− -- Skip 0 s -> (buf1, Right s, inp11, inp21)
470+ -- Continue 0 s -> (buf1, Right s, inp11, inp21)
471− Skip n s ->
471+ Continue n s ->
472 let (src0, buf2) = splitAt n buf1
472 let (src0, buf2) = splitAt n buf1
473 src = Prelude.reverse src0
473 src = Prelude.reverse src0
474 state = (buf2, StepState s, src ++ inp11, inp21)
474 state = (buf2, StepState s, src ++ inp11, inp21)
@@ -482,16 +482,16 @@ longest (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
482 (r,stR) <- useStream bufR inpR1 inpR2 stepR sR x
482 (r,stR) <- useStream bufR inpR1 inpR2 stepR sR x
483 let next = TeePair l r
483 let next = TeePair l r
484 return $ case (stL,stR) of
484 return $ case (stL,stR) of
485− (Yld n1, Yld n2) -> Yield (min n1 n2) next
485+ (Yld n1, Yld n2) -> Partial (min n1 n2) next
486− (Yld n1, Stp n2) -> Yield (min n1 n2) next
486+ (Yld n1, Stp n2) -> Partial (min n1 n2) next
487− (Stp n1, Yld n2) -> Yield (min n1 n2) next
487+ (Stp n1, Yld n2) -> Partial (min n1 n2) next
488 (Stp n1, Stp n2) ->
488 (Stp n1, Stp n2) ->
489 let (_, StepResult rL, _, _) = l
489 let (_, StepResult rL, _, _) = l
490 (_, StepResult rR, _, _) = r
490 (_, StepResult rR, _, _) = r
491− in Stop (max n1 n2) (if n1 >= n2 then rL else rR)
491+ in Done (max n1 n2) (if n1 >= n2 then rL else rR)
492 (Err err, _) -> Error err
492 (Err err, _) -> Error err
493 (_, Err err) -> Error err
493 (_, Err err) -> Error err
494− _ -> Skip 0 next
494+ _ -> Continue 0 next
496 -- XXX the parser that finishes last may not be the longest because it may
496 -- XXX the parser that finishes last may not be the longest because it may
497 -- return a lot of unused input which makes it shorter. Our current
497 -- return a lot of unused input which makes it shorter. Our current
@@ -506,11 +506,11 @@ longest (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
506 (l,stL) <- useStream bufL inpL1 inpL2 stepL sL x
506 (l,stL) <- useStream bufL inpL1 inpL2 stepL sL x
507 let next = TeePair l r
507 let next = TeePair l r
508 return $ case stL of
508 return $ case stL of
509− Yld n -> Yield n next
509+ Yld n -> Partial n next
511 let (_, StepResult rL, _, _) = l
511 let (_, StepResult rL, _, _) = l
512− in Stop n rL
512+ in Done n rL
513− Skp -> Skip 0 next
513+ Skp -> Continue 0 next
514 Err err -> Error err
514 Err err -> Error err
516 step (TeePair l@(_, StepResult _, _, _)
516 step (TeePair l@(_, StepResult _, _, _)
@@ -518,11 +518,11 @@ longest (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
518 (r, stR) <- useStream bufR inpR1 inpR2 stepR sR x
518 (r, stR) <- useStream bufR inpR1 inpR2 stepR sR x
519 let next = TeePair l r
519 let next = TeePair l r
520 return $ case stR of
520 return $ case stR of
521− Yld n -> Yield n next
521+ Yld n -> Partial n next
523 let (_, StepResult rR, _, _) = r
523 let (_, StepResult rR, _, _) = r
524− in Stop n rR
524+ in Done n rR
525− Skp -> Skip 0 next
525+ Skp -> Continue 0 next
526 Err err -> Error err
526 Err err -> Error err
528 step _ _ = undefined
528 step _ _ = undefined