on master help sign in
Rename eqBy to streamEqBy in parsers
8cca012Ranjeet Kumar Ranjan
benchmark/Streamly/Benchmark/Data/Parser.hs+4−4
@@ -160,9 +160,9 @@ takeFramedByEsc_ _ = Stream.parse parser
160listEqBy :: Int -> Stream IO Int -> IO (Either ParseError [Int])
160listEqBy :: Int -> Stream IO Int -> IO (Either ParseError [Int])
161listEqBy len = Stream.parse (PR.listEqBy (==) [1 .. len])
161listEqBy len = Stream.parse (PR.listEqBy (==) [1 .. len])
162
162
163−{-# INLINE eqBy #-}
163+{-# INLINE streamEqBy #-}
164−eqBy :: Int -> Stream IO Int -> IO (Either ParseError ())
164+streamEqBy :: Int -> Stream IO Int -> IO (Either ParseError ())
165−eqBy len = Stream.parse (PR.eqBy (==) (Stream.enumerateFromTo 1 len))
165+streamEqBy len = Stream.parse (PR.streamEqBy (==) (Stream.enumerateFromTo 1 len))
166
166
167{-# INLINE takeWhile #-}
167{-# INLINE takeWhile #-}
168takeWhile :: Monad m => Int -> Stream m Int -> m (Either ParseError ())
168takeWhile :: Monad m => Int -> Stream m Int -> m (Either ParseError ())
@@ -492,7 +492,7 @@ o_1_space_serial value =
492 , benchIOSink value "parseMany (groupBy (<))" (parseManyGroupBy (<))
492 , benchIOSink value "parseMany (groupBy (<))" (parseManyGroupBy (<))
493 , benchIOSink value "parseMany (groupBy (==))" (parseManyGroupBy (==))
493 , benchIOSink value "parseMany (groupBy (==))" (parseManyGroupBy (==))
494 , benchIOSink value "listEqBy" (listEqBy value)
494 , benchIOSink value "listEqBy" (listEqBy value)
495− , benchIOSink value "eqBy" (eqBy value)
495+ , benchIOSink value "streamEqBy" (streamEqBy value)
496 ]
496 ]
497
497
498o_1_space_filesystem :: BenchEnv -> [Benchmark]
498o_1_space_filesystem :: BenchEnv -> [Benchmark]
benchmark/Streamly/Benchmark/Data/Parser/ParserD.hs+4−4
@@ -73,9 +73,9 @@ benchIOSink value name f =
73listEqBy :: Int -> Stream IO Int -> IO (Either ParseError [Int])
73listEqBy :: Int -> Stream IO Int -> IO (Either ParseError [Int])
74listEqBy len = Stream.parseD (PR.listEqBy (==) [1 .. len])
74listEqBy len = Stream.parseD (PR.listEqBy (==) [1 .. len])
75
75
76−{-# INLINE eqBy #-}
76+{-# INLINE streamEqBy #-}
77−eqBy :: Int -> Stream IO Int -> IO (Either ParseError ())
77+streamEqBy :: Int -> Stream IO Int -> IO (Either ParseError ())
78−eqBy len = Stream.parseD (PR.eqBy (==) (D.enumerateFromToIntegral 1 len))
78+streamEqBy len = Stream.parseD (PR.streamEqBy (==) (D.enumerateFromToIntegral 1 len))
79
79
80{-# INLINE drainWhile #-}
80{-# INLINE drainWhile #-}
81drainWhile :: Monad m => (a -> Bool) -> PR.Parser a m ()
81drainWhile :: Monad m => (a -> Bool) -> PR.Parser a m ()
@@ -367,7 +367,7 @@ o_1_space_serial value =
367 -}
367 -}
368 , benchIOSink value "sequenceParser" sequenceParser
368 , benchIOSink value "sequenceParser" sequenceParser
369 , benchIOSink value "listEqBy" (listEqBy value)
369 , benchIOSink value "listEqBy" (listEqBy value)
370− , benchIOSink value "eqBy" (eqBy value)
370+ , benchIOSink value "streamEqBy" (streamEqBy value)
371 ]
371 ]
372
372
373o_1_space_serial_spanning :: Int -> [Benchmark]
373o_1_space_serial_spanning :: Int -> [Benchmark]
core/src/Streamly/Data/Parser.hs+1−1
@@ -51,7 +51,7 @@ module Streamly.Data.Parser
51 -- , either
51 -- , either
52
52
53 -- ** Sequences
53 -- ** Sequences
54− , eqBy
54+ , streamEqBy
55 , listEqBy
55 , listEqBy
56 , listEq
56 , listEq
57
57
core/src/Streamly/Internal/Data/Parser.hs+8−12
@@ -104,7 +104,7 @@ module Streamly.Internal.Data.Parser
104 -- ** Exact match
104 -- ** Exact match
105 , listEq
105 , listEq
106 , listEqBy
106 , listEqBy
107− , eqBy
107+ , streamEqBy
108 , subsequenceBy
108 , subsequenceBy
109
109
110 -- ** By predicate
110 -- ** By predicate
@@ -1000,25 +1000,21 @@ groupByRollingEither :: Monad m =>
1000 (a -> a -> Bool) -> Fold m a b -> Fold m a c -> Parser a m (Either b c)
1000 (a -> a -> Bool) -> Fold m a b -> Fold m a c -> Parser a m (Either b c)
1001groupByRollingEither eq f1 = D.toParserK . D.groupByRollingEither eq f1
1001groupByRollingEither eq f1 = D.toParserK . D.groupByRollingEither eq f1
1002
1002
1003−-- XXX eqBy is not a good name because we are not matching the entire stream
1004−-- unlike the eqBy in Stream module. matchStreamBy, matchStream, matchListBy,
1005−-- matchList.
1006−
1007-- | Like 'listEqBy' but uses a stream instead of a list and does not return
1003-- | Like 'listEqBy' but uses a stream instead of a list and does not return
1008-- the stream.
1004-- the stream.
1009--
1005--
1010−-- See also: "Streamly.Data.Stream.eqBy"
1006+-- See also: "Streamly.Data.Stream.streamEqBy"
1011--
1007--
1012−{-# INLINE eqBy #-}
1008+{-# INLINE streamEqBy #-}
1013−eqBy :: Monad m => (a -> a -> Bool) -> Stream m a -> Parser a m ()
1009+streamEqBy :: Monad m => (a -> a -> Bool) -> Stream m a -> Parser a m ()
1014−eqBy cmp = D.toParserK . D.eqBy cmp . Stream.toStreamD
1010+streamEqBy cmp = D.toParserK . D.streamEqBy cmp . Stream.toStreamD
1015
1011
1016-- | Match the given sequence of elements using the given comparison function.
1012-- | Match the given sequence of elements using the given comparison function.
1017-- Returns the original sequence if successful.
1013-- Returns the original sequence if successful.
1018--
1014--
1019-- Definition:
1015-- Definition:
1020--
1016--
1021−-- >>> listEqBy cmp xs = Parser.eqBy cmp (Stream.fromList xs) *> Parser.fromPure xs
1017+-- >>> listEqBy cmp xs = Parser.streamEqBy cmp (Stream.fromList xs) *> Parser.fromPure xs
1022--
1018--
1023-- Examples:
1019-- Examples:
1024--
1020--
@@ -1026,12 +1022,12 @@ eqBy cmp = D.toParserK . D.eqBy cmp . Stream.toStreamD
1026-- Right "string"
1022-- Right "string"
1027--
1023--
1028-- >>> Stream.parse (Parser.listEqBy (==) "mismatch") $ Stream.fromList "match"
1024-- >>> Stream.parse (Parser.listEqBy (==) "mismatch") $ Stream.fromList "match"
1029−-- Left (ParseError "eqBy: mismtach occurred")
1025+-- Left (ParseError "streamEqBy: mismtach occurred")
1030--
1026--
1031{-# INLINE listEqBy #-}
1027{-# INLINE listEqBy #-}
1032listEqBy :: Monad m => (a -> a -> Bool) -> [a] -> Parser a m [a]
1028listEqBy :: Monad m => (a -> a -> Bool) -> [a] -> Parser a m [a]
1033-- listEqBy cmp xs = D.toParserK (D.listEqBy cmp xs)
1029-- listEqBy cmp xs = D.toParserK (D.listEqBy cmp xs)
1034−listEqBy cmp xs = eqBy cmp (Stream.fromList xs) *> fromPure xs
1030+listEqBy cmp xs = streamEqBy cmp (Stream.fromList xs) *> fromPure xs
1035
1031
1036-- Rename to "list".
1032-- Rename to "list".
1037-- | Match the input sequence with the supplied list and return it if
1033-- | Match the input sequence with the supplied list and return it if
core/src/Streamly/Internal/Data/Parser/ParserD.hs+8−8
@@ -92,7 +92,7 @@ module Streamly.Internal.Data.Parser.ParserD
92
92
93 -- Matching strings
93 -- Matching strings
94 , listEqBy
94 , listEqBy
95− , eqBy
95+ , streamEqBy
96 -- , prefixOf -- match any prefix of a given string
96 -- , prefixOf -- match any prefix of a given string
97 -- , suffixOf -- match any suffix of a given string
97 -- , suffixOf -- match any suffix of a given string
98 -- , infixOf -- match any substring of a given string
98 -- , infixOf -- match any substring of a given string
@@ -1469,7 +1469,7 @@ groupByRollingEither
1469-- XXX custom combinators for matching list, array and stream?
1469-- XXX custom combinators for matching list, array and stream?
1470-- XXX rename to listBy?
1470-- XXX rename to listBy?
1471--
1471--
1472−-- | See 'Streamly.Internal.Data.Parser.eqBy'.
1472+-- | See 'Streamly.Internal.Data.Parser.streamEqBy'.
1473--
1473--
1474-- /Pre-release/
1474-- /Pre-release/
1475--
1475--
@@ -1503,9 +1503,9 @@ listEqBy cmp str = Parser step initial extract
1503 ++ show (length xs) ++ " elements"
1503 ++ show (length xs) ++ " elements"
1504
1504
1505-- | Like 'listEqBy' but uses a stream instead of a list
1505-- | Like 'listEqBy' but uses a stream instead of a list
1506−{-# INLINE eqBy #-}
1506+{-# INLINE streamEqBy #-}
1507−eqBy :: Monad m => (a -> a -> Bool) -> D.Stream m a -> Parser a m ()
1507+streamEqBy :: Monad m => (a -> a -> Bool) -> D.Stream m a -> Parser a m ()
1508−eqBy cmp (D.Stream sstep state) = Parser step initial extract
1508+streamEqBy cmp (D.Stream sstep state) = Parser step initial extract
1509
1509
1510 where
1510 where
1511
1511
@@ -1526,7 +1526,7 @@ eqBy cmp (D.Stream sstep state) = Parser step initial extract
1526 D.Yield x1 s -> Continue 0 (Just' x1, s)
1526 D.Yield x1 s -> Continue 0 (Just' x1, s)
1527 D.Stop -> Done 0 ()
1527 D.Stop -> Done 0 ()
1528 D.Skip s -> Continue 1 (Nothing', s)
1528 D.Skip s -> Continue 1 (Nothing', s)
1529− else return $ Error "eqBy: mismtach occurred"
1529+ else return $ Error "streamEqBy: mismtach occurred"
1530 step (Nothing', st) a = do
1530 step (Nothing', st) a = do
1531 r <- sstep defState st
1531 r <- sstep defState st
1532 return
1532 return
@@ -1534,11 +1534,11 @@ eqBy cmp (D.Stream sstep state) = Parser step initial extract
1534 D.Yield x s -> do
1534 D.Yield x s -> do
1535 if x `cmp` a
1535 if x `cmp` a
1536 then Continue 0 (Nothing', s)
1536 then Continue 0 (Nothing', s)
1537− else Error "eqBy: mismatch occurred"
1537+ else Error "streamEqBy: mismatch occurred"
1538 D.Stop -> Done 1 ()
1538 D.Stop -> Done 1 ()
1539 D.Skip s -> Continue 1 (Nothing', s)
1539 D.Skip s -> Continue 1 (Nothing', s)
1540
1540
1541− extract _ = return $ Error "eqBy: end of input"
1541+ extract _ = return $ Error "streamEqBy: end of input"
1542
1542
1543-------------------------------------------------------------------------------
1543-------------------------------------------------------------------------------
1544-- Transformations on input
1544-- Transformations on input