aeson-commit 1.1 → 1.2
raw patch · 4 files changed
+33/−14 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +5/−0
- README.md +4/−3
- aeson-commit.cabal +10/−4
- src/Data/Aeson/Commit.hs +14/−7
CHANGELOG.md view
@@ -1,5 +1,10 @@ # Changelog +## [1.2]+### [Changed]+- Reword parts of the documentation+- Add missing fields to cabal file in preparation of adding to stackage+ ## [1.1] ### [Added] - A changelog
README.md view
@@ -1,6 +1,7 @@ # aeson-commit -## Parse Aeson data with commitment+[](https://hackage.haskell.org/package/aeson-commit) -Aeson parsers backtracks too much for some use cases. The commit-parser forbids backtracking for already committed parses.+Aeson parsers backtracks too much for some use cases. `aeson-commit` provides a mechanism for preserving parser errors.++See [haddocks](https://hackage.haskell.org/package/aeson-commit/docs/Data-Aeson-Commit.html) for more information and examples.
aeson-commit.cabal view
@@ -1,22 +1,28 @@ cabal-version: >=1.10 name: aeson-commit-version: 1.1+version: 1.2 license: BSD3 copyright: 2020 Cross Compass Ltd.-maintainer: jonascarpay@gmail.com+maintainer: Jonas Carpay <jonascarpay@gmail.com>+homepage: https://github.com/xc-jp/aeson-commit#readme author:- Viktor Kronvall <viktor.kronvall@cross-compass.com>, Jonas Carpay <jonascarpay@gmail.com>+ Viktor Kronvall <viktor.kronvall@cross-compass.com>,+ Jonas Carpay <jonascarpay@gmail.com> synopsis: Parse Aeson data with commitment description: Aeson parsers backtracks too much for some use cases. The commit parser forbids backtracking for already committed parses. -category: Web+category: Text, Web, JSON build-type: Simple extra-source-files: README.md CHANGELOG.md++source-repository head+ type: git+ location: git://github.com/xc-jp/aeson-commit library exposed-modules: Data.Aeson.Commit
src/Data/Aeson/Commit.hs view
@@ -1,12 +1,12 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-|- Commitment mechanism for aeson parsers.- This is comes up when you e.g. want to make a distinction between missing keys and malformed keys.- As an example, this parser will look for a key @"nested"@, and if present try to read the embedded @"value"@, or alternatively look for a top level @"value"@:+ Commitment mechanism for aeson 'Parser'.+ This is comes up when you e.g. want to make a distinction between in error handling for missing keys and malformed keys.+ As an example, this parser will yield @nested.value@ if there the key @nested@ is present, and @value@ if it is not present. > parse o = (o .:> "nested") (withObject "nestedObj" (.: "value"))- > <|> tryParser (o .: "value")+ > <|> tryParser (o .: "value") > { value: "foo", otherField: "bar" } > -> Right "foo"@@ -27,7 +27,14 @@ > - key \"nested\" not found" -}-module Data.Aeson.Commit where+module Data.Aeson.Commit+ ( commit+ , runCommit+ , (.:>)+ , tryParser+ , liftParser+ , Commit (..)+ ) where import Control.Applicative (Alternative (..)) import Control.Monad.Except@@ -59,7 +66,7 @@ captureError :: Parser b -> Parser (Either [Parser Void] b) captureError p = Right <$> p <|> pure (Left [fmap (const undefined) p]) --- | Recommended way of turning a 'Commit' back into a regular 'Parser'.+-- | Turn a 'Commit' back into a regular 'Parser'. runCommit :: Commit a -> Parser a runCommit (Commit f) = runExceptT f >>= either handleErrors pure where@@ -81,7 +88,7 @@ (.:>) :: FromJSON a => Object -> Text -> (a -> Parser b) -> Commit b (o .:> k) cont = commit (o .: k) (\v -> cont v <?> Key k) --- | Try to parse with a 'Parser' and commit if it parses successfully.+-- | Turn a 'Parser' into a 'Commit' -- Unlike 'liftParser', the parser's failure is recoverable. -- -- > tryParser empty <|> p = p