Completed json-alt split.

This commit is contained in:
Michal J. Gajda 2018-11-27 20:14:48 +01:00
parent db86a7a985
commit 3bc007813a
23 changed files with 43 additions and 80 deletions

View File

@ -18,13 +18,18 @@ cache:
- cabal --version
- ghc --version
- cabal update
- cd json-alt
- cabal install
- cabal sdist --builddir=../sdist/
- cabal haddock --builddir=../hackage-docs/ --for-hackage
- cd ../json-autotype
- "sed --in-place 's/-- STATIC: //' json-autotype.cabal"
- cabal install --only-dependencies --enable-tests --enable-benchmarks
- cabal test
- mkdir -p bin sdist
- cabal install --bindir=bin/
- cabal sdist --builddir=sdist/
- cabal haddock --builddir hackage-docs --for-hackage
- cabal install --bindir=../bin/
- cabal sdist --builddir=../sdist/
- cabal haddock --builddir=../hackage-docs --for-hackage
build_8_6_2:
variables:
@ -32,6 +37,8 @@ build_8_6_2:
extends: .build_exe
artifacts:
paths:
- sdist/json-alt-*[0-9].tar.gz
- hackage-docs/json-alt-*-docs.tar.gz
- sdist/json-autotype-*[0-9].tar.gz
- hackage-docs/json-autotype-*-docs.tar.gz
- bin/json-autotype
@ -76,7 +83,7 @@ test_distribution:
- build_8_6_2
artifacts:
paths:
- bin/json-autotype
- json-autotype/bin/json-autotype
stack_build:
image: migamake/haskell-build:8.6.2
@ -88,9 +95,20 @@ stack_build:
- stack test
allow_failure: true
pier_build:
image: migamake/haskell-build:8.6.2
stage: build
script:
- pier --version
- pier build
- pier test
allow_failure: true
release_to_hackage:
stage: release
script:
- cabal upload --username="$HACKAGE_USER" --password="$HACKAGE_PASSWORD" sdist/json-alt-*[0-9].tar.gz
- cabal upload --username="$HACKAGE_USER" --password="$HACKAGE_PASSWORD" -d hackage-docs/json-alt-*-docs.tar.gz
- cabal upload --username="$HACKAGE_USER" --password="$HACKAGE_PASSWORD" sdist/json-autotype-*[0-9].tar.gz
- cabal upload --username="$HACKAGE_USER" --password="$HACKAGE_PASSWORD" -d hackage-docs/json-autotype-*-docs.tar.gz
dependencies:

View File

@ -73,18 +73,5 @@ library
DeriveGeneric,
RecordWildCards
build-depends: base >=4.3 && <5,
GenericPretty >=1.2 && <1.3,
aeson >=1.2.1 && <1.5,
containers >=0.3 && <0.7,
filepath >=1.3 && <1.5,
hashable >=1.2 && <1.3,
lens >=4.1 && <4.18,
mtl >=2.1 && <2.3,
pretty >=1.1 && <1.3,
process >=1.1 && <1.7,
scientific >=0.3 && <0.5,
text >=1.1 && <1.4,
uniplate >=1.6 && <1.7,
unordered-containers >=0.2 && <0.3,
vector >=0.9 && <0.13
aeson >=1.2.1 && <1.5
default-language: Haskell2010

View File

@ -1,48 +0,0 @@
{-# LANGUAGE TypeOperators #-}
-- | This module defines data type (a :|: b) that behaves all like @Either@,
-- except that has no tag in JSON representation as used by @FromJSON@ and @ToJSON@.
module Data.Aeson.AutoType.Alternative(
(:|:)(..)
, toEither, fromEither
, alt
) where
import Data.Aeson
import Control.Applicative
-- | Data type (a :|: b) that behaves all like @Either@,
-- except that has no tag in JSON representation as used by @FromJSON@ and @ToJSON@.
data a :|: b = AltLeft a
| AltRight b
deriving(Show,Eq,Ord)
infixr 5 :|:
-- | Convert to @Either@ datatype.
toEither :: a :|: b -> Either a b
toEither (AltLeft a) = Left a
toEither (AltRight b) = Right b
{-# INLINE toEither #-}
-- | Convert from @Either@ datatype.
fromEither :: Either a b -> a :|: b
fromEither (Left a) = AltLeft a
fromEither (Right b) = AltRight b
{-# INLINE fromEither #-}
-- | Deconstruct the type with two functions corresponding to constructors.
-- This is like @either@.
alt :: (a -> c) -> (b -> c) -> a :|: b -> c
alt f _ (AltLeft a) = f a
alt _ g (AltRight b) = g b
infixr 5 `alt`
instance (ToJSON a, ToJSON b) => ToJSON (a :|: b) where
toJSON (AltLeft a) = toJSON a
toJSON (AltRight b) = toJSON b
{-# INLINE toJSON #-}
instance (FromJSON a, FromJSON b) => FromJSON (a :|: b) where
parseJSON input = (AltLeft <$> parseJSON input) <|>
(AltRight <$> parseJSON input) <|>
fail ("Neither alternative was found for: " ++ show input)
{-# INLINE parseJSON #-}

View File

@ -5,6 +5,7 @@ Changelog
* Hide all API beside Alternative (as unused outside generator).
* Add fixity for alt (#20)
* Use `eitherDecode` instead of `decode` to get better error messages.
* Split Data.Aeson.AutoType.Alternative to `json-alt`.
2.0.2 Nov 2018
* Clean up the tests.

View File

@ -64,20 +64,20 @@ source-repository head
location: https://github.com/mgajda/json-autotype.git
library
exposed-modules: Data.Aeson.AutoType.Alternative
Data.Aeson.AutoType.Pretty
Data.Aeson.AutoType.Type
Data.Aeson.AutoType.Test
Data.Aeson.AutoType.Extract
Data.Aeson.AutoType.Format
Data.Aeson.AutoType.Split
Data.Aeson.AutoType.CodeGen
exposed-modules: Data.Aeson.AutoType.CodeGen
Data.Aeson.AutoType.CodeGen.Generic
Data.Aeson.AutoType.CodeGen.Haskell
Data.Aeson.AutoType.CodeGen.Elm
Data.Aeson.AutoType.CodeGen.HaskellFormat
Data.Aeson.AutoType.CodeGen.ElmFormat
Data.Aeson.AutoType.Extract
Data.Aeson.AutoType.Format
Data.Aeson.AutoType.Pretty
Data.Aeson.AutoType.Split
Data.Aeson.AutoType.Type
Data.Aeson.AutoType.Test
Data.Aeson.AutoType.Util
hs-source-dirs: src
other-extensions: TemplateHaskell,
ScopedTypeVariables,
@ -102,11 +102,15 @@ library
uniplate >=1.6 && <1.7,
unordered-containers >=0.2 && <0.3,
vector >=0.9 && <0.13,
json-alt
smallcheck >=1.0 && <1.2,
QuickCheck >=2.4 && <3.0,
json-alt,
template-haskell
default-language: Haskell2010
executable json-autotype
main-is: GenerateJSONParser.hs
hs-source-dirs: app common
other-modules: CommonCLI
Paths_json_autotype
other-extensions: TemplateHaskell,
@ -147,7 +151,8 @@ executable json-autotype
-- and extracted types.
test-suite json-autotype-qc-test
type: exitcode-stdio-1.0
main-is: test/TestQC.hs
main-is: TestQC.hs
hs-source-dirs: test common
other-extensions: TemplateHaskell,
ScopedTypeVariables,
OverloadedStrings,
@ -173,13 +178,13 @@ test-suite json-autotype-qc-test
QuickCheck >=2.4 && <3.0,
json-autotype,
json-alt
-- hs-source-dirs:
default-language: Haskell2010
test-suite json-autotype-examples
type: exitcode-stdio-1.0
main-is: test/TestExamples.hs
main-is: TestExamples.hs
other-modules: CommonCLI
hs-source-dirs: test common
other-extensions: TemplateHaskell,
ScopedTypeVariables,
@ -217,7 +222,8 @@ test-suite json-autotype-examples
test-suite json-autotype-gen-test
type: exitcode-stdio-1.0
main-is: GenerateTestJSON.hs
other-modules: CommonCLI
hs-source-dirs: test common
other-modules: CommonCLI
other-extensions: TemplateHaskell,
ScopedTypeVariables,
@ -250,5 +256,4 @@ test-suite json-autotype-gen-test
template-haskell,
json-autotype,
json-alt
-- hs-source-dirs:
default-language: Haskell2010