@@ -21,8 +21,8 @@ module Streamly.Internal.Data.Parser
21 , Step (..)
21 , Step (..)
22 , Initial (..)
22 , Initial (..)
24− -- * Downgrade to Fold
24+ -- -- * Downgrade to Fold
25− , toFold
25+ -- , toFold
27 -- First order parsers
27 -- First order parsers
28 -- * Accumulators
28 -- * Accumulators
@@ -270,6 +270,10 @@ import Prelude hiding
270-- Downgrade a parser to a Fold
270-- Downgrade a parser to a Fold
271-------------------------------------------------------------------------------
271-------------------------------------------------------------------------------
273+-- XXX Parsers cannot be converted to folds, because they do not have a
274+-- scanning function. Can we move the applicative folds to parsers instead?
275+-- need to measure the performance.
273-- | Make a 'Fold' from a 'Parser'. The fold just throws an exception if the
277-- | Make a 'Fold' from a 'Parser'. The fold just throws an exception if the
274-- parser fails or tries to backtrack.
278-- parser fails or tries to backtrack.
@@ -281,7 +285,7 @@ import Prelude hiding
282{-# INLINE toFold #-}
286{-# INLINE toFold #-}
283toFold :: Monad m => Parser a m b -> Fold m a b
287toFold :: Monad m => Parser a m b -> Fold m a b
284−toFold (Parser pstep pinitial pextract) = Fold step initial extract
288+toFold (Parser pstep pinitial pextract) = Fold step initial extract final
@@ -317,6 +321,7 @@ toFold (Parser pstep pinitial pextract) = Fold step initial extract
317 Continue n _ -> cerror n
321 Continue n _ -> cerror n
318 Done n _ -> derror n
322 Done n _ -> derror n
319 Error err -> eerror err
323 Error err -> eerror err
321-------------------------------------------------------------------------------
326-------------------------------------------------------------------------------
322-- Upgrade folds to parses
327-- Upgrade folds to parses
@@ -327,7 +332,7 @@ toFold (Parser pstep pinitial pextract) = Fold step initial extract
328{-# INLINE fromFold #-}
333{-# INLINE fromFold #-}
329fromFold :: Monad m => Fold m a b -> Parser a m b
334fromFold :: Monad m => Fold m a b -> Parser a m b
330−fromFold (Fold fstep finitial fextract) = Parser step initial extract
335+fromFold (Fold fstep finitial _ ffinal) = Parser step initial extract
@@ -345,7 +350,7 @@ fromFold (Fold fstep finitial fextract) = Parser step initial extract
345 FL.Partial s1 -> Partial 0 s1
350 FL.Partial s1 -> Partial 0 s1
346 FL.Done b -> Done 0 b
351 FL.Done b -> Done 0 b
348− extract = fmap (Done 0) . fextract
353+ extract = fmap (Done 0) . ffinal
350-- | Convert a Maybe returning fold to an error returning parser. The first
355-- | Convert a Maybe returning fold to an error returning parser. The first
351-- argument is the error message that the parser would return when the fold
356-- argument is the error message that the parser would return when the fold
@@ -355,7 +360,7 @@ fromFold (Fold fstep finitial fextract) = Parser step initial extract
356{-# INLINE fromFoldMaybe #-}
361{-# INLINE fromFoldMaybe #-}
357fromFoldMaybe :: Monad m => String -> Fold m a (Maybe b) -> Parser a m b
362fromFoldMaybe :: Monad m => String -> Fold m a (Maybe b) -> Parser a m b
358−fromFoldMaybe errMsg (Fold fstep finitial fextract) =
363+fromFoldMaybe errMsg (Fold fstep finitial _ ffinal) =
359 Parser step initial extract
364 Parser step initial extract
@@ -381,7 +386,7 @@ fromFoldMaybe errMsg (Fold fstep finitial fextract) =
381 Nothing -> Error errMsg
386 Nothing -> Error errMsg
383 extract s = do
388 extract s = do
384− res <- fextract s
389+ res <- ffinal s
385 case res of
390 case res of
386 Just x -> return $ Done 0 x
391 Just x -> return $ Done 0 x
387 Nothing -> return $ Error errMsg
392 Nothing -> return $ Error errMsg
@@ -630,7 +635,7 @@ data Tuple'Fused a b = Tuple'Fused !a !b deriving Show
631{-# INLINE takeBetween #-}
636{-# INLINE takeBetween #-}
632takeBetween :: Monad m => Int -> Int -> Fold m a b -> Parser a m b
637takeBetween :: Monad m => Int -> Int -> Fold m a b -> Parser a m b
633−takeBetween low high (Fold fstep finitial fextract) =
638+takeBetween low high (Fold fstep finitial _ ffinal) =
635 Parser step initial (extract streamErr)
640 Parser step initial (extract streamErr)
@@ -685,7 +690,7 @@ takeBetween low high (Fold fstep finitial fextract) =
685 then return $ Continue 0 s1
690 then return $ Continue 0 s1
686 else if i1 < high
691 else if i1 < high
687 then return $ Partial 0 s1
692 then return $ Partial 0 s1
688− else fmap (Done 0) (fextract s)
693+ else fmap (Done 0) (ffinal s)
689 FL.Done b ->
694 FL.Done b ->
691 $ if i1 >= low
696 $ if i1 >= low
@@ -695,12 +700,12 @@ takeBetween low high (Fold fstep finitial fextract) =
695 step (Tuple'Fused i s) a = fstep s a >>= snext i
700 step (Tuple'Fused i s) a = fstep s a >>= snext i
697 extract f (Tuple'Fused i s)
702 extract f (Tuple'Fused i s)
698− | i >= low && i <= high = fmap (Done 0) (fextract s)
703+ | i >= low && i <= high = fmap (Done 0) (ffinal s)
699 | otherwise = return $ Error (f i)
704 | otherwise = return $ Error (f i)
701 -- XXX Need to make Initial return type Step to deduplicate this
706 -- XXX Need to make Initial return type Step to deduplicate this
702 iextract f (Tuple'Fused i s)
707 iextract f (Tuple'Fused i s)
703− | i >= low && i <= high = fmap IDone (fextract s)
708+ | i >= low && i <= high = fmap IDone (ffinal s)
704 | otherwise = return $ IError (f i)
709 | otherwise = return $ IError (f i)
706-- | Stops after taking exactly @n@ input elements.
711-- | Stops after taking exactly @n@ input elements.
@@ -717,7 +722,7 @@ takeBetween low high (Fold fstep finitial fextract) =
718{-# INLINE takeEQ #-}
723{-# INLINE takeEQ #-}
719takeEQ :: Monad m => Int -> Fold m a b -> Parser a m b
724takeEQ :: Monad m => Int -> Fold m a b -> Parser a m b
720−takeEQ n (Fold fstep finitial fextract) = Parser step initial extract
725+takeEQ n (Fold fstep finitial _ ffinal) = Parser step initial extract
@@ -727,7 +732,7 @@ takeEQ n (Fold fstep finitial fextract) = Parser step initial extract
727 FL.Partial s ->
732 FL.Partial s ->
729 then return $ IPartial $ Tuple'Fused 1 s
734 then return $ IPartial $ Tuple'Fused 1 s
730− else fmap IDone (fextract s)
735+ else fmap IDone (ffinal s)
731 FL.Done b -> return $
736 FL.Done b -> return $
733 then IError
738 then IError
@@ -751,7 +756,7 @@ takeEQ n (Fold fstep finitial fextract) = Parser step initial extract
751 -- assert (n == i1)
756 -- assert (n == i1)
753 <$> case res of
758 <$> case res of
754− FL.Partial s -> fextract s
759+ FL.Partial s -> ffinal s
755 FL.Done b -> return b
760 FL.Done b -> return b
757 extract (Tuple'Fused i _) =
762 extract (Tuple'Fused i _) =
@@ -783,7 +788,7 @@ data TakeGEState s =
784{-# INLINE takeGE #-}
789{-# INLINE takeGE #-}
785takeGE :: Monad m => Int -> Fold m a b -> Parser a m b
790takeGE :: Monad m => Int -> Fold m a b -> Parser a m b
786−takeGE n (Fold fstep finitial fextract) = Parser step initial extract
791+takeGE n (Fold fstep finitial _ ffinal) = Parser step initial extract
@@ -831,7 +836,7 @@ takeGE n (Fold fstep finitial fextract) = Parser step initial extract
832 $ "takeGE: Expecting at least " ++ show n
837 $ "takeGE: Expecting at least " ++ show n
833 ++ " elements, input terminated on " ++ show (i - 1)
838 ++ " elements, input terminated on " ++ show (i - 1)
834− extract (TakeGEGE r) = fmap (Done 0) $ fextract r
839+ extract (TakeGEGE r) = fmap (Done 0) $ ffinal r
836-------------------------------------------------------------------------------
841-------------------------------------------------------------------------------
837-- Conditional splitting
842-- Conditional splitting
@@ -892,7 +897,7 @@ takeWhileP predicate (Parser pstep pinitial pextract) =
892{-# INLINE takeWhile #-}
897{-# INLINE takeWhile #-}
893takeWhile :: Monad m => (a -> Bool) -> Fold m a b -> Parser a m b
898takeWhile :: Monad m => (a -> Bool) -> Fold m a b -> Parser a m b
894-- takeWhile cond f = takeWhileP cond (fromFold f)
899-- takeWhile cond f = takeWhileP cond (fromFold f)
895−takeWhile predicate (Fold fstep finitial fextract) =
900+takeWhile predicate (Fold fstep finitial _ ffinal) =
896 Parser step initial extract
901 Parser step initial extract
@@ -911,9 +916,9 @@ takeWhile predicate (Fold fstep finitial fextract) =
911 $ case fres of
916 $ case fres of
912 FL.Partial s1 -> Partial 0 s1
917 FL.Partial s1 -> Partial 0 s1
913 FL.Done b -> Done 0 b
918 FL.Done b -> Done 0 b
914− else Done 1 <$> fextract s
919+ else Done 1 <$> ffinal s
916− extract s = fmap (Done 0) (fextract s)
921+ extract s = fmap (Done 0) (ffinal s)
919-- XXX This may not be composable because of the b argument. We can instead
924-- XXX This may not be composable because of the b argument. We can instead
@@ -933,7 +938,7 @@ takeWhile1 acc cond f = undefined
933{-# INLINE takeWhile1 #-}
938{-# INLINE takeWhile1 #-}
934takeWhile1 :: Monad m => (a -> Bool) -> Fold m a b -> Parser a m b
939takeWhile1 :: Monad m => (a -> Bool) -> Fold m a b -> Parser a m b
935-- takeWhile1 cond f = takeWhileP cond (takeBetween 1 maxBound f)
940-- takeWhile1 cond f = takeWhileP cond (takeBetween 1 maxBound f)
936−takeWhile1 predicate (Fold fstep finitial fextract) =
941+takeWhile1 predicate (Fold fstep finitial _ ffinal) =
937 Parser step initial extract
942 Parser step initial extract
@@ -963,11 +968,11 @@ takeWhile1 predicate (Fold fstep finitial fextract) =
963 if predicate a
968 if predicate a
964 then process s a
969 then process s a
966− b <- fextract s
971+ b <- ffinal s
967 return $ Done 1 b
972 return $ Done 1 b
969 extract (Left' _) = return $ Error "takeWhile1: end of input"
974 extract (Left' _) = return $ Error "takeWhile1: end of input"
970− extract (Right' s) = fmap (Done 0) (fextract s)
975+ extract (Right' s) = fmap (Done 0) (ffinal s)
972-- | Drain the input as long as the predicate succeeds, running the effects and
977-- | Drain the input as long as the predicate succeeds, running the effects and
973-- discarding the results.
978-- discarding the results.
@@ -996,7 +1001,7 @@ takeFramedByGeneric :: Monad m =>
996 -> Maybe (a -> Bool) -- is frame end?
1001 -> Maybe (a -> Bool) -- is frame end?
997 -> Fold m a b
1002 -> Fold m a b
998 -> Parser a m b
1003 -> Parser a m b
999−takeFramedByGeneric esc begin end (Fold fstep finitial fextract) =
1004+takeFramedByGeneric esc begin end (Fold fstep finitial _ ffinal) =
1001 Parser step initial extract
1006 Parser step initial extract
@@ -1028,20 +1033,20 @@ takeFramedByGeneric esc begin end (Fold fstep finitial fextract) =
1028 if isEnd a
1033 if isEnd a
1030 if n == 0
1035 if n == 0
1031− then Done 0 <$> fextract s
1036+ then Done 0 <$> ffinal s
1032 else process s a (n - 1)
1037 else process s a (n - 1)
1034 let n1 = if isBegin a then n + 1 else n
1039 let n1 = if isBegin a then n + 1 else n
1035 in process s a n1
1040 in process s a n1
1036 Nothing -> -- takeEndBy case
1041 Nothing -> -- takeEndBy case
1037 if isEnd a
1042 if isEnd a
1038− then Done 0 <$> fextract s
1043+ then Done 0 <$> ffinal s
1039 else process s a n
1044 else process s a n
1040 Nothing -> -- takeStartBy case
1045 Nothing -> -- takeStartBy case
1041 case begin of
1046 case begin of
1042 Just isBegin ->
1047 Just isBegin ->
1043 if isBegin a
1048 if isBegin a
1044− then Done 0 <$> fextract s
1049+ then Done 0 <$> ffinal s
1045 else process s a n
1050 else process s a n
1046 Nothing ->
1051 Nothing ->
1047 error $ "takeFramedByGeneric: "
1052 error $ "takeFramedByGeneric: "
@@ -1066,7 +1071,7 @@ takeFramedByGeneric esc begin end (Fold fstep finitial fextract) =
1066 case end of
1071 case end of
1067 Just isEnd ->
1072 Just isEnd ->
1068 if isEnd a
1073 if isEnd a
1069− then Done 0 <$> fextract s
1074+ then Done 0 <$> ffinal s
1070 else processCheckEsc s a 0
1075 else processCheckEsc s a 0
1071 Nothing ->
1076 Nothing ->
1072 error "Both begin and end frame predicate missing"
1077 error "Both begin and end frame predicate missing"
@@ -1081,7 +1086,7 @@ takeFramedByGeneric esc begin end (Fold fstep finitial fextract) =
1081 case begin of
1086 case begin of
1082 Just _ ->
1087 Just _ ->
1083 case end of
1088 case end of
1084− Nothing -> fmap (Done 0) $ fextract s
1089+ Nothing -> fmap (Done 0) $ ffinal s
1085 Just _ -> err "takeFramedByGeneric: missing frame end"
1090 Just _ -> err "takeFramedByGeneric: missing frame end"
1086 Nothing -> err "takeFramedByGeneric: missing closing frame"
1091 Nothing -> err "takeFramedByGeneric: missing closing frame"
1087 extract (FrameEscEsc _ _) = err "takeFramedByGeneric: trailing escape"
1092 extract (FrameEscEsc _ _) = err "takeFramedByGeneric: trailing escape"
@@ -1120,7 +1125,7 @@ blockWithQuotes :: (Monad m, Eq a) =>
1120 -> Fold m a b
1125 -> Fold m a b
1121 -> Parser a m b
1126 -> Parser a m b
1122blockWithQuotes isEsc isQuote bopen bclose
1127blockWithQuotes isEsc isQuote bopen bclose
1123− (Fold fstep finitial fextract) =
1128+ (Fold fstep finitial _ ffinal) =
1124 Parser step initial extract
1129 Parser step initial extract
@@ -1150,7 +1155,7 @@ blockWithQuotes isEsc isQuote bopen bclose
1150 | a == bopen = process s a (BlockUnquoted (level + 1))
1155 | a == bopen = process s a (BlockUnquoted (level + 1))
1151 | a == bclose =
1156 | a == bclose =
1152 if level == 1
1157 if level == 1
1153− then fmap (Done 0) (fextract s)
1158+ then fmap (Done 0) (ffinal s)
1154 else process s a (BlockUnquoted (level - 1))
1159 else process s a (BlockUnquoted (level - 1))
1155 | isQuote a = process s a (BlockQuoted level)
1160 | isQuote a = process s a (BlockQuoted level)
1156 | otherwise = process s a (BlockUnquoted level)
1161 | otherwise = process s a (BlockUnquoted level)
@@ -1164,7 +1169,7 @@ blockWithQuotes isEsc isQuote bopen bclose
1165 err = return . Error
1170 err = return . Error
1167− extract (BlockInit s) = fmap (Done 0) $ fextract s
1172+ extract (BlockInit s) = fmap (Done 0) $ ffinal s
1168 extract (BlockUnquoted level _) =
1173 extract (BlockUnquoted level _) =
1169 err $ "blockWithQuotes: finished at block nest level " ++ show level
1174 err $ "blockWithQuotes: finished at block nest level " ++ show level
1170 extract (BlockQuoted level _) =
1175 extract (BlockQuoted level _) =
@@ -1299,7 +1304,7 @@ takeEitherSepBy _cond = undefined -- D.toParserK . D.takeEitherSepBy cond
1300{-# INLINE takeStartBy #-}
1305{-# INLINE takeStartBy #-}
1301takeStartBy :: Monad m => (a -> Bool) -> Fold m a b -> Parser a m b
1306takeStartBy :: Monad m => (a -> Bool) -> Fold m a b -> Parser a m b
1302−takeStartBy cond (Fold fstep finitial fextract) =
1307+takeStartBy cond (Fold fstep finitial _ ffinal) =
1304 Parser step initial extract
1309 Parser step initial extract
@@ -1327,10 +1332,10 @@ takeStartBy cond (Fold fstep finitial fextract) =
1327 step (Right' s) a =
1332 step (Right' s) a =
1328 if not (cond a)
1333 if not (cond a)
1329 then process s a
1334 then process s a
1330− else Done 1 <$> fextract s
1335+ else Done 1 <$> ffinal s
1332− extract (Left' s) = fmap (Done 0) $ fextract s
1337+ extract (Left' s) = fmap (Done 0) $ ffinal s
1333− extract (Right' s) = fmap (Done 0) $ fextract s
1338+ extract (Right' s) = fmap (Done 0) $ ffinal s
1335-- | Like 'takeStartBy' but drops the separator.
1340-- | Like 'takeStartBy' but drops the separator.
@@ -1366,7 +1371,7 @@ takeFramedByEsc_ :: Monad m =>
1366 (a -> Bool) -> (a -> Bool) -> (a -> Bool) -> Fold m a b -> Parser a m b
1371 (a -> Bool) -> (a -> Bool) -> (a -> Bool) -> Fold m a b -> Parser a m b
1367-- takeFramedByEsc_ isEsc isEnd p =
1372-- takeFramedByEsc_ isEsc isEnd p =
1368-- takeFramedByGeneric (Just isEsc) Nothing (Just isEnd) (toFold p)
1373-- takeFramedByGeneric (Just isEsc) Nothing (Just isEnd) (toFold p)
1369−takeFramedByEsc_ isEsc isBegin isEnd (Fold fstep finitial fextract) =
1374+takeFramedByEsc_ isEsc isBegin isEnd (Fold fstep finitial _ ffinal ) =
1371 Parser step initial extract
1376 Parser step initial extract
@@ -1402,7 +1407,7 @@ takeFramedByEsc_ isEsc isBegin isEnd (Fold fstep finitial fextract) =
1402 in process s a n1
1407 in process s a n1
1404 if n == 0
1409 if n == 0
1405− then Done 0 <$> fextract s
1410+ then Done 0 <$> ffinal s
1406 else process s a (n - 1)
1411 else process s a (n - 1)
1407 step (FrameEscEsc s n) a = process s a n
1412 step (FrameEscEsc s n) a = process s a n
@@ -1424,7 +1429,7 @@ takeFramedBy_ :: Monad m =>
1424 (a -> Bool) -> (a -> Bool) -> Fold m a b -> Parser a m b
1429 (a -> Bool) -> (a -> Bool) -> Fold m a b -> Parser a m b
1425-- takeFramedBy_ isBegin isEnd =
1430-- takeFramedBy_ isBegin isEnd =
1426-- takeFramedByGeneric (Just (const False)) (Just isBegin) (Just isEnd)
1431-- takeFramedByGeneric (Just (const False)) (Just isBegin) (Just isEnd)
1427−takeFramedBy_ isBegin isEnd (Fold fstep finitial fextract) =
1432+takeFramedBy_ isBegin isEnd (Fold fstep finitial _ ffinal) =
1429 Parser step initial extract
1434 Parser step initial extract
@@ -1454,7 +1459,7 @@ takeFramedBy_ isBegin isEnd (Fold fstep finitial fextract) =
1454 | not (isEnd a) =
1459 | not (isEnd a) =
1455 let n1 = if isBegin a then n + 1 else n
1460 let n1 = if isBegin a then n + 1 else n
1456 in process s a n1
1461 in process s a n1
1457− | n == 0 = Done 0 <$> fextract s
1462+ | n == 0 = Done 0 <$> ffinal s
1458 | otherwise = process s a (n - 1)
1463 | otherwise = process s a (n - 1)
1460 err = return . Error
1465 err = return . Error
@@ -1489,7 +1494,7 @@ data WordByState s b = WBLeft !s | WBWord !s | WBRight !b
1490{-# INLINE wordBy #-}
1495{-# INLINE wordBy #-}
1491wordBy :: Monad m => (a -> Bool) -> Fold m a b -> Parser a m b
1496wordBy :: Monad m => (a -> Bool) -> Fold m a b -> Parser a m b
1492−wordBy predicate (Fold fstep finitial fextract) = Parser step initial extract
1497+wordBy predicate (Fold fstep finitial _ ffinal) = Parser step initial extract
@@ -1516,7 +1521,7 @@ wordBy predicate (Fold fstep finitial fextract) = Parser step initial extract
1516 if not (predicate a)
1521 if not (predicate a)
1517 then worder s a
1522 then worder s a
1519− b <- fextract s
1524+ b <- ffinal s
1520 return $ Partial 0 $ WBRight b
1525 return $ Partial 0 $ WBRight b
1521 step (WBRight b) a =
1526 step (WBRight b) a =
@@ -1524,8 +1529,8 @@ wordBy predicate (Fold fstep finitial fextract) = Parser step initial extract
1524 then Done 1 b
1529 then Done 1 b
1525 else Partial 0 $ WBRight b
1530 else Partial 0 $ WBRight b
1527− extract (WBLeft s) = fmap (Done 0) $ fextract s
1532+ extract (WBLeft s) = fmap (Done 0) $ ffinal s
1528− extract (WBWord s) = fmap (Done 0) $ fextract s
1533+ extract (WBWord s) = fmap (Done 0) $ ffinal s
1529 extract (WBRight b) = return (Done 0 b)
1534 extract (WBRight b) = return (Done 0 b)
1531data WordFramedState s b =
1536data WordFramedState s b =
@@ -1562,7 +1567,7 @@ wordFramedBy :: Monad m =>
1562 -> Fold m a b
1567 -> Fold m a b
1563 -> Parser a m b
1568 -> Parser a m b
1564wordFramedBy isEsc isBegin isEnd isSep
1569wordFramedBy isEsc isBegin isEnd isSep
1565− (Fold fstep finitial fextract) =
1570+ (Fold fstep finitial _ ffinal) =
1566 Parser step initial extract
1571 Parser step initial extract
@@ -1593,7 +1598,7 @@ wordFramedBy isEsc isBegin isEnd isSep
1593 step (WordFramedWord s n) a
1598 step (WordFramedWord s n) a
1594 | isEsc a = return $ Continue 0 $ WordFramedEsc s n
1599 | isEsc a = return $ Continue 0 $ WordFramedEsc s n
1595 | n == 0 && isSep a = do
1600 | n == 0 && isSep a = do
1596− b <- fextract s
1601+ b <- ffinal s
1597 return $ Partial 0 $ WordFramedSkipPost b
1602 return $ Partial 0 $ WordFramedSkipPost b
1598 | otherwise = do
1603 | otherwise = do
1599 -- We need to use different order for checking begin and end for
1604 -- We need to use different order for checking begin and end for
@@ -1626,10 +1631,10 @@ wordFramedBy isEsc isBegin isEnd isSep
1627 err = return . Error
1632 err = return . Error
1629− extract (WordFramedSkipPre s) = fmap (Done 0) $ fextract s
1634+ extract (WordFramedSkipPre s) = fmap (Done 0) $ ffinal s
1630 extract (WordFramedWord s n) =
1635 extract (WordFramedWord s n) =
1631 if n == 0
1636 if n == 0
1632− then fmap (Done 0) $ fextract s
1637+ then fmap (Done 0) $ ffinal s
1633 else err "wordFramedBy: missing frame end"
1638 else err "wordFramedBy: missing frame end"
1634 extract (WordFramedEsc _ _) =
1639 extract (WordFramedEsc _ _) =
1635 err "wordFramedBy: trailing escape"
1640 err "wordFramedBy: trailing escape"
@@ -1716,7 +1721,7 @@ wordWithQuotes :: (Monad m, Eq a) =>
1716 -> Fold m a b
1721 -> Fold m a b
1717 -> Parser a m b
1722 -> Parser a m b
1718wordWithQuotes keepQuotes tr escChar toRight isSep
1723wordWithQuotes keepQuotes tr escChar toRight isSep
1719− (Fold fstep finitial fextract) =
1724+ (Fold fstep finitial _ ffinal) =
1720 Parser step initial extract
1725 Parser step initial extract
@@ -1767,7 +1772,7 @@ wordWithQuotes keepQuotes tr escChar toRight isSep
1767 step (WordUnquotedWord s) a
1772 step (WordUnquotedWord s) a
1768 | isEsc a = return $ Continue 0 $ WordUnquotedEsc s
1773 | isEsc a = return $ Continue 0 $ WordUnquotedEsc s
1769 | isSep a = do
1774 | isSep a = do
1770− b <- fextract s
1775+ b <- ffinal s
1771 return $ Partial 0 $ WordQuotedSkipPost b
1776 return $ Partial 0 $ WordQuotedSkipPost b
1772 | otherwise = do
1777 | otherwise = do
1773 case toRight a of
1778 case toRight a of
@@ -1815,11 +1820,11 @@ wordWithQuotes keepQuotes tr escChar toRight isSep
1816 err = return . Error
1821 err = return . Error
1818− extract (WordQuotedSkipPre s) = fmap (Done 0) $ fextract s
1823+ extract (WordQuotedSkipPre s) = fmap (Done 0) $ ffinal s
1819− extract (WordUnquotedWord s) = fmap (Done 0) $ fextract s
1824+ extract (WordUnquotedWord s) = fmap (Done 0) $ ffinal s
1820 extract (WordQuotedWord s n _ _) =
1825 extract (WordQuotedWord s n _ _) =
1821 if n == 0
1826 if n == 0
1822− then fmap (Done 0) $ fextract s
1827+ then fmap (Done 0) $ ffinal s
1823 else err "wordWithQuotes: missing frame end"
1828 else err "wordWithQuotes: missing frame end"
1824 extract WordQuotedEsc {} =
1829 extract WordQuotedEsc {} =
1825 err "wordWithQuotes: trailing escape"
1830 err "wordWithQuotes: trailing escape"
@@ -1897,7 +1902,7 @@ data GroupByState a s
1898{-# INLINE groupBy #-}
1903{-# INLINE groupBy #-}
1899groupBy :: Monad m => (a -> a -> Bool) -> Fold m a b -> Parser a m b
1904groupBy :: Monad m => (a -> a -> Bool) -> Fold m a b -> Parser a m b
1900−groupBy eq (Fold fstep finitial fextract) = Parser step initial extract
1905+groupBy eq (Fold fstep finitial _ ffinal) = Parser step initial extract
@@ -1920,10 +1925,10 @@ groupBy eq (Fold fstep finitial fextract) = Parser step initial extract
1920 step (GroupByGrouping a0 s) a =
1925 step (GroupByGrouping a0 s) a =
1921 if eq a0 a
1926 if eq a0 a
1922 then grouper s a0 a
1927 then grouper s a0 a
1923− else Done 1 <$> fextract s
1928+ else Done 1 <$> ffinal s
1925− extract (GroupByInit s) = fmap (Done 0) $ fextract s
1930+ extract (GroupByInit s) = fmap (Done 0) $ ffinal s
1926− extract (GroupByGrouping _ s) = fmap (Done 0) $ fextract s
1931+ extract (GroupByGrouping _ s) = fmap (Done 0) $ ffinal s
1928-- | Unlike 'groupBy' this combinator performs a rolling comparison of two
1933-- | Unlike 'groupBy' this combinator performs a rolling comparison of two
1929-- successive elements in the input stream. Assuming the input stream
1934-- successive elements in the input stream. Assuming the input stream
@@ -1957,7 +1962,7 @@ groupBy eq (Fold fstep finitial fextract) = Parser step initial extract
1958{-# INLINE groupByRolling #-}
1963{-# INLINE groupByRolling #-}
1959groupByRolling :: Monad m => (a -> a -> Bool) -> Fold m a b -> Parser a m b
1964groupByRolling :: Monad m => (a -> a -> Bool) -> Fold m a b -> Parser a m b
1960−groupByRolling eq (Fold fstep finitial fextract) = Parser step initial extract
1965+groupByRolling eq (Fold fstep finitial _ ffinal) = Parser step initial extract
@@ -1980,10 +1985,10 @@ groupByRolling eq (Fold fstep finitial fextract) = Parser step initial extract
1980 step (GroupByGrouping a0 s) a =
1985 step (GroupByGrouping a0 s) a =
1981 if eq a0 a
1986 if eq a0 a
1982 then grouper s a
1987 then grouper s a
1983− else Done 1 <$> fextract s
1988+ else Done 1 <$> ffinal s
1985− extract (GroupByInit s) = fmap (Done 0) $ fextract s
1990+ extract (GroupByInit s) = fmap (Done 0) $ ffinal s
1986− extract (GroupByGrouping _ s) = fmap (Done 0) $ fextract s
1991+ extract (GroupByGrouping _ s) = fmap (Done 0) $ ffinal s
1988{-# ANN type GroupByStatePair Fuse #-}
1993{-# ANN type GroupByStatePair Fuse #-}
1989data GroupByStatePair a s1 s2
1994data GroupByStatePair a s1 s2
@@ -2007,8 +2012,8 @@ groupByRollingEither :: Monad m =>
2007 (a -> a -> Bool) -> Fold m a b -> Fold m a c -> Parser a m (Either b c)
2012 (a -> a -> Bool) -> Fold m a b -> Fold m a c -> Parser a m (Either b c)
2008groupByRollingEither
2013groupByRollingEither
2010− (Fold fstep1 finitial1 fextract1)
2015+ (Fold fstep1 finitial1 _ ffinal1)
2011− (Fold fstep2 finitial2 fextract2) = Parser step initial extract
2016+ (Fold fstep2 finitial2 _ ffinal2) = Parser step initial extract
@@ -2067,21 +2072,21 @@ groupByRollingEither
2067 step (GroupByGroupingPairL a0 s1 s2) a =
2072 step (GroupByGroupingPairL a0 s1 s2) a =
2068 if not (eq a0 a)
2073 if not (eq a0 a)
2069 then grouperL2 s1 s2 a
2074 then grouperL2 s1 s2 a
2070− else Done 1 . Left <$> fextract1 s1
2075+ else Done 1 . Left <$> ffinal1 s1
2072 step (GroupByGroupingPairR a0 s1 s2) a =
2077 step (GroupByGroupingPairR a0 s1 s2) a =
2073 if eq a0 a
2078 if eq a0 a
2074 then grouperR2 s1 s2 a
2079 then grouperR2 s1 s2 a
2075− else Done 1 . Right <$> fextract2 s2
2080+ else Done 1 . Right <$> ffinal2 s2
2077− extract (GroupByInitPair s1 _) = Done 0 . Left <$> fextract1 s1
2082+ extract (GroupByInitPair s1 _) = Done 0 . Left <$> ffinal1 s1
2078− extract (GroupByGroupingPairL _ s1 _) = Done 0 . Left <$> fextract1 s1
2083+ extract (GroupByGroupingPairL _ s1 _) = Done 0 . Left <$> ffinal1 s1
2079− extract (GroupByGroupingPairR _ _ s2) = Done 0 . Right <$> fextract2 s2
2084+ extract (GroupByGroupingPairR _ _ s2) = Done 0 . Right <$> ffinal2 s2
2080 extract (GroupByGroupingPair a s1 _) = do
2085 extract (GroupByGroupingPair a s1 _) = do
2081 res <- fstep1 s1 a
2086 res <- fstep1 s1 a
2082 case res of
2087 case res of
2083 FL.Done b -> return $ Done 0 (Left b)
2088 FL.Done b -> return $ Done 0 (Left b)
2084− FL.Partial s11 -> Done 0 . Left <$> fextract1 s11
2089+ FL.Partial s11 -> Done 0 . Left <$> ffinal1 s11
2086-- XXX use an Unfold instead of a list?
2091-- XXX use an Unfold instead of a list?
2087-- XXX custom combinators for matching list, array and stream?
2092-- XXX custom combinators for matching list, array and stream?
@@ -2234,7 +2239,7 @@ postscan = undefined
2234{-# INLINE zipWithM #-}
2239{-# INLINE zipWithM #-}
2235zipWithM :: Monad m =>
2240zipWithM :: Monad m =>
2236 (a -> b -> m c) -> D.Stream m a -> Fold m c x -> Parser b m x
2241 (a -> b -> m c) -> D.Stream m a -> Fold m c x -> Parser b m x
2237−zipWithM zf (D.Stream sstep state) (Fold fstep finitial fextract) =
2242+zipWithM zf (D.Stream sstep state) (Fold fstep finitial _ ffinal) =
2238 Parser step initial extract
2243 Parser step initial extract
@@ -2247,7 +2252,7 @@ zipWithM zf (D.Stream sstep state) (Fold fstep finitial fextract) =
2247 case r of
2252 case r of
2248 D.Yield x s -> return $ IPartial (Just' x, s, fs)
2253 D.Yield x s -> return $ IPartial (Just' x, s, fs)
2249 D.Stop -> do
2254 D.Stop -> do
2250− x <- fextract fs
2255+ x <- ffinal fs
2251 return $ IDone x
2256 return $ IDone x
2252 -- Need Skip/Continue in initial to loop right here
2257 -- Need Skip/Continue in initial to loop right here
2253 D.Skip s -> return $ IPartial (Nothing', s, fs)
2258 D.Skip s -> return $ IPartial (Nothing', s, fs)
@@ -2262,7 +2267,7 @@ zipWithM zf (D.Stream sstep state) (Fold fstep finitial fextract) =
2262 case r of
2267 case r of
2263 D.Yield x1 s -> return $ Continue 0 (Just' x1, s, fs1)
2268 D.Yield x1 s -> return $ Continue 0 (Just' x1, s, fs1)
2264 D.Stop -> do
2269 D.Stop -> do
2265− x <- fextract fs1
2270+ x <- ffinal fs1
2266 return $ Done 0 x
2271 return $ Done 0 x
2267 D.Skip s -> return $ Continue 1 (Nothing', s, fs1)
2272 D.Skip s -> return $ Continue 1 (Nothing', s, fs1)
2268 FL.Done x -> return $ Done 0 x
2273 FL.Done x -> return $ Done 0 x
@@ -2277,7 +2282,7 @@ zipWithM zf (D.Stream sstep state) (Fold fstep finitial fextract) =
2277 return $ Continue 0 (Nothing', s, fs1)
2282 return $ Continue 0 (Nothing', s, fs1)
2278 FL.Done x -> return $ Done 0 x
2283 FL.Done x -> return $ Done 0 x
2279 D.Stop -> do
2284 D.Stop -> do
2280− x <- fextract fs
2285+ x <- ffinal fs
2281 return $ Done 1 x
2286 return $ Done 1 x
2282 D.Skip s -> return $ Continue 1 (Nothing', s, fs)
2287 D.Skip s -> return $ Continue 1 (Nothing', s, fs)
@@ -2561,7 +2566,7 @@ deintercalateAll :: Monad m =>
2561deintercalateAll
2566deintercalateAll
2562 (Parser stepL initialL extractL)
2567 (Parser stepL initialL extractL)
2563 (Parser stepR initialR _)
2568 (Parser stepR initialR _)
2564− (Fold fstep finitial fextract) = Parser step initial extract
2569+ (Fold fstep finitial _ ffinal) = Parser step initial extract
@@ -2632,9 +2637,9 @@ deintercalateAll
2632 extractResult n fs r = do
2637 extractResult n fs r = do
2633 res <- fstep fs r
2638 res <- fstep fs r
2634 case res of
2639 case res of
2635− FL.Partial fs1 -> fmap (Done n) $ fextract fs1
2640+ FL.Partial fs1 -> fmap (Done n) $ ffinal fs1
2636 FL.Done c -> return (Done n c)
2641 FL.Done c -> return (Done n c)
2637− extract (DeintercalateAllInitL fs) = fmap (Done 0) $ fextract fs
2642+ extract (DeintercalateAllInitL fs) = fmap (Done 0) $ ffinal fs
2638 extract (DeintercalateAllL fs sL) = do
2643 extract (DeintercalateAllL fs sL) = do
2639 r <- extractL sL
2644 r <- extractL sL
2640 case r of
2645 case r of
@@ -2642,7 +2647,7 @@ deintercalateAll
2642 Error err -> return $ Error err
2647 Error err -> return $ Error err
2643 Continue n s -> return $ Continue n (DeintercalateAllL fs s)
2648 Continue n s -> return $ Continue n (DeintercalateAllL fs s)
2644 Partial _ _ -> error "Partial in extract"
2649 Partial _ _ -> error "Partial in extract"
2645− extract (DeintercalateAllInitR fs) = fmap (Done 0) $ fextract fs
2650+ extract (DeintercalateAllInitR fs) = fmap (Done 0) $ ffinal fs
2646 extract (DeintercalateAllR _ _) =
2651 extract (DeintercalateAllR _ _) =
2647 return $ Error "deintercalateAll: input ended at 'Right' value"
2652 return $ Error "deintercalateAll: input ended at 'Right' value"
@@ -2685,7 +2690,7 @@ deintercalate :: Monad m =>
2685deintercalate
2690deintercalate
2686 (Parser stepL initialL extractL)
2691 (Parser stepL initialL extractL)
2687 (Parser stepR initialR _)
2692 (Parser stepR initialR _)
2688− (Fold fstep finitial fextract) = Parser step initial extract
2693+ (Fold fstep finitial _ ffinal) = Parser step initial extract
@@ -2716,7 +2721,7 @@ deintercalate
2716 Done n b ->
2721 Done n b ->
2717 processL (fstep fs (Left b)) n DeintercalateInitR
2722 processL (fstep fs (Left b)) n DeintercalateInitR
2718 Error _ -> do
2723 Error _ -> do
2719− xs <- fextract fs
2724+ xs <- ffinal fs
2720 return $ Done cnt1 xs
2725 return $ Done cnt1 xs
2722 {-# INLINE processR #-}
2727 {-# INLINE processR #-}
@@ -2736,7 +2741,7 @@ deintercalate
2736 Continue n s -> return $ Continue n (DeintercalateR (cnt1 - n) fs s)
2741 Continue n s -> return $ Continue n (DeintercalateR (cnt1 - n) fs s)
2737 Done n b -> processR (cnt1 - n) b fs n
2742 Done n b -> processR (cnt1 - n) b fs n
2738 Error _ -> do
2743 Error _ -> do
2739− xs <- fextract fs
2744+ xs <- ffinal fs
2740 return $ Done cnt1 xs
2745 return $ Done cnt1 xs
2742 step (DeintercalateInitL fs) a = do
2747 step (DeintercalateInitL fs) a = do
@@ -2771,17 +2776,17 @@ deintercalate
2771 -- XXX We could have the fold accept pairs of (bR, bL)
2776 -- XXX We could have the fold accept pairs of (bR, bL)
2772 FL.Done _ -> error "Fold terminated consuming partial input"
2777 FL.Done _ -> error "Fold terminated consuming partial input"
2773 Error _ -> do
2778 Error _ -> do
2774− xs <- fextract fs
2779+ xs <- ffinal fs
2775 return $ Done cnt1 xs
2780 return $ Done cnt1 xs
2777 {-# INLINE extractResult #-}
2782 {-# INLINE extractResult #-}
2778 extractResult n fs r = do
2783 extractResult n fs r = do
2779 res <- fstep fs r
2784 res <- fstep fs r
2780 case res of
2785 case res of
2781− FL.Partial fs1 -> fmap (Done n) $ fextract fs1
2786+ FL.Partial fs1 -> fmap (Done n) $ ffinal fs1
2782 FL.Done c -> return (Done n c)
2787 FL.Done c -> return (Done n c)
2784− extract (DeintercalateInitL fs) = fmap (Done 0) $ fextract fs
2789+ extract (DeintercalateInitL fs) = fmap (Done 0) $ ffinal fs
2785 extract (DeintercalateL cnt fs sL) = do
2790 extract (DeintercalateL cnt fs sL) = do
2786 r <- extractL sL
2791 r <- extractL sL
2787 case r of
2792 case r of
@@ -2789,10 +2794,10 @@ deintercalate
2789 Continue n s -> return $ Continue n (DeintercalateL (cnt - n) fs s)
2794 Continue n s -> return $ Continue n (DeintercalateL (cnt - n) fs s)
2790 Partial _ _ -> error "Partial in extract"
2795 Partial _ _ -> error "Partial in extract"
2791 Error _ -> do
2796 Error _ -> do
2792− xs <- fextract fs
2797+ xs <- ffinal fs
2793 return $ Done cnt xs
2798 return $ Done cnt xs
2794− extract (DeintercalateInitR fs) = fmap (Done 0) $ fextract fs
2799+ extract (DeintercalateInitR fs) = fmap (Done 0) $ ffinal fs
2795− extract (DeintercalateR cnt fs _) = fmap (Done cnt) $ fextract fs
2800+ extract (DeintercalateR cnt fs _) = fmap (Done cnt) $ ffinal fs
2796 extract (DeintercalateRL cnt bR fs sL) = do
2801 extract (DeintercalateRL cnt bR fs sL) = do
2797 r <- extractL sL
2802 r <- extractL sL
2798 case r of
2803 case r of
@@ -2804,7 +2809,7 @@ deintercalate
2804 Continue n s -> return $ Continue n (DeintercalateRL (cnt - n) bR fs s)
2809 Continue n s -> return $ Continue n (DeintercalateRL (cnt - n) bR fs s)
2805 Partial _ _ -> error "Partial in extract"
2810 Partial _ _ -> error "Partial in extract"
2806 Error _ -> do
2811 Error _ -> do
2807− xs <- fextract fs
2812+ xs <- ffinal fs
2808 return $ Done cnt xs
2813 return $ Done cnt xs
2810{-# ANN type Deintercalate1State Fuse #-}
2815{-# ANN type Deintercalate1State Fuse #-}
@@ -2841,7 +2846,7 @@ deintercalate1 :: Monad m =>
2841deintercalate1
2846deintercalate1
2842 (Parser stepL initialL extractL)
2847 (Parser stepL initialL extractL)
2843 (Parser stepR initialR _)
2848 (Parser stepR initialR _)
2844− (Fold fstep finitial fextract) = Parser step initial extract
2849+ (Fold fstep finitial _ ffinal) = Parser step initial extract
@@ -2895,7 +2900,7 @@ deintercalate1
2895 Continue n s -> return $ Continue n (Deintercalate1R (cnt1 - n) fs s)
2900 Continue n s -> return $ Continue n (Deintercalate1R (cnt1 - n) fs s)
2896 Done n b -> processR (cnt1 - n) b fs n
2901 Done n b -> processR (cnt1 - n) b fs n
2897 Error _ -> do
2902 Error _ -> do
2898− xs <- fextract fs
2903+ xs <- ffinal fs
2899 return $ Done cnt1 xs
2904 return $ Done cnt1 xs
2901 step (Deintercalate1InitL cnt fs sL) a = runStepInitL cnt fs sL a
2906 step (Deintercalate1InitL cnt fs sL) a = runStepInitL cnt fs sL a
@@ -2924,14 +2929,14 @@ deintercalate1
2924 -- XXX We could have the fold accept pairs of (bR, bL)
2929 -- XXX We could have the fold accept pairs of (bR, bL)
2925 FL.Done _ -> error "Fold terminated consuming partial input"
2930 FL.Done _ -> error "Fold terminated consuming partial input"
2926 Error _ -> do
2931 Error _ -> do
2927− xs <- fextract fs
2932+ xs <- ffinal fs
2928 return $ Done cnt1 xs
2933 return $ Done cnt1 xs
2930 {-# INLINE extractResult #-}
2935 {-# INLINE extractResult #-}
2931 extractResult n fs r = do
2936 extractResult n fs r = do
2932 res <- fstep fs r
2937 res <- fstep fs r
2933 case res of
2938 case res of
2934− FL.Partial fs1 -> fmap (Done n) $ fextract fs1
2939+ FL.Partial fs1 -> fmap (Done n) $ ffinal fs1
2935 FL.Done c -> return (Done n c)
2940 FL.Done c -> return (Done n c)
2937 extract (Deintercalate1InitL cnt fs sL) = do
2942 extract (Deintercalate1InitL cnt fs sL) = do
@@ -2941,8 +2946,8 @@ deintercalate1
2941 Continue n s -> return $ Continue n (Deintercalate1InitL (cnt - n) fs s)
2946 Continue n s -> return $ Continue n (Deintercalate1InitL (cnt - n) fs s)
2942 Partial _ _ -> error "Partial in extract"
2947 Partial _ _ -> error "Partial in extract"
2943 Error err -> return $ Error err
2948 Error err -> return $ Error err
2944− extract (Deintercalate1InitR fs) = fmap (Done 0) $ fextract fs
2949+ extract (Deintercalate1InitR fs) = fmap (Done 0) $ ffinal fs
2945− extract (Deintercalate1R cnt fs _) = fmap (Done cnt) $ fextract fs
2950+ extract (Deintercalate1R cnt fs _) = fmap (Done cnt) $ ffinal fs
2946 extract (Deintercalate1RL cnt bR fs sL) = do
2951 extract (Deintercalate1RL cnt bR fs sL) = do
2947 r <- extractL sL
2952 r <- extractL sL
2948 case r of
2953 case r of
@@ -2954,7 +2959,7 @@ deintercalate1
2954 Continue n s -> return $ Continue n (Deintercalate1RL (cnt - n) bR fs s)
2959 Continue n s -> return $ Continue n (Deintercalate1RL (cnt - n) bR fs s)
2955 Partial _ _ -> error "Partial in extract"
2960 Partial _ _ -> error "Partial in extract"
2956 Error _ -> do
2961 Error _ -> do
2957− xs <- fextract fs
2962+ xs <- ffinal fs
2958 return $ Done cnt xs
2963 return $ Done cnt xs
2960{-# ANN type SepByState Fuse #-}
2965{-# ANN type SepByState Fuse #-}
@@ -2997,7 +3002,7 @@ sepBy :: Monad m =>
2998 (Parser stepL initialL extractL)
3003 (Parser stepL initialL extractL)
2999 (Parser stepR initialR _)
3004 (Parser stepR initialR _)
3000− (Fold fstep finitial fextract) = Parser step initial extract
3005+ (Fold fstep finitial _ ffinal) = Parser step initial extract
@@ -3028,7 +3033,7 @@ sepBy
3028 Done n b ->
3033 Done n b ->
3029 processL (fstep fs b) n SepByInitR
3034 processL (fstep fs b) n SepByInitR
3030 Error _ -> do
3035 Error _ -> do
3031− xs <- fextract fs
3036+ xs <- ffinal fs
3032 return $ Done cnt1 xs
3037 return $ Done cnt1 xs
3034 {-# INLINE processR #-}
3039 {-# INLINE processR #-}
@@ -3048,7 +3053,7 @@ sepBy
3048 Continue n s -> return $ Continue n (SepByR (cnt1 - n) fs s)
3053 Continue n s -> return $ Continue n (SepByR (cnt1 - n) fs s)
3049 Done n _ -> processR (cnt1 - n) fs n
3054 Done n _ -> processR (cnt1 - n) fs n
3050 Error _ -> do
3055 Error _ -> do
3051− xs <- fextract fs
3056+ xs <- ffinal fs
3052 return $ Done cnt1 xs
3057 return $ Done cnt1 xs
3054 step (SepByInitL fs) a = do
3059 step (SepByInitL fs) a = do
@@ -3070,10 +3075,10 @@ sepBy
3070 extractResult n fs r = do
3075 extractResult n fs r = do
3071 res <- fstep fs r
3076 res <- fstep fs r
3072 case res of
3077 case res of
3073− FL.Partial fs1 -> fmap (Done n) $ fextract fs1
3078+ FL.Partial fs1 -> fmap (Done n) $ ffinal fs1
3074 FL.Done c -> return (Done n c)
3079 FL.Done c -> return (Done n c)
3076− extract (SepByInitL fs) = fmap (Done 0) $ fextract fs
3081+ extract (SepByInitL fs) = fmap (Done 0) $ ffinal fs
3077 extract (SepByL cnt fs sL) = do
3082 extract (SepByL cnt fs sL) = do
3078 r <- extractL sL
3083 r <- extractL sL
3079 case r of
3084 case r of
@@ -3081,10 +3086,10 @@ sepBy
3081 Continue n s -> return $ Continue n (SepByL (cnt - n) fs s)
3086 Continue n s -> return $ Continue n (SepByL (cnt - n) fs s)
3082 Partial _ _ -> error "Partial in extract"
3087 Partial _ _ -> error "Partial in extract"
3083 Error _ -> do
3088 Error _ -> do
3084− xs <- fextract fs
3089+ xs <- ffinal fs
3085 return $ Done cnt xs
3090 return $ Done cnt xs
3086− extract (SepByInitR fs) = fmap (Done 0) $ fextract fs
3091+ extract (SepByInitR fs) = fmap (Done 0) $ ffinal fs
3087− extract (SepByR cnt fs _) = fmap (Done cnt) $ fextract fs
3092+ extract (SepByR cnt fs _) = fmap (Done cnt) $ ffinal fs
3089-- | Non-backtracking version of sepBy. Several times faster.
3094-- | Non-backtracking version of sepBy. Several times faster.
3090{-# INLINE sepByAll #-}
3095{-# INLINE sepByAll #-}
@@ -3139,7 +3144,7 @@ sepBy1 :: Monad m =>
3140 (Parser stepL initialL extractL)
3145 (Parser stepL initialL extractL)
3141 (Parser stepR initialR _)
3146 (Parser stepR initialR _)
3142− (Fold fstep finitial fextract) = Parser step initial extract
3147+ (Fold fstep finitial _ ffinal) = Parser step initial extract
@@ -3186,7 +3191,7 @@ sepBy1
3186 Done n b ->
3191 Done n b ->
3187 processL (fstep fs b) n SepBy1InitR
3192 processL (fstep fs b) n SepBy1InitR
3188 Error _ -> do
3193 Error _ -> do
3189− xs <- fextract fs
3194+ xs <- ffinal fs
3190 return $ Done cnt1 xs
3195 return $ Done cnt1 xs
3192 {-# INLINE processR #-}
3197 {-# INLINE processR #-}
@@ -3206,7 +3211,7 @@ sepBy1
3206 Continue n s -> return $ Continue n (SepBy1R (cnt1 - n) fs s)
3211 Continue n s -> return $ Continue n (SepBy1R (cnt1 - n) fs s)
3207 Done n _ -> processR (cnt1 - n) fs n
3212 Done n _ -> processR (cnt1 - n) fs n
3208 Error _ -> do
3213 Error _ -> do
3209− xs <- fextract fs
3214+ xs <- ffinal fs
3210 return $ Done cnt1 xs
3215 return $ Done cnt1 xs
3212 step (SepBy1InitL cnt fs sL) a = runStepInitL cnt fs sL a
3217 step (SepBy1InitL cnt fs sL) a = runStepInitL cnt fs sL a
@@ -3223,7 +3228,7 @@ sepBy1
3223 extractResult n fs r = do
3228 extractResult n fs r = do
3224 res <- fstep fs r
3229 res <- fstep fs r
3225 case res of
3230 case res of
3226− FL.Partial fs1 -> fmap (Done n) $ fextract fs1
3231+ FL.Partial fs1 -> fmap (Done n) $ ffinal fs1
3227 FL.Done c -> return (Done n c)
3232 FL.Done c -> return (Done n c)
3229 extract (SepBy1InitL cnt fs sL) = do
3234 extract (SepBy1InitL cnt fs sL) = do
@@ -3240,10 +3245,10 @@ sepBy1
3240 Continue n s -> return $ Continue n (SepBy1L (cnt - n) fs s)
3245 Continue n s -> return $ Continue n (SepBy1L (cnt - n) fs s)
3241 Partial _ _ -> error "Partial in extract"
3246 Partial _ _ -> error "Partial in extract"
3242 Error _ -> do
3247 Error _ -> do
3243− xs <- fextract fs
3248+ xs <- ffinal fs
3244 return $ Done cnt xs
3249 return $ Done cnt xs
3245− extract (SepBy1InitR fs) = fmap (Done 0) $ fextract fs
3250+ extract (SepBy1InitR fs) = fmap (Done 0) $ ffinal fs
3246− extract (SepBy1R cnt fs _) = fmap (Done cnt) $ fextract fs
3251+ extract (SepBy1R cnt fs _) = fmap (Done cnt) $ ffinal fs
3248-------------------------------------------------------------------------------
3253-------------------------------------------------------------------------------
3249-- Interleaving a collection of parsers
3254-- Interleaving a collection of parsers
@@ -3273,7 +3278,7 @@ roundRobin _ps _f = undefined
3273{-# INLINE sequence #-}
3278{-# INLINE sequence #-}
3274sequence :: Monad m =>
3279sequence :: Monad m =>
3275 D.Stream m (Parser a m b) -> Fold m b c -> Parser a m c
3280 D.Stream m (Parser a m b) -> Fold m b c -> Parser a m c
3276−sequence (D.Stream sstep sstate) (Fold fstep finitial fextract) =
3281+sequence (D.Stream sstep sstate) (Fold fstep finitial _ ffinal) =
3277 Parser step initial extract
3282 Parser step initial extract
@@ -3291,7 +3296,7 @@ sequence (D.Stream sstep sstate) (Fold fstep finitial fextract) =
3291 case sres of
3296 case sres of
3292 D.Yield p ss1 -> return $ Continue 1 (Just' p, ss1, fs)
3297 D.Yield p ss1 -> return $ Continue 1 (Just' p, ss1, fs)
3293 D.Stop -> do
3298 D.Stop -> do
3294− c <- fextract fs
3299+ c <- ffinal fs
3295 return $ Done 1 c
3300 return $ Done 1 c
3296 D.Skip ss1 -> return $ Continue 1 (Nothing', ss1, fs)
3301 D.Skip ss1 -> return $ Continue 1 (Nothing', ss1, fs)
@@ -3327,7 +3332,7 @@ sequence (D.Stream sstep sstate) (Fold fstep finitial fextract) =
3327 FL.Done c -> return $ Done 1 c
3332 FL.Done c -> return $ Done 1 c
3328 IError err -> return $ Error err
3333 IError err -> return $ Error err
3330− extract (Nothing', _, fs) = fmap (Done 0) $ fextract fs
3335+ extract (Nothing', _, fs) = fmap (Done 0) $ ffinal fs
3331 extract (Just' (Parser pstep pinit pextr), ss, fs) = do
3336 extract (Just' (Parser pstep pinit pextr), ss, fs) = do
3332 ps <- pinit
3337 ps <- pinit
3333 case ps of
3338 case ps of
@@ -3337,7 +3342,7 @@ sequence (D.Stream sstep sstate) (Fold fstep finitial fextract) =
3337 Done n b -> do
3342 Done n b -> do
3338 res <- fstep fs b
3343 res <- fstep fs b
3339 case res of
3344 case res of
3340− FL.Partial fs1 -> fmap (Done n) $ fextract fs1
3345+ FL.Partial fs1 -> fmap (Done n) $ ffinal fs1
3341 FL.Done c -> return (Done n c)
3346 FL.Done c -> return (Done n c)
3342 Error err -> return $ Error err
3347 Error err -> return $ Error err
3343 Continue n s -> return $ Continue n (Just' (Parser pstep (return (IPartial s)) pextr), ss, fs)
3348 Continue n s -> return $ Continue n (Just' (Parser pstep (return (IPartial s)) pextr), ss, fs)
@@ -3345,7 +3350,7 @@ sequence (D.Stream sstep sstate) (Fold fstep finitial fextract) =
3345 IDone b -> do
3350 IDone b -> do
3346 fres <- fstep fs b
3351 fres <- fstep fs b
3347 case fres of
3352 case fres of
3348− FL.Partial fs1 -> fmap (Done 0) $ fextract fs1
3353+ FL.Partial fs1 -> fmap (Done 0) $ ffinal fs1
3349 FL.Done c -> return (Done 0 c)
3354 FL.Done c -> return (Done 0 c)
3350 IError err -> return $ Error err
3355 IError err -> return $ Error err
@@ -3480,7 +3485,7 @@ manyTill :: Monad m
3480 => Parser a m b -> Parser a m x -> Fold m b c -> Parser a m c
3485 => Parser a m b -> Parser a m x -> Fold m b c -> Parser a m c
3481manyTill (Parser stepL initialL extractL)
3486manyTill (Parser stepL initialL extractL)
3482 (Parser stepR initialR _)
3487 (Parser stepR initialR _)
3483− (Fold fstep finitial fextract) =
3488+ (Fold fstep finitial _ ffinal) =
3484 Parser step initial extract
3489 Parser step initial extract
@@ -3502,7 +3507,7 @@ manyTill (Parser stepL initialL extractL)
3502 resR <- initialR
3507 resR <- initialR
3503 case resR of
3508 case resR of
3504 IPartial sr -> return $ p (ManyTillR 0 fs sr)
3509 IPartial sr -> return $ p (ManyTillR 0 fs sr)
3505− IDone _ -> d <$> fextract fs
3510+ IDone _ -> d <$> ffinal fs
3506 IError _ -> scrutL fs p c d e
3511 IError _ -> scrutL fs p c d e
3508 initial = do
3513 initial = do
@@ -3519,7 +3524,7 @@ manyTill (Parser stepL initialL extractL)
3519 assertM(cnt + 1 - n >= 0)
3524 assertM(cnt + 1 - n >= 0)
3520 return $ Continue n (ManyTillR (cnt + 1 - n) fs s)
3525 return $ Continue n (ManyTillR (cnt + 1 - n) fs s)
3521 Done n _ -> do
3526 Done n _ -> do
3522− b <- fextract fs
3527+ b <- ffinal fs
3523 return $ Done n b
3528 return $ Done n b
3524 Error _ -> do
3529 Error _ -> do
3525 resL <- initialL
3530 resL <- initialL
@@ -3558,12 +3563,12 @@ manyTill (Parser stepL initialL extractL)
3558 Done n b -> do
3563 Done n b -> do
3559 r <- fstep fs b
3564 r <- fstep fs b
3560 case r of
3565 case r of
3561− FL.Partial fs1 -> fmap (Done n) $ fextract fs1
3566+ FL.Partial fs1 -> fmap (Done n) $ ffinal fs1
3562 FL.Done c -> return (Done n c)
3567 FL.Done c -> return (Done n c)
3563 Error err -> return $ Error err
3568 Error err -> return $ Error err
3564 Continue n s -> return $ Continue n (ManyTillL fs s)
3569 Continue n s -> return $ Continue n (ManyTillL fs s)
3565 Partial _ _ -> error "Partial in extract"
3570 Partial _ _ -> error "Partial in extract"
3566− extract (ManyTillR _ fs _) = fmap (Done 0) $ fextract fs
3571+ extract (ManyTillR _ fs _) = fmap (Done 0) $ ffinal fs
3568-- | @manyThen f collect recover@ repeats the parser @collect@ on the input and
3573-- | @manyThen f collect recover@ repeats the parser @collect@ on the input and
3569-- collects the output in the supplied fold. If the the parser @collect@ fails,
3574-- collects the output in the supplied fold. If the the parser @collect@ fails,