on master help sign in
Add a list matching parser
commit62e9f2e6b9f5fb782f3840dda519761d01e755b5 authorHarendra Kumar <harendra@composewell.com> dateWed 4 May 2022, 17:04 (4 years ago) parentaf4f001
1 file changed+11−1
core/src/Streamly/Internal/Data/Parser.hs+11−1
core/src/Streamly/Internal/Data/Parser.hs+11−1
@@ -88,6 +88,8 @@ module Streamly.Internal.Data.Parser
8888 , takeP
8989
9090 -- Grab a sequence of input elements by inspecting them
91+ , eqBy
92+ , list
9193 , lookAhead
9294 , takeWhileP
9395 , takeWhile
@@ -109,7 +111,6 @@ module Streamly.Internal.Data.Parser
109111 , groupBy
110112 , groupByRolling
111113 , groupByRollingEither
112− , eqBy
113114
114115 -- | Unimplemented
115116 --
@@ -215,6 +216,7 @@ where
215216
216217import Control.Applicative ((<|>))
217218import Control.Monad.Catch (MonadCatch, MonadThrow)
219+import Data.Functor (($>))
218220import Prelude hiding
219221 (any, all, take, takeWhile, sequence, concatMap, maybe, either, filter)
220222
@@ -803,6 +805,14 @@ groupByRollingEither eq f1 = D.toParserK . D.groupByRollingEither eq f1
803805eqBy :: MonadCatch m => (a -> a -> Bool) -> [a] -> Parser m a ()
804806eqBy cmp = D.toParserK . D.eqBy cmp
805807
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+
806816-------------------------------------------------------------------------------
807817-- nested parsers
808818-------------------------------------------------------------------------------