megaparsec-utils 0.2.0.0 → 0.3.0.0
raw patch · 3 files changed
+15/−14 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Text.Megaparsec.Utils: occurrences :: MonadParsec e s m => m a -> m [a]
+ Text.Megaparsec.Utils: occurrences :: MonadParsec e s m => m a -> m (NonEmpty a)
- Text.Megaparsec.Utils.Common: occurrences :: MonadParsec e s m => m a -> m [a]
+ Text.Megaparsec.Utils.Common: occurrences :: MonadParsec e s m => m a -> m (NonEmpty a)
Files
- megaparsec-utils.cabal +1/−1
- src/Text/Megaparsec/Utils/Common.hs +10/−9
- test/Text/Megaparsec/UtilsSpec.hs +4/−4
megaparsec-utils.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: megaparsec-utils-version: 0.2.0.0+version: 0.3.0.0 synopsis: Parsers and utilities for the Megaparsec library. description: Common parsers and utilities to use with the Megaparsec library. category: Parsing
src/Text/Megaparsec/Utils/Common.hs view
@@ -29,6 +29,7 @@ import Control.Applicative.Combinators (choice) import Control.Monad (replicateM) import Control.Monad.Combinators (optional)+import qualified Control.Monad.Combinators.NonEmpty as NE (some) import Data.Foldable (traverse_) import Data.Functor (($>)) import Data.List (intercalate, sortOn)@@ -50,8 +51,8 @@ -- | Parse all occurrences of a given parser. -- -- @since 0.2.0.0-occurrences :: MonadParsec e s m => m a -> m [a]-occurrences = some . try . occurrence . try+occurrences :: MonadParsec e s m => m a -> m (NonEmpty a)+occurrences = NE.some . try . occurrence . try -- | Build a case-insensitive human-readable boolean parser, including C-style -- numbers, English yes-no and @on@ / @off@.@@ -66,8 +67,8 @@ -> m Bool mkBoolParser char' fromChar = true <|> false where- true = True <$ choice (map (try . traverse_ (char' . fromChar)) ["true", "y", "yes", "on", "1"])- false = False <$ choice (map (try . traverse_ (char' . fromChar)) ["false", "n", "no", "off", "0"])+ true = True <$ choice (fmap (try . traverse_ (char' . fromChar)) ["true", "y", "yes", "on", "1"])+ false = False <$ choice (fmap (try . traverse_ (char' . fromChar)) ["false", "n", "no", "off", "0"]) -- | Build a parser for a 'Bounded' 'Enum' type that has a 'Show' instance, -- trying all possibilities, case-insensitive, in the 'Enum' order.@@ -85,7 +86,7 @@ -- ^ Convert a literal 'Char' to a token. -> m a mkBoundedEnumShowParser char' fromChar =- choice . map parseShow $ sortOn (negate . length . show) [(minBound :: a) ..]+ choice . fmap parseShow $ sortOn (negate . length . show) [(minBound :: a) ..] where parseShow a = try (traverse_ (char' . fromChar) (show a)) $> a @@ -119,7 +120,7 @@ num <- some digitChar dec <- optional (dot >> some digitChar) - let toStr = map toChar+ let toStr = fmap toChar str = toStr num <> maybe "" (('.' :) . toStr) dec maybe (fail ("could not read from input: " <> str)) pure (readMaybe str)@@ -138,7 +139,7 @@ -> m a mkPosNumParser digitChar toChar = do digits <- some digitChar- let str = map toChar digits+ let str = fmap toChar digits maybe (fail ("could not read from digits: " <> str)) pure@@ -178,11 +179,11 @@ part4 <- replicateM 4 hexDigitChar <* dash part5 <- replicateM 12 hexDigitChar - let toStr = map toChar+ let toStr = fmap toChar pure ( fromJust ( U.fromString- (intercalate "-" (map toStr [part1, part2, part3, part4, part5]))+ (intercalate "-" (toStr <$> [part1, part2, part3, part4, part5])) ) )
test/Text/Megaparsec/UtilsSpec.hs view
@@ -204,20 +204,20 @@ describe "occurrences" $ do it "SomeData" . forAll input $ \(prefix, v, suffix) -> do let s = unwords [prefix, show (v :: SomeData), suffix]- parseOrPrettyError (occurrences someDataParser) s `shouldBe` Right [v]+ parseOrPrettyError (occurrences someDataParser) s `shouldBe` Right (pure v) context "SomeEnum" $ do it "words" . forAll input $ \(prefix, v, suffix) -> do let s = unwords [prefix, show (v :: SomeEnum), suffix]- parseOrPrettyError (occurrences someEnumParser) s `shouldBe` Right [v]+ parseOrPrettyError (occurrences someEnumParser) s `shouldBe` Right (pure v) it "with partial" $ parseOrPrettyError (occurrences someEnumParser) "a [Some] SomeA yo"- `shouldBe` Right [SomeA]+ `shouldBe` Right (pure SomeA) it "SomeADT" . forAll input $ \(prefix, v, suffix) -> do let s = unwords [prefix, show (v :: SomeADT), suffix]- parseOrPrettyError (occurrences someADTParser) s `shouldBe` Right [v]+ parseOrPrettyError (occurrences someADTParser) s `shouldBe` Right (pure v) describe "comma-separated" $ do context "valid" $ do