@@ -76,8 +76,8 @@ module Streamly.Internal.Data.Parser
77 -- All of these can be expressed in terms of either
77 -- All of these can be expressed in terms of either
80− , except
80+ , oneNotEq
@@ -102,9 +102,9 @@ module Streamly.Internal.Data.Parser
103 -- Grab a sequence of input elements by inspecting them
103 -- Grab a sequence of input elements by inspecting them
104 -- ** Exact match
104 -- ** Exact match
109 -- ** By predicate
109 -- ** By predicate
110 , takeWhileP
110 , takeWhileP
@@ -248,11 +248,6 @@ module Streamly.Internal.Data.Parser
251−import Data.Functor (($>))
252−import Prelude hiding
253− ( any, all, dropWhile, take, takeWhile, sequence, concatMap, maybe, either
256import Streamly.Internal.Data.Fold.Type (Fold(..))
251import Streamly.Internal.Data.Fold.Type (Fold(..))
257import Streamly.Internal.Data.Parser.ParserK.Type (Parser)
252import Streamly.Internal.Data.Parser.ParserK.Type (Parser)
258import Streamly.Internal.Data.Stream.Type (Stream)
253import Streamly.Internal.Data.Stream.Type (Stream)
@@ -262,6 +257,10 @@ import qualified Streamly.Internal.Data.Parser.ParserD as D
262import qualified Streamly.Internal.Data.Parser.ParserK.Type as K
257import qualified Streamly.Internal.Data.Parser.ParserK.Type as K
263import qualified Streamly.Internal.Data.Stream.Type as Stream
258import qualified Streamly.Internal.Data.Stream.Type as Stream
260+import Prelude hiding
261+ ( any, all, dropWhile, take, takeWhile, sequence, concatMap, maybe, either
@@ -463,19 +462,19 @@ one = satisfy $ const True
464-- | Match a specific element.
463-- | Match a specific element.
466−-- >>> element x = Parser.satisfy (== x)
465+-- >>> oneEq x = Parser.satisfy (== x)
468−{-# INLINE element #-}
467+{-# INLINE oneEq #-}
469−element :: (Monad m, Eq a) => a -> Parser m a a
468+oneEq :: (Monad m, Eq a) => a -> Parser m a a
470−element x = satisfy (== x)
469+oneEq x = satisfy (== x)
472-- | Match anything other than the supplied element.
471-- | Match anything other than the supplied element.
474−-- >>> except x = Parser.satisfy (/= x)
473+-- >>> oneNotEq x = Parser.satisfy (/= x)
476−{-# INLINE except #-}
475+{-# INLINE oneNotEq #-}
477−except :: (Monad m, Eq a) => a -> Parser m a a
476+oneNotEq :: (Monad m, Eq a) => a -> Parser m a a
478−except x = satisfy (/= x)
477+oneNotEq x = satisfy (/= x)
480-- | Match any one of the elements in the supplied list.
479-- | Match any one of the elements in the supplied list.
@@ -1026,30 +1025,37 @@ groupByRollingEither :: Monad m =>
1026groupByRollingEither eq f1 = D.toParserK . D.groupByRollingEither eq f1
1025groupByRollingEither eq f1 = D.toParserK . D.groupByRollingEither eq f1
1028-- | Match the given sequence of elements using the given comparison function.
1027-- | Match the given sequence of elements using the given comparison function.
1028+-- Returns the original sequence if successful.
1030−-- >>> Stream.parse (Parser.eqBy (==) "string") $ Stream.fromList "string"
1030+-- >>> Stream.parse (Parser.listEqBy (==) "string") $ Stream.fromList "string"
1032−-- >>> Stream.parse (Parser.eqBy (==) "mismatch") $ Stream.fromList "match"
1033+-- >>> Stream.parse (Parser.listEqBy (==) "mismatch") $ Stream.fromList "match"
1033−-- *** Exception: ParseError "eqBy: failed, yet to match 7 elements"
1034+-- *** Exception: ParseError "listEqBy: failed, yet to match 7 elements"
1035-- /Pre-release/
1036-- /Pre-release/
1037−{-# INLINE eqBy #-}
1038+{-# INLINE listEqBy #-}
1038−eqBy :: Monad m => (a -> a -> Bool) -> [a] -> Parser m a ()
1039+listEqBy :: Monad m => (a -> a -> Bool) -> [a] -> Parser m a [a]
1039−eqBy cmp = D.toParserK . D.eqBy cmp
1040+listEqBy cmp xs = D.toParserK (D.listEqBy cmp xs)
1041−-- | Like eqBy but uses a stream instead of a list
1042+-- | Like 'listEqBy' but uses a stream instead of a list and does not return
1042−{-# INLINE matchBy #-}
1046+{-# INLINE eqBy #-}
1043−matchBy :: Monad m => (a -> a -> Bool) -> Stream m a -> Parser m a ()
1047+eqBy :: Monad m => (a -> a -> Bool) -> Stream m a -> Parser m a ()
1044−matchBy cmp = D.toParserK . D.matchBy cmp . Stream.toStreamD
1048+eqBy cmp = D.toParserK . D.eqBy cmp . Stream.toStreamD
1046-- | Match the input sequence with the supplied list and return it if
1050-- | Match the input sequence with the supplied list and return it if
1047-- successful.
1051-- successful.
1053+-- >>> listEq = Parser.listEqBy (==)
1049-- /Pre-release/
1055-- /Pre-release/
1050−{-# INLINE list #-}
1056+{-# INLINE listEq #-}
1051−list :: (Monad m, Eq a) => [a] -> Parser m a [a]
1057+listEq :: (Monad m, Eq a) => [a] -> Parser m a [a]
1052−list xs = eqBy (==) xs $> xs
1058+listEq = listEqBy (==)
1054-------------------------------------------------------------------------------
1060-------------------------------------------------------------------------------
1055-- nested parsers
1061-- nested parsers