@@ -76,8 +76,8 @@ module Streamly.Internal.Data.Parser
7676
7777 -- All of these can be expressed in terms of either
7878 , one
79− , element
80− , except
79+ , oneEq
80+ , oneNotEq
8181 , oneOf
8282 , noneOf
8383 , eof
@@ -102,9 +102,9 @@ module Streamly.Internal.Data.Parser
102102
103103 -- Grab a sequence of input elements by inspecting them
104104 -- ** Exact match
105+ , listEq
106+ , listEqBy
105107 , eqBy
106− , matchBy
107− , list
108108
109109 -- ** By predicate
110110 , takeWhileP
@@ -248,11 +248,6 @@ module Streamly.Internal.Data.Parser
248248 )
249249where
250250
251−import Data.Functor (($>))
252−import Prelude hiding
253− ( any, all, dropWhile, take, takeWhile, sequence, concatMap, maybe, either
254− , filter )
255−
256251import Streamly.Internal.Data.Fold.Type (Fold(..))
257252import Streamly.Internal.Data.Parser.ParserK.Type (Parser)
258253import Streamly.Internal.Data.Stream.Type (Stream)
@@ -262,6 +257,10 @@ import qualified Streamly.Internal.Data.Parser.ParserD as D
262257import qualified Streamly.Internal.Data.Parser.ParserK.Type as K
263258import qualified Streamly.Internal.Data.Stream.Type as Stream
264259
260+import Prelude hiding
261+ ( any, all, dropWhile, take, takeWhile, sequence, concatMap, maybe, either
262+ , filter )
263+
265264--
266265-- $setup
267266-- >>> :m
@@ -463,19 +462,19 @@ one = satisfy $ const True
463462
464463-- | Match a specific element.
465464--
466−-- >>> element x = Parser.satisfy (== x)
465+-- >>> oneEq x = Parser.satisfy (== x)
467466--
468−{-# INLINE element #-}
469−element :: (Monad m, Eq a) => a -> Parser m a a
470−element x = satisfy (== x)
467+{-# INLINE oneEq #-}
468+oneEq :: (Monad m, Eq a) => a -> Parser m a a
469+oneEq x = satisfy (== x)
471470
472471-- | Match anything other than the supplied element.
473472--
474−-- >>> except x = Parser.satisfy (/= x)
473+-- >>> oneNotEq x = Parser.satisfy (/= x)
475474--
476−{-# INLINE except #-}
477−except :: (Monad m, Eq a) => a -> Parser m a a
478−except x = satisfy (/= x)
475+{-# INLINE oneNotEq #-}
476+oneNotEq :: (Monad m, Eq a) => a -> Parser m a a
477+oneNotEq x = satisfy (/= x)
479478
480479-- | Match any one of the elements in the supplied list.
481480--
@@ -1026,30 +1025,37 @@ groupByRollingEither :: Monad m =>
10261025groupByRollingEither eq f1 = D.toParserK . D.groupByRollingEither eq f1
10271026
10281027-- | Match the given sequence of elements using the given comparison function.
1028+-- Returns the original sequence if successful.
10291029--
1030−-- >>> Stream.parse (Parser.eqBy (==) "string") $ Stream.fromList "string"
1030+-- >>> Stream.parse (Parser.listEqBy (==) "string") $ Stream.fromList "string"
1031+-- "string"
10311032--
1032−-- >>> Stream.parse (Parser.eqBy (==) "mismatch") $ Stream.fromList "match"
1033−-- *** Exception: ParseError "eqBy: failed, yet to match 7 elements"
1033+-- >>> Stream.parse (Parser.listEqBy (==) "mismatch") $ Stream.fromList "match"
1034+-- *** Exception: ParseError "listEqBy: failed, yet to match 7 elements"
10341035--
10351036-- /Pre-release/
10361037--
1037−{-# INLINE eqBy #-}
1038−eqBy :: Monad m => (a -> a -> Bool) -> [a] -> Parser m a ()
1039−eqBy cmp = D.toParserK . D.eqBy cmp
1038+{-# INLINE listEqBy #-}
1039+listEqBy :: Monad m => (a -> a -> Bool) -> [a] -> Parser m a [a]
1040+listEqBy cmp xs = D.toParserK (D.listEqBy cmp xs)
10401041
1041−-- | Like eqBy but uses a stream instead of a list
1042−{-# INLINE matchBy #-}
1043−matchBy :: Monad m => (a -> a -> Bool) -> Stream m a -> Parser m a ()
1044−matchBy cmp = D.toParserK . D.matchBy cmp . Stream.toStreamD
1042+-- | Like 'listEqBy' but uses a stream instead of a list and does not return
1043+-- the stream.
1044+--
1045+-- /Pre-release/
1046+{-# INLINE eqBy #-}
1047+eqBy :: Monad m => (a -> a -> Bool) -> Stream m a -> Parser m a ()
1048+eqBy cmp = D.toParserK . D.eqBy cmp . Stream.toStreamD
10451049
10461050-- | Match the input sequence with the supplied list and return it if
10471051-- successful.
10481052--
1053+-- >>> listEq = Parser.listEqBy (==)
1054+--
10491055-- /Pre-release/
1050−{-# INLINE list #-}
1051−list :: (Monad m, Eq a) => [a] -> Parser m a [a]
1052−list xs = eqBy (==) xs $> xs
1056+{-# INLINE listEq #-}
1057+listEq :: (Monad m, Eq a) => [a] -> Parser m a [a]
1058+listEq = listEqBy (==)
10531059
10541060-------------------------------------------------------------------------------
10551061-- nested parsers