JsonGrammar 0.3.1 → 0.3.2
raw patch · 2 files changed
+23/−17 lines, 2 filesdep +hashabledep +unordered-containersdep ~aesondep ~attoparsecdep ~base
Dependencies added: hashable, unordered-containers
Dependency ranges changed: aeson, attoparsec, base, semigroups, template-haskell, vector
Files
- JsonGrammar.cabal +11/−9
- Language/JsonGrammar.hs +12/−8
JsonGrammar.cabal view
@@ -1,5 +1,5 @@ Name: JsonGrammar-Version: 0.3.1+Version: 0.3.2 Synopsis: Combinators for bidirectional JSON parsing Description: Combinators for bidirectional JSON parsing @@ -7,7 +7,7 @@ Author: Martijn van Steenbergen Maintainer: martijn@van.steenbergen.nl Stability: Experimental-Copyright: Some Rights Reserved (CC) 2010 Martijn van Steenbergen+Copyright: Some Rights Reserved (CC) 2010-2011 Martijn van Steenbergen Homepage: https://github.com/MedeaMelana/JsonGrammar Bug-reports: https://github.com/MedeaMelana/JsonGrammar/issues @@ -25,17 +25,19 @@ Data.Iso.TH, Data.Iso.Common, Language.JsonGrammar- Build-Depends: base >= 3.0 && < 4.5,+ Build-Depends: base >= 3.0 && < 4.6, containers >= 0.3 && < 0.5,- aeson >= 0.3 && < 0.4,- semigroups >= 0.5 && < 0.6,- template-haskell >= 2.4 && < 2.7,- -- constraints copied from aeson-0.3.2.5:- attoparsec >= 0.8.5.3,+ aeson >= 0.6 && < 0.7,+ semigroups >= 0.5 && < 0.9,+ template-haskell >= 2.4 && < 2.8,+ -- constraints copied from aeson-0.6.0.0:+ attoparsec >= 0.8.6.1, bytestring,+ hashable >= 1.1.2.0, text >= 0.11.0.2, time,- vector >= 0.7+ unordered-containers >= 0.1.3.0,+ vector >= 0.7.1 Source-Repository head Type: git
Language/JsonGrammar.hs view
@@ -21,11 +21,12 @@ import Data.Attoparsec.Number import Data.ByteString (ByteString) import qualified Data.ByteString.Lazy as Lazy+import Data.Hashable (Hashable) import Data.Int-import Data.IntSet+import Data.IntSet (IntSet) import Data.Iso hiding (option)-import qualified Data.Map as M-import Data.Maybe (fromMaybe)+import qualified Data.HashMap.Lazy as M+import Data.Maybe (fromMaybe, isJust) import Data.String import Data.Text (Text) import qualified Data.Text.Lazy as Lazy@@ -90,8 +91,7 @@ >>> inverse nil -- t2 -- | Describe a single array element with the given grammar.-elementBy :: Iso (Value :- t) (a :- t) ->- Iso ([Value] :- t) ([Value] :- a :- t)+elementBy :: Iso (Value :- t1) t2 -> Iso ([Value] :- t1) ([Value] :- t2) elementBy g = inverse cons -- Value :- [Value] :- t >>> swap -- [Value] :- Value :- t >>> duck g -- [Value] :- a :- t@@ -115,7 +115,7 @@ value <- M.lookup textName o return (M.delete textName o :- value :- r) to (o :- value :- r) = do- guard (M.notMember textName o)+ guard (notMember textName o) return (M.insert textName value o :- r) -- | Expect a specific key/value pair.@@ -128,11 +128,15 @@ guard (value' == value) return (M.delete textName o) to o = do- guard (M.notMember textName o)+ guard (notMember textName o) return (M.insert textName value o) +-- Defined in Data.Map but not in Data.HashMap.Lazy:+notMember :: (Eq k, Hashable k) => k -> M.HashMap k v -> Bool+notMember k m = isJust (M.lookup k m)+ -- | Collect all properties left in an object.-rest :: Iso (Object :- t) (Object :- M.Map Text Value :- t)+rest :: Iso (Object :- t) (Object :- M.HashMap Text Value :- t) rest = lit M.empty -- | Match and discard all properties left in the object. When converting back to JSON, produces no properties.