parsers 0.12.6 → 0.12.7
raw patch · 4 files changed
+36/−7 lines, 4 filesdep +semigroupsPVP ok
version bump matches the API change (PVP)
Dependencies added: semigroups
API changes (from Hackage documentation)
+ Text.Parser.Combinators: endByNonEmpty :: Alternative m => m a -> m sep -> m (NonEmpty a)
+ Text.Parser.Combinators: sepByNonEmpty :: Alternative m => m a -> m sep -> m (NonEmpty a)
+ Text.Parser.Combinators: sepEndByNonEmpty :: Alternative m => m a -> m sep -> m (NonEmpty a)
Files
- CHANGELOG.markdown +6/−0
- parsers.cabal +2/−1
- src/Text/Parser/Combinators.hs +24/−2
- tests/QuickCheck.hs +4/−4
CHANGELOG.markdown view
@@ -1,3 +1,9 @@+0.12.7+------+* Add `sepByNonEmpty`, `sepEndByNonEmpty`, and `endByNonEmpty` to+ `Text.Parser.Combinators`+* Fix sporadic `QuickCheck` test suite failures+ 0.12.6 ------ * Add a library dependency in the `doctests` test suite
parsers.cabal view
@@ -1,6 +1,6 @@ name: parsers category: Text, Parsing-version: 0.12.6+version: 0.12.7 license: BSD3 cabal-version: >= 1.10 license-file: LICENSE@@ -59,6 +59,7 @@ base-orphans >= 0.3 && < 1, charset >= 0.3 && < 1, containers >= 0.4 && < 0.6,+ semigroups >= 0.12 && < 1, parsec >= 3.1 && < 3.2, attoparsec >= 0.12.1.4 && < 0.14, text >= 0.10 && < 1.3,
src/Text/Parser/Combinators.hs view
@@ -42,9 +42,12 @@ , many -- from Control.Applicative , sepBy , sepBy1+ , sepByNonEmpty , sepEndBy1+ , sepEndByNonEmpty , sepEndBy , endBy1+ , endByNonEmpty , endBy , count , chainl@@ -68,6 +71,7 @@ import Control.Monad.Trans.Reader import Control.Monad.Trans.Identity import Data.Foldable (asum)+import Data.List.NonEmpty #if __GLASGOW_HASKELL__ < 710 import Data.Monoid #ifdef ORPHAN_ALTERNATIVE_READP@@ -122,15 +126,27 @@ -- | @sepBy1 p sep@ parses /one/ or more occurrences of @p@, separated -- by @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 = toList <$> sepByNonEmpty p sep {-# INLINE sepBy1 #-} +-- | @sepByNonEmpty p sep@ parses /one/ or more occurrences of @p@, separated+-- by @sep@. Returns a non-empty list of values returned by @p@.+sepByNonEmpty :: Alternative m => m a -> m sep -> m (NonEmpty a)+sepByNonEmpty p sep = (:|) <$> p <*> many (sep *> p)+{-# INLINE sepByNonEmpty #-}+ -- | @sepEndBy1 p sep@ parses /one/ or more occurrences of @p@, -- separated 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 = toList <$> sepEndByNonEmpty p sep +-- | @sepEndByNonEmpty p sep@ parses /one/ or more occurrences of @p@,+-- separated and optionally ended by @sep@. Returns a non-empty list of values+-- returned by @p@.+sepEndByNonEmpty :: Alternative m => m a -> m sep -> m (NonEmpty a)+sepEndByNonEmpty p sep = (:|) <$> p <*> ((sep *> sepEndBy p sep) <|> pure [])+ -- | @sepEndBy p sep@ parses /zero/ or more occurrences of @p@, -- separated and optionally ended by @sep@, ie. haskell style -- statements. Returns a list of values returned by @p@.@@ -145,6 +161,12 @@ endBy1 :: Alternative m => m a -> m sep -> m [a] endBy1 p sep = some (p <* sep) {-# INLINE endBy1 #-}++-- | @endByNonEmpty p sep@ parses /one/ or more occurrences of @p@, separated+-- and ended by @sep@. Returns a non-empty list of values returned by @p@.+endByNonEmpty :: Alternative m => m a -> m sep -> m (NonEmpty a)+endByNonEmpty p sep = some1 (p <* sep)+{-# INLINE endByNonEmpty #-} -- | @endBy p sep@ parses /zero/ or more occurrences of @p@, separated -- and ended by @sep@. Returns a list of values returned by @p@.
tests/QuickCheck.hs view
@@ -9,8 +9,8 @@ import Control.Applicative -import Data.Attoparsec.ByteString.Char8 (parseOnly)-import qualified Data.ByteString.Char8 as B8+import Data.Attoparsec.Text (parseOnly)+import Data.String #if MIN_VERSION_base(4,7,0) import Data.Either@@ -32,14 +32,14 @@ -- Instead of letting quick check pick the parser framework as a test parameter -- it may be better to just run all tests for each parser framework. -data P a = P (forall m. (Monad m, CharParsing m) => m a)+newtype P a = P (forall m. (Monad m, CharParsing m) => m a) data TestParser a = TestParser String (P a -> String -> Either String a) instance Show (TestParser a) where show (TestParser n _) = n pAtto, pParsec, pReadP :: TestParser a-pAtto = TestParser "attoparsec" $ \(P p) -> parseOnly p . B8.pack+pAtto = TestParser "attoparsec" $ \(P p) -> parseOnly p . fromString pParsec = TestParser "parsec" $ \(P p) -> either (Left . show) Right . parse p "test input" pReadP = TestParser "ReadP" $ \(P p) s -> case readP_to_S p s of [] -> Left "parseFailed"