packages feed

parser-combinators 1.1.0 → 1.2.0

raw patch · 10 files changed

+103/−51 lines, 10 filesdep ~base

Dependency ranges changed: base

Files

CHANGELOG.md view
@@ -1,7 +1,15 @@+## Parser combinators 1.2.0++* Added `manyTill_` and `someTill_` combinators which work like the older+  `manyTill` and `someTill` except they also return the result of the `end`+  parser.++* Dropped support for GHC 8.0.+ ## Parser combinators 1.1.0  * Added support for ternary operators; see `TernR` in-    `Control.Monad.Combinators.Expr`.+  `Control.Monad.Combinators.Expr`.  ## Parser combinators 1.0.3 
Control/Applicative/Combinators.hs view
@@ -1,6 +1,6 @@ -- | -- Module      :  Control.Applicative.Combinators--- Copyright   :  © 2017–2019 Mark Karpov+-- Copyright   :  © 2017–present Mark Karpov -- License     :  BSD 3 clause -- -- Maintainer  :  Mark Karpov <markkarpov92@gmail.com>@@ -43,6 +43,7 @@ -- composite parsers in @try@ to achieve correct behavior.  {-# LANGUAGE BangPatterns #-}+{-# LANGUAGE TupleSections #-}  module Control.Applicative.Combinators   ( -- * Re-exports from "Control.Applicative"@@ -66,7 +67,9 @@   , endBy   , endBy1   , manyTill+  , manyTill_   , someTill+  , someTill_   , option   , sepBy   , sepBy1@@ -198,7 +201,8 @@ {-# INLINE endBy1 #-}  -- | @'manyTill' p end@ applies parser @p@ /zero/ or more times until parser--- @end@ succeeds. Returns the list of values returned by @p@.+-- @end@ succeeds. Returns the list of values returned by @p@. @end@ result+-- is consumed and lost. Use 'manyTill_' if you wish to keep it. -- -- See also: 'skipMany', 'skipManyTill'. @@ -208,14 +212,43 @@     go = ([] <$ end) <|> liftA2 (:) p go {-# INLINE manyTill #-} +-- | @'manyTill_' p end@ applies parser @p@ /zero/ or more times until+-- parser @end@ succeeds. Returns the list of values returned by @p@ and the+-- @end@ result. Use 'manyTill' if you have no need in the result of the+-- @end@.+--+-- See also: 'skipMany', 'skipManyTill'.+--+-- @since 1.2.0++manyTill_ :: Alternative m => m a -> m end -> m ([a], end)+manyTill_ p end = go+  where+    go = (([],) <$> end) <|> liftA2 (\x (xs, y) -> (x:xs, y)) p go+{-# INLINE manyTill_ #-}+ -- | @'someTill' p end@ works similarly to @'manyTill' p end@, but @p@--- should succeed at least once.+-- should succeed at least once. @end@ result is consumed and lost. Use+-- 'someTill_' if you wish to keep it. -- -- See also: 'skipSome', 'skipSomeTill'.  someTill :: Alternative m => m a -> m end -> m [a] someTill p end = liftA2 (:) p (manyTill p end) {-# INLINE someTill #-}++-- | @'someTill_' p end@ works similarly to @'manyTill_' p end@, but @p@+-- should succeed at least once. Use 'someTill' if you have no need in the+-- result of the @end@.+--+-- See also: 'skipSome', 'skipSomeTill'.+--+-- @since 1.2.0++someTill_ :: Alternative m => m a -> m end -> m ([a], end)+someTill_ p end =+  liftA2 (\x (xs, y) -> (x:xs, y)) p (manyTill_ p end)+{-# INLINE someTill_ #-}  -- | @'option' x p@ tries to apply the parser @p@. If @p@ fails without -- consuming input, it returns the value @x@, otherwise the value returned
Control/Applicative/Combinators/NonEmpty.hs view
@@ -1,6 +1,6 @@ -- | -- Module      :  Control.Applicative.Combinators--- Copyright   :  © 2017–2019 Mark Karpov+-- Copyright   :  © 2017–present Mark Karpov -- License     :  BSD 3 clause -- -- Maintainer  :  Mark Karpov <markkarpov92@gmail.com>
Control/Applicative/Permutations.hs view
@@ -1,6 +1,6 @@ -- | -- Module      :  Control.Applicative.Permutations--- Copyright   :  © 2017–2019 Alex Washburn+-- Copyright   :  © 2017–present Alex Washburn -- License     :  BSD 3 clause -- -- Maintainer  :  Mark Karpov <markkarpov92@gmail.com>@@ -40,8 +40,6 @@ -- -- @since 0.2.0 -{-# LANGUAGE CPP #-}- module Control.Applicative.Permutations   ( -- ** Permutation type     Permutation@@ -68,12 +66,10 @@     where       lhsAlt = (<*> rhs) <$> v       rhsAlt = (lhs <*>) <$> w-#if MIN_VERSION_base(4,10,0)   liftA2 f lhs@(P x v) rhs@(P y w) = P (liftA2 f x y) (lhsAlt <|> rhsAlt)     where       lhsAlt = (\p -> liftA2 f p rhs) <$> v       rhsAlt = liftA2 f lhs <$> w-#endif  -- | \"Unlifts\" a permutation parser into a parser to be evaluated. 
Control/Monad/Combinators.hs view
@@ -1,6 +1,6 @@ -- | -- Module      :  Control.Monad.Combinators--- Copyright   :  © 2017–2019 Mark Karpov+-- Copyright   :  © 2017–present Mark Karpov -- License     :  BSD 3 clause -- -- Maintainer  :  Mark Karpov <markkarpov92@gmail.com>@@ -37,8 +37,10 @@   , endBy1   , many   , manyTill+  , manyTill_   , some   , someTill+  , someTill_   , C.option   , sepBy   , sepBy1@@ -121,7 +123,7 @@     god f !d =       if d > 0         then do-          r <- optional p+          r <- C.optional p           case r of             Nothing -> return (f [])             Just  x -> god (f . (x:)) (d - 1)@@ -134,14 +136,14 @@ -- > cStatements = cStatement `endBy` semicolon  endBy :: MonadPlus m => m a -> m sep -> m [a]-endBy p sep = many (p >>= \x -> re x sep)+endBy p sep = many (p >>= \x -> x <$ sep) {-# INLINE endBy #-}  -- | @'endBy1' p sep@ parses /one/ or more occurrences of @p@, separated and -- ended by @sep@. Returns a list of values returned by @p@.  endBy1 :: MonadPlus m => m a -> m sep -> m [a]-endBy1 p sep = some (p >>= \x -> re x sep)+endBy1 p sep = some (p >>= \x -> x <$ sep) {-# INLINE endBy1 #-}  -- | @'many' p@ applies the parser @p@ /zero/ or more times and returns a@@ -153,28 +155,43 @@ many p = go id   where     go f = do-      r <- optional p+      r <- C.optional p       case r of         Nothing -> return (f [])         Just  x -> go (f . (x:)) {-# INLINE many #-}  -- | @'manyTill' p end@ applies parser @p@ /zero/ or more times until parser--- @end@ succeeds. Returns the list of values returned by @p@.+-- @end@ succeeds. Returns the list of values returned by @p@. __Note__ that+-- @end@ result is consumed and lost. Use 'manyTill_' if you wish to keep+-- it. -- -- See also: 'skipMany', 'skipManyTill'.  manyTill :: MonadPlus m => m a -> m end -> m [a]-manyTill p end = go id+manyTill p end = fst <$> manyTill_ p end+{-# INLINE manyTill #-}++-- | @'manyTill_' p end@ applies parser @p@ /zero/ or more times until+-- parser @end@ succeeds. Returns the list of values returned by @p@ and the+-- @end@ result. Use 'manyTill' if you have no need in the result of the+-- @end@.+--+-- See also: 'skipMany', 'skipManyTill'.+--+-- @since 1.2.0++manyTill_ :: MonadPlus m => m a -> m end -> m ([a], end)+manyTill_ p end = go id   where     go f = do-      done <- option False (re True end)-      if done-        then return (f [])-        else do+      done <- C.optional end+      case done of+        Just done' -> return (f [], done')+        Nothing  -> do           x <- p           go (f . (x:))-{-# INLINE manyTill #-}+{-# INLINE manyTill_ #-}  -- | @'some' p@ applies the parser @p@ /one/ or more times and returns a -- list of the values returned by @p@.@@ -186,7 +203,8 @@ {-# INLINE some #-}  -- | @'someTill' p end@ works similarly to @'manyTill' p end@, but @p@--- should succeed at least once.+-- should succeed at least once. __Note__ that @end@ result is consumed and+-- lost. Use 'someTill_' if you wish to keep it. -- -- See also: 'skipSome', 'skipSomeTill'. @@ -194,6 +212,18 @@ someTill p end = liftM2 (:) p (manyTill p end) {-# INLINE someTill #-} +-- | @'someTill_' p end@ works similarly to @'manyTill_' p end@, but @p@+-- should succeed at least once. Use 'someTill' if you have no need in the+-- result of the @end@.+--+-- See also: 'skipSome', 'skipSomeTill'.+--+-- @since 1.2.0++someTill_ :: MonadPlus m => m a -> m end -> m ([a], end)+someTill_ p end = liftM2 (\x (xs, y) -> (x:xs, y)) p (manyTill_ p end)+{-# INLINE someTill_ #-}+ -- | @'sepBy' p sep@ parses /zero/ or more occurrences of @p@, separated by -- @sep@. Returns a list of values returned by @p@. --@@ -201,7 +231,7 @@  sepBy :: MonadPlus m => m a -> m sep -> m [a] sepBy p sep = do-  r <- optional p+  r <- C.optional p   case r of     Nothing -> return []     Just  x -> (x:) <$> many (sep >> p)@@ -223,11 +253,11 @@ sepEndBy p sep = go id   where     go f = do-      r <- optional p+      r <- C.optional p       case r of         Nothing -> return (f [])         Just  x -> do-          more <- option False (re True sep)+          more <- C.option False (True <$ sep)           if more             then go (f . (x:))             else return (f [x])@@ -239,7 +269,7 @@ sepEndBy1 :: MonadPlus m => m a -> m sep -> m [a] sepEndBy1 p sep = do   x <- p-  more <- option False (re True sep)+  more <- C.option False (True <$ sep)   if more     then (x:) <$> sepEndBy p sep     else return [x]@@ -254,7 +284,7 @@ skipMany p = go   where     go = do-      more <- option False (re True p)+      more <- C.option False (True <$ p)       when more go {-# INLINE skipMany #-} @@ -291,7 +321,7 @@ skipManyTill p end = go   where     go = do-      r <- optional end+      r <- C.optional end       case r of         Nothing -> p >> go         Just  x -> return x@@ -306,18 +336,3 @@ skipSomeTill :: MonadPlus m => m a -> m end -> m end skipSomeTill p end = p >> skipManyTill p end {-# INLINE skipSomeTill #-}--------------------------------------------------------------------------------- Compat helpers (for older GHCs)--re :: Monad m => a -> m b -> m a-re x = fmap (const x)-{-# INLINE re #-}--option :: MonadPlus m => a -> m a -> m a-option x p = p `mplus` return x-{-# INLINE option #-}--optional :: MonadPlus m => m a -> m (Maybe a)-optional p = fmap Just p `mplus` return Nothing-{-# INLINE optional #-}
Control/Monad/Combinators/Expr.hs view
@@ -1,6 +1,6 @@ -- | -- Module      :  Control.Monad.Combinators.Expr--- Copyright   :  © 2017–2019 Mark Karpov+-- Copyright   :  © 2017–present Mark Karpov -- License     :  BSD 3 clause -- -- Maintainer  :  Mark Karpov <markkarpov92@gmail.com>
Control/Monad/Combinators/NonEmpty.hs view
@@ -1,6 +1,6 @@ -- | -- Module      :  Control.Monad.Combinators.NonEmpty--- Copyright   :  © 2017–2019 Mark Karpov+-- Copyright   :  © 2017–present Mark Karpov -- License     :  BSD 3 clause -- -- Maintainer  :  Mark Karpov <markkarpov92@gmail.com>
LICENSE.md view
@@ -1,4 +1,4 @@-Copyright © 2017–2019 Mark Karpov+Copyright © 2017–present Mark Karpov  All rights reserved. 
README.md view
@@ -20,6 +20,6 @@  ## License -Copyright © 2017–2019 Mark Karpov+Copyright © 2017–present Mark Karpov  Distributed under BSD 3 clause license.
parser-combinators.cabal view
@@ -1,7 +1,7 @@ name:                 parser-combinators-version:              1.1.0+version:              1.2.0 cabal-version:        1.18-tested-with:          GHC==8.0.2, GHC==8.2.2, GHC==8.4.4, GHC==8.6.5+tested-with:          GHC==8.2.2, GHC==8.4.4, GHC==8.6.5 license:              BSD3 license-file:         LICENSE.md author:               Mark Karpov <markkarpov92@gmail.com>@@ -26,7 +26,7 @@   default:            False  library-  build-depends:      base             >= 4.9 && < 5.0+  build-depends:      base             >= 4.10 && < 5.0   exposed-modules:    Control.Applicative.Combinators                     , Control.Applicative.Combinators.NonEmpty                     , Control.Applicative.Permutations