@@ -161,20 +161,13 @@ import Streamly.Internal.Data.Strict (Tuple3'(..))
161161--
162162{-# ANN type Step Fuse #-}
163163data Step s b =
164− Yield Int s
165− -- ^ Trim the backtracking buffer keeping only most recent @n@ items.
166− -- @Yield n state@ indicates that the parser has yielded a new result
167− -- which is a point of no return. The result can be extracted using
168− -- @extract@. The driver drops the buffer except @n@ most recent
169− -- elements. The rule is that if a parser has yielded at least once it
170− -- cannot return a failure result.
171−
172− | YieldB Int s
164+ Yield Int s
173165 -- ^ Go back by @n@ items in the input buffer and drop the rest.
174− -- @YieldB n state@ indicates that the parser has yielded a new result
166+ -- @Yield n state@ indicates that the parser has yielded a new result
175167 -- which is a point of no return. The result can be extracted using
176168 -- @extract@. The driver moves back the current position of the cursor by
177− -- @n@ elements and drops any buffer before that.
169+ -- @n@ elements and drops any buffer before that. The rule is that if a
170+ -- parser has yielded at least once it cannot return a failure result.
178171
179172 -- only rewind
180173 | Skip Int s
@@ -202,7 +195,6 @@ data Step s b =
202195instance Functor (Step s) where
203196 {-# INLINE fmap #-}
204197 fmap _ (Yield n s) = Yield n s
205− fmap _ (YieldB n s) = YieldB n s
206198 fmap _ (Skip n s) = Skip n s
207199 fmap f (Stop n b) = Stop n (f b)
208200 fmap _ (Error err) = Error err
@@ -303,8 +295,7 @@ splitWith func (Parser stepL initialL extractL)
303295 -- e.g. in ((,) <$> p1 <*> p2) <|> p3, if p2 fails we have to
304296 -- backtrack and start running p3. So we need to keep the input
305297 -- buffered until we know that the applicative cannot fail.
306− Yield _ s -> return $ Skip 0 (SeqParseL s)
307− YieldB n s -> return $ Skip n (SeqParseL s)
298+ Yield n s -> return $ Skip n (SeqParseL s)
308299 Skip n s -> return $ Skip n (SeqParseL s)
309300 Stop n b -> Skip n <$> (SeqParseR (func b) <$> initialR)
310301 Error err -> return $ Error err
@@ -313,7 +304,6 @@ splitWith func (Parser stepL initialL extractL)
313304 r <- stepR st a
314305 return $ case r of
315306 Yield n s -> Yield n (SeqParseR f s)
316− YieldB n s -> YieldB n (SeqParseR f s)
317307 Skip n s -> Skip n (SeqParseR f s)
318308 Stop n b -> Stop n (f b)
319309 Error err -> Error err
@@ -348,8 +338,7 @@ split_ (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
348338 (\r i -> case r of
349339 -- Note: this leads to buffering even if we are not in an
350340 -- Alternative composition.
351− Yield _ s -> Skip 0 (SeqAL s)
352− YieldB n s -> Skip n (SeqAL s)
341+ Yield n s -> Skip n (SeqAL s)
353342 Skip n s -> Skip n (SeqAL s)
354343 Stop n _ -> Skip n (SeqAR i)
355344 -- XXX should we sequence initialR monadically?
@@ -358,7 +347,6 @@ split_ (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
358347 step (SeqAR st) a = do
359348 (\r -> case r of
360349 Yield n s -> Yield n (SeqAR s)
361− YieldB n s -> YieldB n (SeqAR s)
362350 Skip n s -> Skip n (SeqAR s)
363351 Stop n b -> Stop n b
364352 Error err -> Error err) <$> stepR st a
@@ -413,7 +401,6 @@ alt (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
413401 r <- stepL st a
414402 case r of
415403 Yield n s -> return $ Yield n (AltParseL 0 s)
416− YieldB n s -> return $ YieldB n (AltParseL 0 s)
417404 Skip n s -> do
418405 assert (cnt + 1 - n >= 0) (return ())
419406 return $ Skip n (AltParseL (cnt + 1 - n) s)
@@ -426,7 +413,6 @@ alt (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
426413 r <- stepR st a
427414 return $ case r of
428415 Yield n s -> Yield n (AltParseR s)
429− YieldB n s -> YieldB n (AltParseR s)
430416 Skip n s -> Skip n (AltParseR s)
431417 Stop n b -> Stop n b
432418 Error err -> Error err
@@ -455,8 +441,7 @@ splitMany (Fold fstep finitial fextract) (Parser step1 initial1 extract1) =
455441 r <- step1 st a
456442 let cnt1 = cnt + 1
457443 case r of
458− Yield _ s -> return $ Skip 0 (Tuple3' s cnt1 fs)
459− YieldB n s -> do
444+ Yield n s -> do
460445 assert (cnt1 - n >= 0) (return ())
461446 return $ Skip n (Tuple3' s (cnt1 - n) fs)
462447 Skip n s -> do
@@ -465,7 +450,7 @@ splitMany (Fold fstep finitial fextract) (Parser step1 initial1 extract1) =
465450 Stop n b -> do
466451 s <- initial1
467452 fs1 <- fstep fs b
468− return $ YieldB n (Tuple3' s 0 fs1)
453+ return $ Yield n (Tuple3' s 0 fs1)
469454 Error _ -> do
470455 xs <- fextract fs
471456 return $ Stop cnt1 xs
@@ -497,29 +482,27 @@ splitSome (Fold fstep finitial fextract) (Parser step1 initial1 extract1) =
497482 step (Tuple3' st _ (Left fs)) a = do
498483 r <- step1 st a
499484 case r of
500− Yield _ s -> return $ Skip 0 (Tuple3' s undefined (Left fs))
501− YieldB n s -> return $ Skip n (Tuple3' s undefined (Left fs))
485+ Yield n s -> return $ Skip n (Tuple3' s undefined (Left fs))
502486 Skip n s -> return $ Skip n (Tuple3' s undefined (Left fs))
503487 Stop n b -> do
504488 s <- initial1
505489 fs1 <- fstep fs b
506− return $ YieldB n (Tuple3' s 0 (Right fs1))
490+ return $ Yield n (Tuple3' s 0 (Right fs1))
507491 Error err -> return $ Error err
508492 step (Tuple3' st cnt (Right fs)) a = do
509493 r <- step1 st a
510494 let cnt1 = cnt + 1
511495 case r of
512− Yield _ s -> return $ Yield 0 (Tuple3' s cnt1 (Right fs))
513− YieldB n s -> do
496+ Yield n s -> do
514497 assert (cnt1 - n >= 0) (return ())
515− return $ YieldB n (Tuple3' s (cnt1 - n) (Right fs))
498+ return $ Yield n (Tuple3' s (cnt1 - n) (Right fs))
516499 Skip n s -> do
517500 assert (cnt1 - n >= 0) (return ())
518501 return $ Skip n (Tuple3' s (cnt1 - n) (Right fs))
519502 Stop n b -> do
520503 s <- initial1
521504 fs1 <- fstep fs b
522− return $ YieldB n (Tuple3' s 0 (Right fs1))
505+ return $ Yield n (Tuple3' s 0 (Right fs1))
523506 Error _ -> Stop cnt1 <$> fextract fs
524507
525508 -- XXX The "try" may impact performance if this parser is used as a scan
@@ -598,8 +581,7 @@ concatMap func (Parser stepL initialL extractL) = Parser step initial extract
598581 step (ConcatParseL st) a = do
599582 r <- stepL st a
600583 return $ case r of
601− Yield _ s -> Skip 0 (ConcatParseL s)
602− YieldB n s -> Skip n (ConcatParseL s)
584+ Yield n s -> Skip n (ConcatParseL s)
603585 Skip n s -> Skip n (ConcatParseL s)
604586 Stop n b -> Skip n (ConcatParseR (func b))
605587 Error err -> Error err
@@ -610,8 +592,6 @@ concatMap func (Parser stepL initialL extractL) = Parser step initial extract
610592 return $ case r of
611593 Yield n s ->
612594 Yield n (ConcatParseR (Parser stepR (return s) extractR))
613− YieldB n s ->
614− YieldB n (ConcatParseR (Parser stepR (return s) extractR))
615595 Skip n s ->
616596 Skip n (ConcatParseR (Parser stepR (return s) extractR))
617597 Stop n b -> Stop n b