Update to megaparsec-7.0 (#60)

* Upper bound megaparsec 7.0

* Update to megaparsec-7.0.0

* Drop support GHC 7.8.4

* Change haddock comparison for 8.4.3

* Make sure we user megaparsec 7.0.1

* Fix travis
This commit is contained in:
Cristhian Motoche 2018-10-10 13:50:47 -05:00 committed by GitHub
parent a6a7b5cf10
commit b77803e17d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 62 additions and 30 deletions

View File

@ -9,12 +9,14 @@ cache:
matrix:
include:
- env: CABALVER=1.24 GHCVER=7.8.4
addons: {apt: {packages: [cabal-install-1.24,ghc-7.8.4,],sources: [hvr-ghc]}}
- env: CABALVER=1.24 GHCVER=7.10.3
addons: {apt: {packages: [cabal-install-1.24,ghc-7.10.3],sources: [hvr-ghc]}}
- env: CABALVER=1.24 GHCVER=8.0.2
addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.2],sources: [hvr-ghc]}}
- env: CABALVER=2.2 GHCVER=8.2.2
addons: {apt: {packages: [cabal-install-2.2,ghc-8.2.2], sources: [hvr-ghc]}}
- env: CABALVER=2.2 GHCVER=8.4.3
addons: {apt: {packages: [cabal-install-2.2,ghc-8.4.3], sources: [hvr-ghc]}}
before_install:
- export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
@ -32,7 +34,10 @@ script:
esac
- cabal build
- cabal sdist
- cabal haddock | grep "100%" | wc -l | grep "13"
- case "$GHCVER" in
"8.4.3") cabal haddock | grep "100%" | wc -l | grep "1" ;;
*) cabal haddock | grep "100%" | wc -l | grep "13" ;;
esac
notifications:
email: false

View File

@ -1,3 +1,7 @@
## Inflections 0.4.0.3
* Support `megaparsec` == 7.0*.
* **Drop support** for `GHC 7.8.4`.
## Inflections 0.4.0.3
* Support `exceptions` == 0.10.*

View File

@ -142,7 +142,7 @@ import Prelude hiding (Word)
--
-- >>> toUnderscore "FooBarBazz"
-- "foo_bar_bazz"
toUnderscore :: Text -> Either (ParseError Char Void) Text
toUnderscore :: Text -> Either (ParseErrorBundle Text Void) Text
toUnderscore = fmap underscore . parseCamelCase []
-- | Transforms CamelCasedString to snake-cased-string-with-dashes.
@ -151,7 +151,7 @@ toUnderscore = fmap underscore . parseCamelCase []
--
-- >>> toDashed "FooBarBazz"
-- "foo-bar-bazz"
toDashed :: Text -> Either (ParseError Char Void) Text
toDashed :: Text -> Either (ParseErrorBundle Text Void) Text
toDashed = fmap dasherize . parseCamelCase []
-- | Transforms underscored_text to CamelCasedText. If first argument is
@ -167,7 +167,7 @@ toDashed = fmap dasherize . parseCamelCase []
toCamelCased
:: Bool -- ^ Capitalize the first character
-> Text -- ^ Input
-> Either (ParseError Char Void) Text -- ^ Output
-> Either (ParseErrorBundle Text Void) Text -- ^ Output
toCamelCased c = fmap (camelizeCustom c) . parseSnakeCase []
-- | Transforms underscored_text to space-separated human-readable text.
@ -186,7 +186,7 @@ toCamelCased c = fmap (camelizeCustom c) . parseSnakeCase []
toHumanized
:: Bool -- ^ Capitalize the first character
-> Text -- ^ Input
-> Either (ParseError Char Void) Text -- ^ Output
-> Either (ParseErrorBundle Text Void) Text -- ^ Output
toHumanized c = fmap (humanizeCustom c) . parseSnakeCase []
-- | Lift something of type @'Either' ('ParseError' 'Char' 'Void') a@ to
@ -197,6 +197,6 @@ toHumanized c = fmap (humanizeCustom c) . parseSnakeCase []
--
-- /since 0.3.0.0/
betterThrow :: MonadThrow m => Either (ParseError Char Void) a -> m a
betterThrow :: MonadThrow m => Either (ParseErrorBundle Text Void) a -> m a
betterThrow (Left err) = throwM (InflectionParsingFailed err)
betterThrow (Right x) = return x

View File

@ -25,7 +25,7 @@ import Control.Applicative (empty, many, (<|>), (<$>), (<*))
import Data.Text (Text)
import Data.Void (Void)
import Text.Inflections.Types
import Text.Megaparsec (Parsec, ParseError, choice, eof, parse)
import Text.Megaparsec (Parsec, ParseErrorBundle, choice, eof, parse)
import Text.Megaparsec.Char
import qualified Data.Text as T
@ -51,7 +51,7 @@ type Parser = Parsec Void Text
parseCamelCase :: (Foldable f, Functor f)
=> f (Word 'Acronym) -- ^ Collection of acronyms
-> Text -- ^ Input
-> Either (ParseError Char Void) [SomeWord] -- ^ Result of parsing
-> Either (ParseErrorBundle Text Void) [SomeWord] -- ^ Result of parsing
parseCamelCase acronyms = parse (parser acronyms) ""
parser :: (Foldable f, Functor f)

View File

@ -24,7 +24,7 @@ import Control.Applicative (empty, some, (<$>), (<*))
import Data.Text (Text)
import Data.Void (Void)
import Text.Inflections.Types
import Text.Megaparsec (Parsec, ParseError, eof, sepBy, parse)
import Text.Megaparsec (Parsec, ParseErrorBundle, eof, sepBy, parse)
import Text.Megaparsec.Char
import qualified Data.Text as T
@ -50,7 +50,7 @@ type Parser = Parsec Void Text
parseSnakeCase :: (Foldable f, Functor f)
=> f (Word 'Acronym) -- ^ Collection of acronyms
-> Text -- ^ Input
-> Either (ParseError Char Void) [SomeWord] -- ^ Result of parsing
-> Either (ParseErrorBundle Text Void) [SomeWord] -- ^ Result of parsing
parseSnakeCase acronyms = parse (parser acronyms) ""
parser :: (Foldable f, Functor f)

View File

@ -136,7 +136,7 @@ instance Transformable (Word 'Acronym) where
-- /since 0.3.0.0/
data InflectionException
= InflectionParsingFailed (ParseError Char Void)
= InflectionParsingFailed (ParseErrorBundle Text Void)
| InflectionInvalidWord Text
| InflectionInvalidAcronym Text
deriving (Eq, Show, Typeable, Data, Generic)

View File

@ -1,5 +1,5 @@
name: inflections
version: 0.4.0.3
version: 0.4.0.4
synopsis: Inflections library for Haskell
description:
Inflections provides methods for singularization, pluralization,
@ -49,7 +49,7 @@ library
ghc-options: -O2 -Wall
build-depends: base >= 4.6 && < 5.0
, exceptions >= 0.6 && < 0.11
, megaparsec >= 6.0 && < 7.0
, megaparsec >= 7.0.1 && < 8.0
, text >= 0.2 && < 1.3
, unordered-containers >= 0.2.7 && < 0.3
if !impl(ghc >= 7.10)
@ -66,7 +66,7 @@ test-suite test
, base >= 4.6 && < 5.0
, containers >= 0.5 && < 0.7
, hspec >= 2.0 && < 3.0
, hspec-megaparsec >= 1.0 && < 2.0
, hspec-megaparsec >= 2.0 && < 3.0
, megaparsec
, text >= 0.2 && < 1.3
if !impl(ghc >= 7.10)

View File

@ -1,7 +1,14 @@
---
resolver: lts-7.13
resolver: lts-12.10
extra-deps:
- hspec-megaparsec-1.0.0
- megaparsec-6.0.0
- parser-combinators-0.1.0
- hspec-megaparsec-2.0.0
- hspec-expectations-0.8.2
- hspec-2.5.6
- hspec-core-2.5.6
- hspec-discover-2.5.6
- parser-combinators-1.0.0
- HUnit-1.6.0.0
- QuickCheck-2.12.2
- quickcheck-io-0.2.0
- megaparsec-7.0.1

View File

@ -1,3 +1,4 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
@ -8,6 +9,7 @@ import Test.Hspec
import Test.QuickCheck
import Text.Inflections
import Text.Megaparsec
import Data.Text
import qualified Data.List.NonEmpty as NE
import qualified Data.Set as S
@ -16,21 +18,35 @@ import qualified Data.Set as S
import Control.Applicative
#endif
arbitraryParseError :: Gen (ParseError Char Void)
instance Arbitrary Text where
arbitrary = pack <$> (arbitrary :: Gen String)
arbitraryParseErrorBundle :: Gen (ParseErrorBundle Text Void)
arbitraryParseErrorBundle = ParseErrorBundle <$> nonEmptyParseErrors <*> arbitraryPosState
where
posArbitrary = mkPos <$> ((+1) . abs <$> arbitrary)
nonEmptyParseErrors :: Gen (NE.NonEmpty (ParseError Text Void))
nonEmptyParseErrors = NE.fromList <$> listOf1 arbitraryParseError
arbitrarySourcePos :: Gen SourcePos
arbitrarySourcePos = SourcePos <$> arbitrary <*> posArbitrary <*> posArbitrary
arbitraryPosState :: Gen (PosState Text)
arbitraryPosState =
PosState
<$> arbitrary
<*> arbitrary
<*> arbitrarySourcePos
<*> posArbitrary
<*> arbitrary
arbitraryParseError :: Gen (ParseError Text Void)
arbitraryParseError = oneof [trivialError, fancyError]
where
trivialError = TrivialError <$> nonEmptyArbitrary <*> maybeErrorItem <*> setErrorItem
fancyError = FancyError <$> nonEmptyArbitrary <*> setErrorFancy
nonEmptyArbitrary = NE.fromList <$> listOf1 arbitrarySourcePos
trivialError = TrivialError <$> arbitrary <*> maybeErrorItem <*> setErrorItem
fancyError = FancyError <$> arbitrary <*> setErrorFancy
setErrorFancy = S.fromList <$> listOf arbitraryErrorFancy
maybeErrorItem = oneof [ Just <$> arbitraryErrorItem, return Nothing]
setErrorItem = S.fromList <$> listOf arbitraryErrorItem
arbitrarySourcePos :: Gen SourcePos
arbitrarySourcePos = SourcePos <$> arbitrary <*> posArbitrary <*> posArbitrary
where
posArbitrary = mkPos <$> ((+1) . abs <$> arbitrary)
arbitraryErrorFancy :: Gen (ErrorFancy e)
arbitraryErrorFancy = oneof [ ErrorFail <$> arbitrary ]
@ -72,7 +88,7 @@ spec = do
describe "betterThrow" $ do
context "when given a parse error" $
it "throws the correct exception" $
property $ forAll arbitraryParseError $ \err ->
property $ forAll arbitraryParseErrorBundle $ \err ->
betterThrow (Left err) `shouldThrow`
(== InflectionParsingFailed err)