on master help sign in
Add a list matching parser
62e9f2eHarendra Kumar
core/src/Streamly/Internal/Data/Parser.hs+11−1
@@ -88,6 +88,8 @@ module Streamly.Internal.Data.Parser
88 , takeP
88 , takeP
89
89
90 -- Grab a sequence of input elements by inspecting them
90 -- Grab a sequence of input elements by inspecting them
91+ , eqBy
92+ , list
91 , lookAhead
93 , lookAhead
92 , takeWhileP
94 , takeWhileP
93 , takeWhile
95 , takeWhile
@@ -109,7 +111,6 @@ module Streamly.Internal.Data.Parser
109 , groupBy
111 , groupBy
110 , groupByRolling
112 , groupByRolling
111 , groupByRollingEither
113 , groupByRollingEither
112− , eqBy
113
114
114 -- | Unimplemented
115 -- | Unimplemented
115 --
116 --
@@ -215,6 +216,7 @@ where
215
216
216import Control.Applicative ((<|>))
217import Control.Applicative ((<|>))
217import Control.Monad.Catch (MonadCatch, MonadThrow)
218import Control.Monad.Catch (MonadCatch, MonadThrow)
219+import Data.Functor (($>))
218import Prelude hiding
220import Prelude hiding
219 (any, all, take, takeWhile, sequence, concatMap, maybe, either, filter)
221 (any, all, take, takeWhile, sequence, concatMap, maybe, either, filter)
220
222
@@ -803,6 +805,14 @@ groupByRollingEither eq f1 = D.toParserK . D.groupByRollingEither eq f1
803eqBy :: MonadCatch m => (a -> a -> Bool) -> [a] -> Parser m a ()
805eqBy :: MonadCatch m => (a -> a -> Bool) -> [a] -> Parser m a ()
804eqBy cmp = D.toParserK . D.eqBy cmp
806eqBy cmp = D.toParserK . D.eqBy cmp
805
807
808+-- | Match the input sequence with the supplied list and return it if
809+-- successful.
810+--
811+-- /Pre-release/
812+{-# INLINE list #-}
813+list :: (MonadCatch m, Eq a) => [a] -> Parser m a [a]
814+list xs = eqBy (==) xs $> xs
815+
806-------------------------------------------------------------------------------
816-------------------------------------------------------------------------------
807-- nested parsers
817-- nested parsers
808-------------------------------------------------------------------------------
818-------------------------------------------------------------------------------