on master help sign in
Rename the parser Step constructors
6bf8b4aHarendra Kumar
src/Streamly/Internal/Data/Parser/ParserD.hs+40−40
@@ -190,7 +190,7 @@ fromFold (Fold fstep finitial fextract) = Parser step finitial fextract
190
190
191 where
191 where
192
192
193− step s a = Yield 0 <$> fstep s a
193+ step s a = Partial 0 <$> fstep s a
194
194
195-------------------------------------------------------------------------------
195-------------------------------------------------------------------------------
196-- Convert to and from CPS style parser representation
196-- Convert to and from CPS style parser representation
@@ -241,11 +241,11 @@ any predicate = Parser step initial return
241
241
242 step s a = return $
242 step s a = return $
243 if s
243 if s
244− then Stop 0 True
244+ then Done 0 True
245 else
245 else
246 if predicate a
246 if predicate a
247− then Stop 0 True
247+ then Done 0 True
248− else Yield 0 False
248+ else Partial 0 False
249
249
250{-# INLINABLE all #-}
250{-# INLINABLE all #-}
251all :: Monad m => (a -> Bool) -> Parser m a Bool
251all :: Monad m => (a -> Bool) -> Parser m a Bool
@@ -259,9 +259,9 @@ all predicate = Parser step initial return
259 if s
259 if s
260 then
260 then
261 if predicate a
261 if predicate a
262− then Yield 0 True
262+ then Partial 0 True
263− else Stop 0 False
263+ else Done 0 False
264− else Stop 0 False
264+ else Done 0 False
265
265
266-------------------------------------------------------------------------------
266-------------------------------------------------------------------------------
267-- Failing Parsers
267-- Failing Parsers
@@ -279,7 +279,7 @@ peek = Parser step initial extract
279
279
280 initial = return ()
280 initial = return ()
281
281
282− step () a = return $ Stop 1 a
282+ step () a = return $ Done 1 a
283
283
284 extract () = throwM $ ParseError "peek: end of input"
284 extract () = throwM $ ParseError "peek: end of input"
285
285
@@ -311,7 +311,7 @@ satisfy predicate = Parser step initial extract
311
311
312 step () a = return $
312 step () a = return $
313 if predicate a
313 if predicate a
314− then Stop 0 a
314+ then Done 0 a
315 else Error "satisfy: predicate failed"
315 else Error "satisfy: predicate failed"
316
316
317 extract _ = throwM $ ParseError "satisfy: end of input"
317 extract _ = throwM $ ParseError "satisfy: end of input"
@@ -337,8 +337,8 @@ take n (Fold fstep finitial fextract) = Parser step initial extract
337 let i1 = i + 1
337 let i1 = i + 1
338 s1 = Tuple' i1 res
338 s1 = Tuple' i1 res
339 if i1 < n
339 if i1 < n
340− then return $ Yield 0 s1
340+ then return $ Partial 0 s1
341− else Stop 0 <$> fextract res
341+ else Done 0 <$> fextract res
342
342
343 extract (Tuple' _ r) = fextract r
343 extract (Tuple' _ r) = fextract r
344
344
@@ -358,7 +358,7 @@ takeEQ n (Fold fstep finitial fextract) = Parser step initial extract
358 res <- fstep r a
358 res <- fstep r a
359 let i1 = i + 1
359 let i1 = i + 1
360 s1 = Tuple' i1 res
360 s1 = Tuple' i1 res
361− if i1 < n then return (Skip 0 s1) else Stop 0 <$> fextract res
361+ if i1 < n then return (Continue 0 s1) else Done 0 <$> fextract res
362
362
363 extract (Tuple' i r) =
363 extract (Tuple' i r) =
364 if n == i
364 if n == i
@@ -389,8 +389,8 @@ takeGE n (Fold fstep finitial fextract) = Parser step initial extract
389 s1 = Tuple' i1 res
389 s1 = Tuple' i1 res
390 return $
390 return $
391 if i1 < n
391 if i1 < n
392− then Skip 0 s1
392+ then Continue 0 s1
393− else Yield 0 s1
393+ else Partial 0 s1
394
394
395 extract (Tuple' i r) = fextract r >>= f
395 extract (Tuple' i r) = fextract r >>= f
396
396
@@ -420,8 +420,8 @@ takeWhile predicate (Fold fstep finitial fextract) =
420
420
421 step s a =
421 step s a =
422 if predicate a
422 if predicate a
423− then Yield 0 <$> fstep s a
423+ then Partial 0 <$> fstep s a
424− else Stop 1 <$> fextract s
424+ else Done 1 <$> fextract s
425
425
426-- | See 'Streamly.Internal.Data.Parser.takeWhile1'.
426-- | See 'Streamly.Internal.Data.Parser.takeWhile1'.
427--
427--
@@ -441,16 +441,16 @@ takeWhile1 predicate (Fold fstep finitial fextract) =
441 then do
441 then do
442 s <- finitial
442 s <- finitial
443 r <- fstep s a
443 r <- fstep s a
444− return $ Yield 0 (Just r)
444+ return $ Partial 0 (Just r)
445 else return $ Error "takeWhile1: empty"
445 else return $ Error "takeWhile1: empty"
446 step (Just s) a =
446 step (Just s) a =
447 if predicate a
447 if predicate a
448 then do
448 then do
449 r <- fstep s a
449 r <- fstep s a
450− return $ Yield 0 (Just r)
450+ return $ Partial 0 (Just r)
451 else do
451 else do
452 b <- fextract s
452 b <- fextract s
453− return $ Stop 1 b
453+ return $ Done 1 b
454
454
455 extract Nothing = throwM $ ParseError "takeWhile1: end of input"
455 extract Nothing = throwM $ ParseError "takeWhile1: end of input"
456 extract (Just s) = fextract s
456 extract (Just s) = fextract s
@@ -469,8 +469,8 @@ sliceSepBy predicate (Fold fstep finitial fextract) =
469 initial = finitial
469 initial = finitial
470 step s a =
470 step s a =
471 if not (predicate a)
471 if not (predicate a)
472− then Yield 0 <$> fstep s a
472+ then Partial 0 <$> fstep s a
473− else Stop 0 <$> fextract s
473+ else Done 0 <$> fextract s
474
474
475-- | See 'Streamly.Internal.Data.Parser.sliceEndWith'.
475-- | See 'Streamly.Internal.Data.Parser.sliceEndWith'.
476--
476--
@@ -511,11 +511,11 @@ sliceSepByMax predicate cnt (Fold fstep finitial fextract) =
511 let i1 = i + 1
511 let i1 = i + 1
512 s1 = Tuple' i1 res
512 s1 = Tuple' i1 res
513 if i1 < cnt
513 if i1 < cnt
514− then return $ Yield 0 s1
514+ then return $ Partial 0 s1
515 else do
515 else do
516 b <- fextract res
516 b <- fextract res
517− return $ Stop 0 b
517+ return $ Done 0 b
518− | otherwise = Stop 0 <$> fextract r
518+ | otherwise = Done 0 <$> fextract r
519 extract (Tuple' _ r) = fextract r
519 extract (Tuple' _ r) = fextract r
520
520
521-- | See 'Streamly.Internal.Data.Parser.wordBy'.
521-- | See 'Streamly.Internal.Data.Parser.wordBy'.
@@ -553,14 +553,14 @@ eqBy cmp str = Parser step initial extract
553
553
554 initial = return str
554 initial = return str
555
555
556− step [] _ = return $ Stop 0 ()
556+ step [] _ = return $ Done 0 ()
557 step [x] a = return $
557 step [x] a = return $
558 if x `cmp` a
558 if x `cmp` a
559− then Stop 0 ()
559+ then Done 0 ()
560 else Error "eqBy: failed, yet to match the last element"
560 else Error "eqBy: failed, yet to match the last element"
561 step (x:xs) a = return $
561 step (x:xs) a = return $
562 if x `cmp` a
562 if x `cmp` a
563− then Skip 0 xs
563+ then Continue 0 xs
564 else Error $
564 else Error $
565 "eqBy: failed, yet to match " ++ show (length xs + 1) ++ " elements"
565 "eqBy: failed, yet to match " ++ show (length xs + 1) ++ " elements"
566
566
@@ -588,9 +588,9 @@ lookAhead (Parser step1 initial1 _) =
588 r <- step1 st a
588 r <- step1 st a
589 let cnt1 = cnt + 1
589 let cnt1 = cnt + 1
590 return $ case r of
590 return $ case r of
591− Yield n s -> Skip n (Tuple' (cnt1 - n) s)
591+ Partial n s -> Continue n (Tuple' (cnt1 - n) s)
592− Skip n s -> Skip n (Tuple' (cnt1 - n) s)
592+ Continue n s -> Continue n (Tuple' (cnt1 - n) s)
593− Stop _ b -> Stop cnt1 b
593+ Done _ b -> Done cnt1 b
594 Error err -> Error err
594 Error err -> Error err
595
595
596 -- XXX returning an error let's us backtrack. To implement it in a way so
596 -- XXX returning an error let's us backtrack. To implement it in a way so
@@ -711,26 +711,26 @@ manyTill (Fold fstep finitial fextract)
711 step (ManyTillR cnt fs st) a = do
711 step (ManyTillR cnt fs st) a = do
712 r <- stepR st a
712 r <- stepR st a
713 case r of
713 case r of
714− Yield n s -> return $ Yield n (ManyTillR 0 fs s)
714+ Partial n s -> return $ Partial n (ManyTillR 0 fs s)
715− Skip n s -> do
715+ Continue n s -> do
716 assert (cnt + 1 - n >= 0) (return ())
716 assert (cnt + 1 - n >= 0) (return ())
717− return $ Skip n (ManyTillR (cnt + 1 - n) fs s)
717+ return $ Continue n (ManyTillR (cnt + 1 - n) fs s)
718− Stop n _ -> do
718+ Done n _ -> do
719 b <- fextract fs
719 b <- fextract fs
720− return $ Stop n b
720+ return $ Done n b
721 Error _ -> do
721 Error _ -> do
722 rR <- initialL
722 rR <- initialL
723− return $ Skip (cnt + 1) (ManyTillL fs rR)
723+ return $ Continue (cnt + 1) (ManyTillL fs rR)
724
724
725 step (ManyTillL fs st) a = do
725 step (ManyTillL fs st) a = do
726 r <- stepL st a
726 r <- stepL st a
727 case r of
727 case r of
728− Yield n s -> return $ Yield n (ManyTillL fs s)
728+ Partial n s -> return $ Partial n (ManyTillL fs s)
729− Skip n s -> return $ Skip n (ManyTillL fs s)
729+ Continue n s -> return $ Continue n (ManyTillL fs s)
730− Stop n b -> do
730+ Done n b -> do
731 fs1 <- fstep fs b
731 fs1 <- fstep fs b
732 l <- initialR
732 l <- initialR
733− return $ Yield n (ManyTillR 0 fs1 l)
733+ return $ Partial n (ManyTillR 0 fs1 l)
734 Error err -> return $ Error err
734 Error err -> return $ Error err
735
735
736 extract (ManyTillL fs sR) = extractL sR >>= fstep fs >>= fextract
736 extract (ManyTillL fs sR) = extractL sR >>= fstep fs >>= fextract
src/Streamly/Internal/Data/Parser/ParserD/Tee.hs+55−55
@@ -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.
79--
79--
@@ -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
178
178
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
189 Stp n ->
189 Stp n ->
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
194
194
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
205 Stp n ->
205 Stp n ->
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
210
210
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
300 in do
300 in do
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
308
308
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
319 Stp n ->
319 Stp n ->
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
324
324
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
421
421
422 step _ _ = undefined
422 step _ _ = undefined
423
423
@@ -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
495
495
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
510 Stp n ->
510 Stp n ->
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
515
515
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
522 Stp n ->
522 Stp n ->
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
527
527
528 step _ _ = undefined
528 step _ _ = undefined
src/Streamly/Internal/Data/Parser/ParserD/Types.hs+112−100
@@ -40,11 +40,11 @@
40-- 'Step' functor provides the following commands to the fold driver
40-- 'Step' functor provides the following commands to the fold driver
41-- corresponding to the use cases outlined in the previous para:
41-- corresponding to the use cases outlined in the previous para:
42--
42--
43−-- 1. 'Skip': buffer the current input and go back to a previous
43+-- 1. 'Continue': buffer the current input and go back to a previous
44-- position in the stream
44-- position in the stream
45−-- 2. 'Yield': buffer the current input and go back to a previous
45+-- 2. 'Partial': buffer the current input and go back to a previous
46-- position in the stream, drop the buffer before that position.
46-- position in the stream, drop the buffer before that position.
47−-- 3. 'Stop': parser succeeded, returns how much input was leftover
47+-- 3. 'Done': parser succeeded, returns how much input was leftover
48-- 4. 'Error': indicates that the parser has failed without a result
48-- 4. 'Error': indicates that the parser has failed without a result
49--
49--
50-- = How a Parser Works?
50-- = How a Parser Works?
@@ -55,19 +55,19 @@
55--
55--
56-- The parser may build a new output value from multiple input items. When it
56-- The parser may build a new output value from multiple input items. When it
57-- consumes an input item but needs more input to build a complete output item
57-- consumes an input item but needs more input to build a complete output item
58−-- it uses @Skip 0 s@, yielding the intermediate state @s@ and asking the
58+-- it uses @Continue 0 s@, yielding the intermediate state @s@ and asking the
59-- driver to provide more input. When the parser determines that a new output
59-- driver to provide more input. When the parser determines that a new output
60−-- value is complete it can use a @Stop n b@ to terminate the parser with @n@
60+-- value is complete it can use a @Done n b@ to terminate the parser with @n@
61-- items of input unused and the final value of the accumulator returned as
61-- items of input unused and the final value of the accumulator returned as
62-- @b@. If at any time the parser determines that the parse has failed it can
62-- @b@. If at any time the parser determines that the parse has failed it can
63-- return @Error err@.
63-- return @Error err@.
64--
64--
65−-- A parser building a collection of values (e.g. a list) can use the @Yield@
65+-- A parser building a collection of values (e.g. a list) can use the @Partial@
66-- constructor whenever a new item in the output collection is generated. If a
66-- constructor whenever a new item in the output collection is generated. If a
67-- parser building a collection of values has yielded at least one value then
67-- parser building a collection of values has yielded at least one value then
68-- it considered successful and cannot fail after that. In the current
68-- it considered successful and cannot fail after that. In the current
69-- implementation, this is not automatically enforced, there is a rule that the
69-- implementation, this is not automatically enforced, there is a rule that the
70−-- parser MUST use only @Stop@ for termination after the first @Yield@, it
70+-- parser MUST use only @Done@ for termination after the first @Partial@, it
71-- cannot use @Error@. It may be possible to change the implementation so that
71-- cannot use @Error@. It may be possible to change the implementation so that
72-- this rule is not required, but there may be some performance cost to it.
72-- this rule is not required, but there may be some performance cost to it.
73--
73--
@@ -82,7 +82,7 @@
82-- = Error Handling
82-- = Error Handling
83--
83--
84-- When a parser's @step@ function is invoked it may terminate by either a
84-- When a parser's @step@ function is invoked it may terminate by either a
85−-- 'Stop' or an 'Error' return value. In an 'Alternative' composition an error
85+-- 'Done' or an 'Error' return value. In an 'Alternative' composition an error
86-- return can make the composed parser backtrack and try another parser.
86-- return can make the composed parser backtrack and try another parser.
87--
87--
88-- If the stream stops before a parser could terminate then we use the
88-- If the stream stops before a parser could terminate then we use the
@@ -145,58 +145,70 @@ import Streamly.Internal.Data.Strict (Tuple3'(..))
145
145
146-- | The return type of a 'Parser' step.
146-- | The return type of a 'Parser' step.
147--
147--
148−-- A parser is driven by a parse driver one step at a time, at any time the
148+-- The parse operation feeds the input stream to the parser one element at a
149−-- driver may @extract@ the result of the parser. The parser may ask the driver
149+-- time, representing a parse 'Step'. The parser may or may not consume the
150−-- to backtrack at any point, therefore, the driver holds the input up to a
150+-- item and returns a result. If the result is 'Partial' we can either extract
151−-- point of no return in a backtracking buffer. The buffer grows or shrinks
151+-- the result or feed more input to the parser. If the result is 'Continue', we
152−-- based on the return values of the parser step execution.
152+-- must feed more input in order to get a result. If the parser returns 'Done'
153+-- then the parser can no longer take any more input.
154+--
155+-- If the result is 'Continue', the parse operation retains the input in a
156+-- backtracking buffer, in case the parser may ask to backtrack in future.
157+-- Whenever a 'Partial n' result is returned we first backtrack by @n@ elements
158+-- in the input and then release any remaining backtracking buffer. Similarly,
159+-- 'Continue n' backtracks to @n@ elements before the current position and
160+-- starts feeding the input from that point for future invocations of the
161+-- parser.
153−--
162+--
154−-- When a parser step is executed it generates a new intermediate state of the
163+-- If parser is not yet done, we can use the @extract@ operation on the @state@
155−-- parse result along with a command to the driver. The command tells the
164+-- of the parser to extract a result. If the parser has not yet yielded a
156−-- driver whether to keep the input stream for a potential backtracking later
165+-- result, the operation fails with a 'ParseError' exception. If the parser
157−-- on or drop it, and how much to keep. The constructors of 'Step' represent
166+-- yielded a 'Partial' result in the past the last partial result is returned.
158−-- the commands to the driver.
167+-- Therefore, if a parser yields a partial result once it cannot fail later on.
168+--
169+-- The parser can never backtrack beyond the position where the last partial
170+-- result left it at. The parser must ensure that the backtrack position is
171+-- always after that.
159--
172--
160-- /Internal/
173-- /Internal/
161--
174--
162{-# ANN type Step Fuse #-}
175{-# ANN type Step Fuse #-}
163data Step s b =
176data Step s b =
164− Yield Int s
177+ Partial Int s
165− -- ^ Go back by @n@ items in the input buffer and drop the rest.
178+ -- ^ Partial result with an optional backtrack.
166− -- @Yield n state@ indicates that the parser has yielded a new result
179+ --
167− -- which is a point of no return. The result can be extracted using
180+ -- @Partial count state@ means a partial result is available which
168− -- @extract@. The driver moves back the current position of the cursor by
181+ -- can be extracted successfully, @state@ is the opaque state of the
169− -- @n@ elements and drops any buffer before that. The rule is that if a
182+ -- parser to be supplied to the next invocation of the step operation.
170− -- parser has yielded at least once it cannot return a failure result.
183+ -- The current input position is reset to @count@ elements back and any
171−
184+ -- input before that is dropped from the backtrack buffer.
172− -- only rewind
185+
173− | Skip Int s
186+ | Continue Int s
174− -- ^ Go back by @n@ items in the input buffer.
187+ -- ^ Need more input with an optional backtrack.
188+ --
175− -- @Skip n state@ indicates that the parser has consumed the current input
189+ -- @Continue count state@ means the parser has consumed the current input
176− -- but no new result has been generated. A new @state@ is generated.
190+ -- but no new result is generated, @state@ is the next state of the parser.
177− -- However, if we use @extract@ on @state@ it will generate a result from
191+ -- The current input is retained in the backtrack buffer and the input
178− -- the previous @Yield@. When @n@ is non-zero it is a backward offset from
192+ -- position is reset to @count@ elements back.
179− -- the current position in the stream from which the driver will replay the
193+
180− -- input to the parser. The offset cannot be beyond the latest point of no
181− -- return created by @Yield@.
182−
183− | Stop Int b
194+ | Done Int b
184− -- ^ Trim the backtracking buffer keeping only most recent @n@ items.
195+ -- ^ Done with leftover input count and result.
185− -- @Stop n result@ asks the driver to stop driving the parser because it
196+ --
186− -- has reached a fixed point and further input will not change the result.
197+ -- @Done count result@ means the parser has finished, it will accept no
187− -- @n@ is the count of unused input elements which includes the element on
198+ -- more input, last @count@ elements from the input are unused and the
188− -- which 'Stop' occurred.
199+ -- result of the parser is in @result@.
189
200
190 | Error String
201 | Error String
191− -- ^ Go back to the start of the backtracking buffer.
202+ -- ^ Parser failed without generating any output.
192− -- An error makes the parser backtrack to the last checkpoint and try
203+ --
204+ -- The parsing operation may backtrack to the beginning and try another
193− -- another alternative.
205+ -- alternative.
194
206
195instance Functor (Step s) where
207instance Functor (Step s) where
196 {-# INLINE fmap #-}
208 {-# INLINE fmap #-}
197− fmap _ (Yield n s) = Yield n s
209+ fmap _ (Partial n s) = Partial n s
198− fmap _ (Skip n s) = Skip n s
210+ fmap _ (Continue n s) = Continue n s
199− fmap f (Stop n b) = Stop n (f b)
211+ fmap f (Done n b) = Done n (f b)
200 fmap _ (Error err) = Error err
212 fmap _ (Error err) = Error err
201
213
202-- | A parser is a fold that can fail and is represented as @Parser step
214-- | A parser is a fold that can fail and is represented as @Parser step
@@ -243,7 +255,7 @@ instance Functor m => Functor (Parser m a) where
243--
255--
244{-# INLINE_NORMAL yield #-}
256{-# INLINE_NORMAL yield #-}
245yield :: Monad m => b -> Parser m a b
257yield :: Monad m => b -> Parser m a b
246−yield b = Parser (\_ _ -> pure $ Stop 1 b) -- step
258+yield b = Parser (\_ _ -> pure $ Done 1 b) -- step
247 (pure ()) -- initial
259 (pure ()) -- initial
248 (\_ -> pure b) -- extract
260 (\_ -> pure b) -- extract
249
261
@@ -253,7 +265,7 @@ yield b = Parser (\_ _ -> pure $ Stop 1 b) -- step
253--
265--
254{-# INLINE yieldM #-}
266{-# INLINE yieldM #-}
255yieldM :: Monad m => m b -> Parser m a b
267yieldM :: Monad m => m b -> Parser m a b
256−yieldM b = Parser (\_ _ -> Stop 1 <$> b) -- step
268+yieldM b = Parser (\_ _ -> Done 1 <$> b) -- step
257 (pure ()) -- initial
269 (pure ()) -- initial
258 (\_ -> b) -- extract
270 (\_ -> b) -- extract
259
271
@@ -287,7 +299,7 @@ splitWith func (Parser stepL initialL extractL)
287 initial = SeqParseL <$> initialL
299 initial = SeqParseL <$> initialL
288
300
289 -- Note: For the composed parse to terminate, the left parser has to be
301 -- Note: For the composed parse to terminate, the left parser has to be
290− -- a terminating parser returning a Stop at some point.
302+ -- a terminating parser returning a Done at some point.
291 step (SeqParseL st) a = do
303 step (SeqParseL st) a = do
292 r <- stepL st a
304 r <- stepL st a
293 case r of
305 case r of
@@ -295,17 +307,17 @@ splitWith func (Parser stepL initialL extractL)
295 -- e.g. in ((,) <$> p1 <*> p2) <|> p3, if p2 fails we have to
307 -- e.g. in ((,) <$> p1 <*> p2) <|> p3, if p2 fails we have to
296 -- backtrack and start running p3. So we need to keep the input
308 -- backtrack and start running p3. So we need to keep the input
297 -- buffered until we know that the applicative cannot fail.
309 -- buffered until we know that the applicative cannot fail.
298− Yield n s -> return $ Skip n (SeqParseL s)
310+ Partial n s -> return $ Continue n (SeqParseL s)
299− Skip n s -> return $ Skip n (SeqParseL s)
311+ Continue n s -> return $ Continue n (SeqParseL s)
300− Stop n b -> Skip n <$> (SeqParseR (func b) <$> initialR)
312+ Done n b -> Continue n <$> (SeqParseR (func b) <$> initialR)
301 Error err -> return $ Error err
313 Error err -> return $ Error err
302
314
303 step (SeqParseR f st) a = do
315 step (SeqParseR f st) a = do
304 r <- stepR st a
316 r <- stepR st a
305 return $ case r of
317 return $ case r of
306− Yield n s -> Yield n (SeqParseR f s)
318+ Partial n s -> Partial n (SeqParseR f s)
307− Skip n s -> Skip n (SeqParseR f s)
319+ Continue n s -> Continue n (SeqParseR f s)
308− Stop n b -> Stop n (f b)
320+ Done n b -> Done n (f b)
309 Error err -> Error err
321 Error err -> Error err
310
322
311 extract (SeqParseR f sR) = fmap f (extractR sR)
323 extract (SeqParseR f sR) = fmap f (extractR sR)
@@ -333,22 +345,22 @@ split_ (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
333 initial = SeqAL <$> initialL
345 initial = SeqAL <$> initialL
334
346
335 -- Note: For the composed parse to terminate, the left parser has to be
347 -- Note: For the composed parse to terminate, the left parser has to be
336− -- a terminating parser returning a Stop at some point.
348+ -- a terminating parser returning a Done at some point.
337 step (SeqAL st) a = do
349 step (SeqAL st) a = do
338 (\r i -> case r of
350 (\r i -> case r of
339 -- Note: this leads to buffering even if we are not in an
351 -- Note: this leads to buffering even if we are not in an
340 -- Alternative composition.
352 -- Alternative composition.
341− Yield n s -> Skip n (SeqAL s)
353+ Partial n s -> Continue n (SeqAL s)
342− Skip n s -> Skip n (SeqAL s)
354+ Continue n s -> Continue n (SeqAL s)
343− Stop n _ -> Skip n (SeqAR i)
355+ Done n _ -> Continue n (SeqAR i)
344 -- XXX should we sequence initialR monadically?
356 -- XXX should we sequence initialR monadically?
345 Error err -> Error err) <$> stepL st a <*> initialR
357 Error err -> Error err) <$> stepL st a <*> initialR
346
358
347 step (SeqAR st) a = do
359 step (SeqAR st) a = do
348 (\r -> case r of
360 (\r -> case r of
349− Yield n s -> Yield n (SeqAR s)
361+ Partial n s -> Partial n (SeqAR s)
350− Skip n s -> Skip n (SeqAR s)
362+ Continue n s -> Continue n (SeqAR s)
351− Stop n b -> Stop n b
363+ Done n b -> Done n b
352 Error err -> Error err) <$> stepR st a
364 Error err -> Error err) <$> stepR st a
353
365
354 extract (SeqAR sR) = extractR sR
366 extract (SeqAR sR) = extractR sR
@@ -400,21 +412,21 @@ alt (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
400 step (AltParseL cnt st) a = do
412 step (AltParseL cnt st) a = do
401 r <- stepL st a
413 r <- stepL st a
402 case r of
414 case r of
403− Yield n s -> return $ Yield n (AltParseL 0 s)
415+ Partial n s -> return $ Partial n (AltParseL 0 s)
404− Skip n s -> do
416+ Continue n s -> do
405 assert (cnt + 1 - n >= 0) (return ())
417 assert (cnt + 1 - n >= 0) (return ())
406− return $ Skip n (AltParseL (cnt + 1 - n) s)
418+ return $ Continue n (AltParseL (cnt + 1 - n) s)
407− Stop n b -> return $ Stop n b
419+ Done n b -> return $ Done n b
408 Error _ -> do
420 Error _ -> do
409 rR <- initialR
421 rR <- initialR
410− return $ Skip (cnt + 1) (AltParseR rR)
422+ return $ Continue (cnt + 1) (AltParseR rR)
411
423
412 step (AltParseR st) a = do
424 step (AltParseR st) a = do
413 r <- stepR st a
425 r <- stepR st a
414 return $ case r of
426 return $ case r of
415− Yield n s -> Yield n (AltParseR s)
427+ Partial n s -> Partial n (AltParseR s)
416− Skip n s -> Skip n (AltParseR s)
428+ Continue n s -> Continue n (AltParseR s)
417− Stop n b -> Stop n b
429+ Done n b -> Done n b
418 Error err -> Error err
430 Error err -> Error err
419
431
420 extract (AltParseR sR) = extractR sR
432 extract (AltParseR sR) = extractR sR
@@ -441,19 +453,19 @@ splitMany (Fold fstep finitial fextract) (Parser step1 initial1 extract1) =
441 r <- step1 st a
453 r <- step1 st a
442 let cnt1 = cnt + 1
454 let cnt1 = cnt + 1
443 case r of
455 case r of
444− Yield n s -> do
456+ Partial n s -> do
445 assert (cnt1 - n >= 0) (return ())
457 assert (cnt1 - n >= 0) (return ())
446− return $ Skip n (Tuple3' s (cnt1 - n) fs)
458+ return $ Continue n (Tuple3' s (cnt1 - n) fs)
447− Skip n s -> do
459+ Continue n s -> do
448 assert (cnt1 - n >= 0) (return ())
460 assert (cnt1 - n >= 0) (return ())
449− return $ Skip n (Tuple3' s (cnt1 - n) fs)
461+ return $ Continue n (Tuple3' s (cnt1 - n) fs)
450− Stop n b -> do
462+ Done n b -> do
451 s <- initial1
463 s <- initial1
452 fs1 <- fstep fs b
464 fs1 <- fstep fs b
453− return $ Yield n (Tuple3' s 0 fs1)
465+ return $ Partial n (Tuple3' s 0 fs1)
454 Error _ -> do
466 Error _ -> do
455 xs <- fextract fs
467 xs <- fextract fs
456− return $ Stop cnt1 xs
468+ return $ Done cnt1 xs
457
469
458 -- XXX The "try" may impact performance if this parser is used as a scan
470 -- XXX The "try" may impact performance if this parser is used as a scan
459 extract (Tuple3' s _ fs) = do
471 extract (Tuple3' s _ fs) = do
@@ -482,28 +494,28 @@ splitSome (Fold fstep finitial fextract) (Parser step1 initial1 extract1) =
482 step (Tuple3' st _ (Left fs)) a = do
494 step (Tuple3' st _ (Left fs)) a = do
483 r <- step1 st a
495 r <- step1 st a
484 case r of
496 case r of
485− Yield n s -> return $ Skip n (Tuple3' s undefined (Left fs))
497+ Partial n s -> return $ Continue n (Tuple3' s undefined (Left fs))
486− Skip n s -> return $ Skip n (Tuple3' s undefined (Left fs))
498+ Continue n s -> return $ Continue n (Tuple3' s undefined (Left fs))
487− Stop n b -> do
499+ Done n b -> do
488 s <- initial1
500 s <- initial1
489 fs1 <- fstep fs b
501 fs1 <- fstep fs b
490− return $ Yield n (Tuple3' s 0 (Right fs1))
502+ return $ Partial n (Tuple3' s 0 (Right fs1))
491 Error err -> return $ Error err
503 Error err -> return $ Error err
492 step (Tuple3' st cnt (Right fs)) a = do
504 step (Tuple3' st cnt (Right fs)) a = do
493 r <- step1 st a
505 r <- step1 st a
494 let cnt1 = cnt + 1
506 let cnt1 = cnt + 1
495 case r of
507 case r of
496− Yield n s -> do
508+ Partial n s -> do
497 assert (cnt1 - n >= 0) (return ())
509 assert (cnt1 - n >= 0) (return ())
498− return $ Yield n (Tuple3' s (cnt1 - n) (Right fs))
510+ return $ Partial n (Tuple3' s (cnt1 - n) (Right fs))
499− Skip n s -> do
511+ Continue n s -> do
500 assert (cnt1 - n >= 0) (return ())
512 assert (cnt1 - n >= 0) (return ())
501− return $ Skip n (Tuple3' s (cnt1 - n) (Right fs))
513+ return $ Continue n (Tuple3' s (cnt1 - n) (Right fs))
502− Stop n b -> do
514+ Done n b -> do
503 s <- initial1
515 s <- initial1
504 fs1 <- fstep fs b
516 fs1 <- fstep fs b
505− return $ Yield n (Tuple3' s 0 (Right fs1))
517+ return $ Partial n (Tuple3' s 0 (Right fs1))
506− Error _ -> Stop cnt1 <$> fextract fs
518+ Error _ -> Done cnt1 <$> fextract fs
507
519
508 -- XXX The "try" may impact performance if this parser is used as a scan
520 -- XXX The "try" may impact performance if this parser is used as a scan
509 extract (Tuple3' s _ (Left fs)) = extract1 s >>= fstep fs >>= fextract
521 extract (Tuple3' s _ (Left fs)) = extract1 s >>= fstep fs >>= fextract
@@ -581,20 +593,20 @@ concatMap func (Parser stepL initialL extractL) = Parser step initial extract
581 step (ConcatParseL st) a = do
593 step (ConcatParseL st) a = do
582 r <- stepL st a
594 r <- stepL st a
583 return $ case r of
595 return $ case r of
584− Yield n s -> Skip n (ConcatParseL s)
596+ Partial n s -> Continue n (ConcatParseL s)
585− Skip n s -> Skip n (ConcatParseL s)
597+ Continue n s -> Continue n (ConcatParseL s)
586− Stop n b -> Skip n (ConcatParseR (func b))
598+ Done n b -> Continue n (ConcatParseR (func b))
587 Error err -> Error err
599 Error err -> Error err
588
600
589 step (ConcatParseR (Parser stepR initialR extractR)) a = do
601 step (ConcatParseR (Parser stepR initialR extractR)) a = do
590 st <- initialR
602 st <- initialR
591 r <- stepR st a
603 r <- stepR st a
592 return $ case r of
604 return $ case r of
593− Yield n s ->
605+ Partial n s ->
594− Yield n (ConcatParseR (Parser stepR (return s) extractR))
606+ Partial n (ConcatParseR (Parser stepR (return s) extractR))
595− Skip n s ->
607+ Continue n s ->
596− Skip n (ConcatParseR (Parser stepR (return s) extractR))
608+ Continue n (ConcatParseR (Parser stepR (return s) extractR))
597− Stop n b -> Stop n b
609+ Done n b -> Done n b
598 Error err -> Error err
610 Error err -> Error err
599
611
600 extract (ConcatParseR (Parser _ initialR extractR)) =
612 extract (ConcatParseR (Parser _ initialR extractR)) =
src/Streamly/Internal/Data/Stream/StreamD.hs+30−30
@@ -998,19 +998,19 @@ parselMx' pstep initial extract (Stream step state) = do
998 Yield x s -> do
998 Yield x s -> do
999 pRes <- pstep pst x
999 pRes <- pstep pst x
1000 case pRes of
1000 case pRes of
1001− PR.Yield 0 pst1 -> go SPEC s [] pst1
1001+ PR.Partial 0 pst1 -> go SPEC s [] pst1
1002− PR.Yield n pst1 -> do
1002+ PR.Partial n pst1 -> do
1003 assert (n <= length (x:buf)) (return ())
1003 assert (n <= length (x:buf)) (return ())
1004 let src0 = Prelude.take n (x:buf)
1004 let src0 = Prelude.take n (x:buf)
1005 src = Prelude.reverse src0
1005 src = Prelude.reverse src0
1006 gobuf SPEC s [] src pst1
1006 gobuf SPEC s [] src pst1
1007− PR.Skip 0 pst1 -> go SPEC s (x:buf) pst1
1007+ PR.Continue 0 pst1 -> go SPEC s (x:buf) pst1
1008− PR.Skip n pst1 -> do
1008+ PR.Continue n pst1 -> do
1009 assert (n <= length (x:buf)) (return ())
1009 assert (n <= length (x:buf)) (return ())
1010 let (src0, buf1) = splitAt n (x:buf)
1010 let (src0, buf1) = splitAt n (x:buf)
1011 src = Prelude.reverse src0
1011 src = Prelude.reverse src0
1012 gobuf SPEC s buf1 src pst1
1012 gobuf SPEC s buf1 src pst1
1013− PR.Stop _ b -> return b
1013+ PR.Done _ b -> return b
1014 PR.Error err -> throwM $ ParseError err
1014 PR.Error err -> throwM $ ParseError err
1015 Skip s -> go SPEC s buf pst
1015 Skip s -> go SPEC s buf pst
1016 Stop -> extract pst
1016 Stop -> extract pst
@@ -1019,20 +1019,20 @@ parselMx' pstep initial extract (Stream step state) = do
1019 gobuf !_ s buf (x:xs) !pst = do
1019 gobuf !_ s buf (x:xs) !pst = do
1020 pRes <- pstep pst x
1020 pRes <- pstep pst x
1021 case pRes of
1021 case pRes of
1022− PR.Yield 0 pst1 ->
1022+ PR.Partial 0 pst1 ->
1023 gobuf SPEC s [] xs pst1
1023 gobuf SPEC s [] xs pst1
1024− PR.Yield n pst1 -> do
1024+ PR.Partial n pst1 -> do
1025 assert (n <= length (x:buf)) (return ())
1025 assert (n <= length (x:buf)) (return ())
1026 let src0 = Prelude.take n (x:buf)
1026 let src0 = Prelude.take n (x:buf)
1027 src = Prelude.reverse src0 ++ xs
1027 src = Prelude.reverse src0 ++ xs
1028 gobuf SPEC s [] src pst1
1028 gobuf SPEC s [] src pst1
1029− PR.Skip 0 pst1 -> gobuf SPEC s (x:buf) xs pst1
1029+ PR.Continue 0 pst1 -> gobuf SPEC s (x:buf) xs pst1
1030− PR.Skip n pst1 -> do
1030+ PR.Continue n pst1 -> do
1031 assert (n <= length (x:buf)) (return ())
1031 assert (n <= length (x:buf)) (return ())
1032 let (src0, buf1) = splitAt n (x:buf)
1032 let (src0, buf1) = splitAt n (x:buf)
1033 src = Prelude.reverse src0 ++ xs
1033 src = Prelude.reverse src0 ++ xs
1034 gobuf SPEC s buf1 src pst1
1034 gobuf SPEC s buf1 src pst1
1035− PR.Stop _ b -> return b
1035+ PR.Done _ b -> return b
1036 PR.Error err -> throwM $ ParseError err
1036 PR.Error err -> throwM $ ParseError err
1037
1037
1038------------------------------------------------------------------------------
1038------------------------------------------------------------------------------
@@ -1077,22 +1077,22 @@ parseMany (PRD.Parser pstep initial extract) (Stream step state) =
1077 Yield x s -> do
1077 Yield x s -> do
1078 pRes <- pstep pst x
1078 pRes <- pstep pst x
1079 case pRes of
1079 case pRes of
1080− PR.Yield 0 pst1 ->
1080+ PR.Partial 0 pst1 ->
1081 return $ Skip $ ParseChunksStream s [] pst1
1081 return $ Skip $ ParseChunksStream s [] pst1
1082− PR.Yield n pst1 -> do
1082+ PR.Partial n pst1 -> do
1083 assert (n <= length (x:buf)) (return ())
1083 assert (n <= length (x:buf)) (return ())
1084 let src0 = Prelude.take n (x:buf)
1084 let src0 = Prelude.take n (x:buf)
1085 src = Prelude.reverse src0
1085 src = Prelude.reverse src0
1086 return $ Skip $ ParseChunksBuf src s [] pst1
1086 return $ Skip $ ParseChunksBuf src s [] pst1
1087− -- PR.Skip 0 pst1 ->
1087+ -- PR.Continue 0 pst1 ->
1088 -- return $ Skip $ ParseChunksStream s (x:buf) pst1
1088 -- return $ Skip $ ParseChunksStream s (x:buf) pst1
1089− PR.Skip n pst1 -> do
1089+ PR.Continue n pst1 -> do
1090 assert (n <= length (x:buf)) (return ())
1090 assert (n <= length (x:buf)) (return ())
1091 let (src0, buf1) = splitAt n (x:buf)
1091 let (src0, buf1) = splitAt n (x:buf)
1092 src = Prelude.reverse src0
1092 src = Prelude.reverse src0
1093 return $ Skip $ ParseChunksBuf src s buf1 pst1
1093 return $ Skip $ ParseChunksBuf src s buf1 pst1
1094 -- XXX Specialize for Stop 0 common case?
1094 -- XXX Specialize for Stop 0 common case?
1095− PR.Stop n b -> do
1095+ PR.Done n b -> do
1096 assert (n <= length (x:buf)) (return ())
1096 assert (n <= length (x:buf)) (return ())
1097 let src = Prelude.reverse (Prelude.take n (x:buf))
1097 let src = Prelude.reverse (Prelude.take n (x:buf))
1098 return $ Skip $
1098 return $ Skip $
@@ -1113,21 +1113,21 @@ parseMany (PRD.Parser pstep initial extract) (Stream step state) =
1113 stepOuter _ (ParseChunksBuf (x:xs) s buf pst) = do
1113 stepOuter _ (ParseChunksBuf (x:xs) s buf pst) = do
1114 pRes <- pstep pst x
1114 pRes <- pstep pst x
1115 case pRes of
1115 case pRes of
1116− PR.Yield 0 pst1 ->
1116+ PR.Partial 0 pst1 ->
1117 return $ Skip $ ParseChunksBuf xs s [] pst1
1117 return $ Skip $ ParseChunksBuf xs s [] pst1
1118− PR.Yield n pst1 -> do
1118+ PR.Partial n pst1 -> do
1119 assert (n <= length (x:buf)) (return ())
1119 assert (n <= length (x:buf)) (return ())
1120 let src0 = Prelude.take n (x:buf)
1120 let src0 = Prelude.take n (x:buf)
1121 src = Prelude.reverse src0 ++ xs
1121 src = Prelude.reverse src0 ++ xs
1122 return $ Skip $ ParseChunksBuf src s [] pst1
1122 return $ Skip $ ParseChunksBuf src s [] pst1
1123− -- PR.Skip 0 pst1 -> return $ Skip $ ParseChunksBuf xs s (x:buf) pst1
1123+ -- PR.Continue 0 pst1 -> return $ Skip $ ParseChunksBuf xs s (x:buf) pst1
1124− PR.Skip n pst1 -> do
1124+ PR.Continue n pst1 -> do
1125 assert (n <= length (x:buf)) (return ())
1125 assert (n <= length (x:buf)) (return ())
1126 let (src0, buf1) = splitAt n (x:buf)
1126 let (src0, buf1) = splitAt n (x:buf)
1127 src = Prelude.reverse src0 ++ xs
1127 src = Prelude.reverse src0 ++ xs
1128 return $ Skip $ ParseChunksBuf src s buf1 pst1
1128 return $ Skip $ ParseChunksBuf src s buf1 pst1
1129 -- XXX Specialize for Stop 0 common case?
1129 -- XXX Specialize for Stop 0 common case?
1130− PR.Stop n b -> do
1130+ PR.Done n b -> do
1131 assert (n <= length (x:buf)) (return ())
1131 assert (n <= length (x:buf)) (return ())
1132 let src = Prelude.reverse (Prelude.take n (x:buf)) ++ xs
1132 let src = Prelude.reverse (Prelude.take n (x:buf)) ++ xs
1133 return $ Skip $ ParseChunksYield b (ParseChunksInit src s)
1133 return $ Skip $ ParseChunksYield b (ParseChunksInit src s)
@@ -1179,25 +1179,25 @@ parseIterate func seed (Stream step state) =
1179 pst <- initial
1179 pst <- initial
1180 pRes <- pstep pst x
1180 pRes <- pstep pst x
1181 case pRes of
1181 case pRes of
1182− PR.Yield 0 pst1 ->
1182+ PR.Partial 0 pst1 ->
1183 return $ Skip $ ConcatParseStream s []
1183 return $ Skip $ ConcatParseStream s []
1184 (PRD.Parser pstep (return pst1) extract)
1184 (PRD.Parser pstep (return pst1) extract)
1185− PR.Yield n pst1 -> do
1185+ PR.Partial n pst1 -> do
1186 assert (n <= length (x:buf)) (return ())
1186 assert (n <= length (x:buf)) (return ())
1187 let src0 = Prelude.take n (x:buf)
1187 let src0 = Prelude.take n (x:buf)
1188 src = Prelude.reverse src0
1188 src = Prelude.reverse src0
1189 return $ Skip $ ConcatParseBuf src s []
1189 return $ Skip $ ConcatParseBuf src s []
1190 (PRD.Parser pstep (return pst1) extract)
1190 (PRD.Parser pstep (return pst1) extract)
1191− -- PR.Skip 0 pst1 ->
1191+ -- PR.Continue 0 pst1 ->
1192 -- return $ Skip $ ConcatParseStream s (x:buf) pst1
1192 -- return $ Skip $ ConcatParseStream s (x:buf) pst1
1193− PR.Skip n pst1 -> do
1193+ PR.Continue n pst1 -> do
1194 assert (n <= length (x:buf)) (return ())
1194 assert (n <= length (x:buf)) (return ())
1195 let (src0, buf1) = splitAt n (x:buf)
1195 let (src0, buf1) = splitAt n (x:buf)
1196 src = Prelude.reverse src0
1196 src = Prelude.reverse src0
1197 return $ Skip $ ConcatParseBuf src s buf1
1197 return $ Skip $ ConcatParseBuf src s buf1
1198 (PRD.Parser pstep (return pst1) extract)
1198 (PRD.Parser pstep (return pst1) extract)
1199 -- XXX Specialize for Stop 0 common case?
1199 -- XXX Specialize for Stop 0 common case?
1200− PR.Stop n b -> do
1200+ PR.Done n b -> do
1201 assert (n <= length (x:buf)) (return ())
1201 assert (n <= length (x:buf)) (return ())
1202 let src = Prelude.reverse (Prelude.take n (x:buf))
1202 let src = Prelude.reverse (Prelude.take n (x:buf))
1203 return $ Skip $
1203 return $ Skip $
@@ -1221,24 +1221,24 @@ parseIterate func seed (Stream step state) =
1221 pst <- initial
1221 pst <- initial
1222 pRes <- pstep pst x
1222 pRes <- pstep pst x
1223 case pRes of
1223 case pRes of
1224− PR.Yield 0 pst1 ->
1224+ PR.Partial 0 pst1 ->
1225 return $ Skip $ ConcatParseBuf xs s []
1225 return $ Skip $ ConcatParseBuf xs s []
1226 (PRD.Parser pstep (return pst1) extract)
1226 (PRD.Parser pstep (return pst1) extract)
1227− PR.Yield n pst1 -> do
1227+ PR.Partial n pst1 -> do
1228 assert (n <= length (x:buf)) (return ())
1228 assert (n <= length (x:buf)) (return ())
1229 let src0 = Prelude.take n (x:buf)
1229 let src0 = Prelude.take n (x:buf)
1230 src = Prelude.reverse src0 ++ xs
1230 src = Prelude.reverse src0 ++ xs
1231 return $ Skip $ ConcatParseBuf src s []
1231 return $ Skip $ ConcatParseBuf src s []
1232 (PRD.Parser pstep (return pst1) extract)
1232 (PRD.Parser pstep (return pst1) extract)
1233− -- PR.Skip 0 pst1 -> return $ Skip $ ConcatParseBuf xs s (x:buf) pst1
1233+ -- PR.Continue 0 pst1 -> return $ Skip $ ConcatParseBuf xs s (x:buf) pst1
1234− PR.Skip n pst1 -> do
1234+ PR.Continue n pst1 -> do
1235 assert (n <= length (x:buf)) (return ())
1235 assert (n <= length (x:buf)) (return ())
1236 let (src0, buf1) = splitAt n (x:buf)
1236 let (src0, buf1) = splitAt n (x:buf)
1237 src = Prelude.reverse src0 ++ xs
1237 src = Prelude.reverse src0 ++ xs
1238 return $ Skip $ ConcatParseBuf src s buf1
1238 return $ Skip $ ConcatParseBuf src s buf1
1239 (PRD.Parser pstep (return pst1) extract)
1239 (PRD.Parser pstep (return pst1) extract)
1240 -- XXX Specialize for Stop 0 common case?
1240 -- XXX Specialize for Stop 0 common case?
1241− PR.Stop n b -> do
1241+ PR.Done n b -> do
1242 assert (n <= length (x:buf)) (return ())
1242 assert (n <= length (x:buf)) (return ())
1243 let src = Prelude.reverse (Prelude.take n (x:buf)) ++ xs
1243 let src = Prelude.reverse (Prelude.take n (x:buf)) ++ xs
1244 return $ Skip $ ConcatParseYield b
1244 return $ Skip $ ConcatParseYield b
src/Streamly/Internal/Data/Zipper.hs+20−20
@@ -221,19 +221,19 @@ parse pstep initial extract (Zipper [] ls rs stream) =
221 yieldk x r = do
221 yieldk x r = do
222 acc1 <- acc >>= \b -> pstep b x
222 acc1 <- acc >>= \b -> pstep b x
223 case acc1 of
223 case acc1 of
224− PR.Yield 0 pst1 -> go r [] (return pst1)
224+ PR.Partial 0 pst1 -> go r [] (return pst1)
225− PR.Yield n pst1 -> do
225+ PR.Partial n pst1 -> do
226 assert (n <= length (x:buf)) (return ())
226 assert (n <= length (x:buf)) (return ())
227 let src0 = Prelude.take n (x:buf)
227 let src0 = Prelude.take n (x:buf)
228 src = Prelude.reverse src0
228 src = Prelude.reverse src0
229 gobuf r [] src (return pst1)
229 gobuf r [] src (return pst1)
230− PR.Skip 0 pst1 -> go r (x:buf) (return pst1)
230+ PR.Continue 0 pst1 -> go r (x:buf) (return pst1)
231− PR.Skip n pst1 -> do
231+ PR.Continue n pst1 -> do
232 assert (n <= length (x:buf)) (return ())
232 assert (n <= length (x:buf)) (return ())
233 let (src0, buf1) = splitAt n (x:buf)
233 let (src0, buf1) = splitAt n (x:buf)
234 src = Prelude.reverse src0
234 src = Prelude.reverse src0
235 gobuf r buf1 src (return pst1)
235 gobuf r buf1 src (return pst1)
236− PR.Stop n b -> do
236+ PR.Done n b -> do
237 assert (n <= length (x:buf)) (return ())
237 assert (n <= length (x:buf)) (return ())
238 let (src0, buf1) = splitAt n (x:buf)
238 let (src0, buf1) = splitAt n (x:buf)
239 src = Prelude.reverse src0
239 src = Prelude.reverse src0
@@ -247,20 +247,20 @@ parse pstep initial extract (Zipper [] ls rs stream) =
247 r <- pst
247 r <- pst
248 pRes <- pstep r x
248 pRes <- pstep r x
249 case pRes of
249 case pRes of
250− PR.Yield 0 pst1 ->
250+ PR.Partial 0 pst1 ->
251 gobuf s [] xs (return pst1)
251 gobuf s [] xs (return pst1)
252− PR.Yield n pst1 -> do
252+ PR.Partial n pst1 -> do
253 assert (n <= length (x:buf)) (return ())
253 assert (n <= length (x:buf)) (return ())
254 let src0 = Prelude.take n (x:buf)
254 let src0 = Prelude.take n (x:buf)
255 src = Prelude.reverse src0
255 src = Prelude.reverse src0
256 gobuf s [] (src ++ xs) (return pst1)
256 gobuf s [] (src ++ xs) (return pst1)
257− PR.Skip 0 pst1 -> gobuf s (x:buf) xs (return pst1)
257+ PR.Continue 0 pst1 -> gobuf s (x:buf) xs (return pst1)
258− PR.Skip n pst1 -> do
258+ PR.Continue n pst1 -> do
259 assert (n <= length (x:buf)) (return ())
259 assert (n <= length (x:buf)) (return ())
260 let (src0, buf1) = splitAt n (x:buf)
260 let (src0, buf1) = splitAt n (x:buf)
261 src = Prelude.reverse src0 ++ xs
261 src = Prelude.reverse src0 ++ xs
262 gobuf s buf1 src (return pst1)
262 gobuf s buf1 src (return pst1)
263− PR.Stop n b -> do
263+ PR.Done n b -> do
264 assert (n <= length (x:buf)) (return ())
264 assert (n <= length (x:buf)) (return ())
265 let (src0, buf1) = splitAt n (x:buf)
265 let (src0, buf1) = splitAt n (x:buf)
266 src = Prelude.reverse src0 ++ xs
266 src = Prelude.reverse src0 ++ xs
@@ -291,21 +291,21 @@ parse pstep initial extract (Zipper (cp:cps) ls rs stream) =
291 acc1 <- acc >>= \b -> pstep b x
291 acc1 <- acc >>= \b -> pstep b x
292 let cnt1 = cnt + 1
292 let cnt1 = cnt + 1
293 case acc1 of
293 case acc1 of
294− PR.Yield 0 pst1 ->
294+ PR.Partial 0 pst1 ->
295 go cnt1 r [] (return pst1)
295 go cnt1 r [] (return pst1)
296− PR.Yield n pst1 -> do
296+ PR.Partial n pst1 -> do
297 assert (n <= length (x:buf)) (return ())
297 assert (n <= length (x:buf)) (return ())
298 let src0 = Prelude.take n (x:buf)
298 let src0 = Prelude.take n (x:buf)
299 src = Prelude.reverse src0
299 src = Prelude.reverse src0
300 gobuf (cnt1 - n) r [] src (return pst1)
300 gobuf (cnt1 - n) r [] src (return pst1)
301− PR.Skip 0 pst1 -> go cnt1 r (x:buf) (return pst1)
301+ PR.Continue 0 pst1 -> go cnt1 r (x:buf) (return pst1)
302− PR.Skip n pst1 -> do
302+ PR.Continue n pst1 -> do
303 assert (n <= length (x:buf)) (return ())
303 assert (n <= length (x:buf)) (return ())
304 let (src0, buf1) = splitAt n (x:buf)
304 let (src0, buf1) = splitAt n (x:buf)
305 src = Prelude.reverse src0
305 src = Prelude.reverse src0
306 assert (cnt1 - n >= 0) (return ())
306 assert (cnt1 - n >= 0) (return ())
307 gobuf (cnt1 - n) r buf1 src (return pst1)
307 gobuf (cnt1 - n) r buf1 src (return pst1)
308− PR.Stop n b -> do
308+ PR.Done n b -> do
309 assert (n <= length (x:buf)) (return ())
309 assert (n <= length (x:buf)) (return ())
310 let (src0, buf1) = splitAt n (x:buf)
310 let (src0, buf1) = splitAt n (x:buf)
311 src = Prelude.reverse src0
311 src = Prelude.reverse src0
@@ -325,21 +325,21 @@ parse pstep initial extract (Zipper (cp:cps) ls rs stream) =
325 pRes <- pstep r x
325 pRes <- pstep r x
326 let cnt1 = cnt + 1
326 let cnt1 = cnt + 1
327 case pRes of
327 case pRes of
328− PR.Yield 0 pst1 ->
328+ PR.Partial 0 pst1 ->
329 gobuf cnt1 s [] xs (return pst1)
329 gobuf cnt1 s [] xs (return pst1)
330− PR.Yield n pst1 -> do
330+ PR.Partial n pst1 -> do
331 assert (n <= length (x:buf)) (return ())
331 assert (n <= length (x:buf)) (return ())
332 let src0 = Prelude.take n (x:buf)
332 let src0 = Prelude.take n (x:buf)
333 src = Prelude.reverse src0
333 src = Prelude.reverse src0
334 gobuf (cnt1 - n) s [] (src ++ xs) (return pst1)
334 gobuf (cnt1 - n) s [] (src ++ xs) (return pst1)
335− PR.Skip 0 pst1 -> gobuf cnt1 s (x:buf) xs (return pst1)
335+ PR.Continue 0 pst1 -> gobuf cnt1 s (x:buf) xs (return pst1)
336− PR.Skip n pst1 -> do
336+ PR.Continue n pst1 -> do
337 assert (n <= length (x:buf)) (return ())
337 assert (n <= length (x:buf)) (return ())
338 let (src0, buf1) = splitAt n (x:buf)
338 let (src0, buf1) = splitAt n (x:buf)
339 src = Prelude.reverse src0 ++ xs
339 src = Prelude.reverse src0 ++ xs
340 assert (cnt1 - n >= 0) (return ())
340 assert (cnt1 - n >= 0) (return ())
341 gobuf (cnt1 - n) s buf1 src (return pst1)
341 gobuf (cnt1 - n) s buf1 src (return pst1)
342− PR.Stop n b -> do
342+ PR.Done n b -> do
343 assert (n <= length (x:buf)) (return ())
343 assert (n <= length (x:buf)) (return ())
344 let (src0, buf1) = splitAt n (x:buf)
344 let (src0, buf1) = splitAt n (x:buf)
345 src = Prelude.reverse src0 ++ xs
345 src = Prelude.reverse src0 ++ xs