packages feed

parser-combinators 0.2.1 → 0.3.0

raw patch · 3 files changed

+38/−11 lines, 3 files

Files

CHANGELOG.md view
@@ -1,3 +1,9 @@+## Parser combinators 0.3.0++* Added the `skipCount` combinator.++* Improved algorithmic efficiency of the `count'` combinator.+ ## Parser combinators 0.2.1  * Removed the byte order marking at the beginning of the
Control/Applicative/Combinators.hs view
@@ -63,6 +63,7 @@   , sepEndBy1   , skipMany   , skipSome+  , skipCount   , skipManyTill   , skipSomeTill ) where@@ -70,7 +71,9 @@ import Control.Applicative import Data.Foldable -#if !MIN_VERSION_base(4,8,0)+#if MIN_VERSION_base(4,9,0)+import Control.Monad (replicateM, replicateM_)+#elif !MIN_VERSION_base(4,8,0) import Data.Traversable (sequenceA) #endif @@ -128,10 +131,14 @@ -- | @'count' n p@ parses @n@ occurrences of @p@. If @n@ is smaller or equal -- to zero, the parser equals to @'pure' []@. Returns a list of @n@ values. ----- See also: 'count''.+-- See also: 'skipCount', 'count''.  count :: Applicative m => Int -> m a -> m [a]+#if MIN_VERSION_base(4,9,0)+count = replicateM+#else count n p = sequenceA (replicate n p)+#endif {-# INLINE count #-}  -- | @'count'' m n p@ parses from @m@ to @n@ occurrences of @p@. If @n@ is@@ -148,10 +155,8 @@   where     go !m !n       | n <= 0 || m > n = pure []-      | m > 0           = (:) <$> p <*> go (m - 1) (n - 1)-      | otherwise       =-          let f t ts = maybe [] (:ts) t-          in f <$> optional p <*> go 0 (pred n)+      | m > 0           = liftA2 (:) p (go (m - 1) (n - 1))+      | otherwise       = liftA2 (:) p (go 0 (n - 1)) <|> pure [] {-# INLINE count' #-}  -- | Combine two alternatives.@@ -184,7 +189,7 @@ manyTill :: Alternative m => m a -> m end -> m [a] manyTill p end = go   where-    go = ([] <$ end) <|> ((:) <$> p <*> go)+    go = ([] <$ end) <|> liftA2 (:) p go {-# INLINE manyTill #-}  -- | @'someTill' p end@ works similarly to @'manyTill' p end@, but @p@@@ -193,7 +198,7 @@ -- See also: 'skipSome', 'skipSomeTill'.  someTill :: Alternative m => m a -> m end -> m [a]-someTill p end = (:) <$> p <*> manyTill p end+someTill p end = liftA2 (:) p (manyTill p end) {-# INLINE someTill #-}  -- | @'option' x p@ tries to apply the parser @p@. If @p@ fails without@@ -221,7 +226,7 @@ -- @sep@. Returns a list of values returned by @p@.  sepBy1 :: Alternative m => m a -> m sep -> m [a]-sepBy1 p sep = (:) <$> p <*> many (sep *> p)+sepBy1 p sep = liftA2 (:) p (many (sep *> p)) {-# INLINE sepBy1 #-}  -- | @'sepEndBy' p sep@ parses /zero/ or more occurrences of @p@, separated@@ -235,7 +240,7 @@ -- and optionally ended by @sep@. Returns a list of values returned by @p@.  sepEndBy1 :: Alternative m => m a -> m sep -> m [a]-sepEndBy1 p sep = (:) <$> p <*> ((sep *> sepEndBy p sep) <|> pure [])+sepEndBy1 p sep = liftA2 (:) p ((sep *> sepEndBy p sep) <|> pure []) {-# INLINEABLE sepEndBy1 #-}  -- | @'skipMany' p@ applies the parser @p@ /zero/ or more times, skipping@@ -257,6 +262,22 @@ skipSome :: Alternative m => m a -> m () skipSome p = p *> skipMany p {-# INLINE skipSome #-}++-- | @'skipCount' n p@ parses @n@ occurrences of @p@, skipping its result. If+-- @n@ is smaller or equal to zero, the parser equals to @'pure' []@. Returns a+-- list of @n@ values.+--+-- See also: 'count', 'count''.+--+-- @since 0.3.0++skipCount :: Applicative m => Int -> m a -> m ()+#if MIN_VERSION_base(4,9,0)+skipCount = replicateM_+#else+skipCount n p = sequenceA_ (replicate n p)+#endif+{-# INLINE skipCount #-}  -- | @'skipManyTill' p end@ applies the parser @p@ /zero/ or more times -- skipping results until parser @end@ succeeds. Result parsed by @end@ is
parser-combinators.cabal view
@@ -1,5 +1,5 @@ name:                 parser-combinators-version:              0.2.1+version:              0.3.0 cabal-version:        >= 1.18 tested-with:          GHC==7.4.2, GHC==7.6.3, GHC==7.8.4, GHC==7.10.3, GHC==8.0.2, GHC==8.2.2 license:              BSD3