json-syntax 0.2.5.0 → 0.2.6.0
raw patch · 4 files changed
+110/−1 lines, 4 files
Files
- CHANGELOG.md +4/−0
- json-syntax.cabal +1/−1
- src/Json.hs +85/−0
- test/Main.hs +20/−0
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for json-syntax +## 0.2.6.0 -- 2023-07-26++* Add `objectFromList` and `arrayFromList`.+ ## 0.2.5.0 -- 2023-07-25 * Add `object(13|14|15|16|17)`.
json-syntax.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: json-syntax-version: 0.2.5.0+version: 0.2.6.0 synopsis: High-performance JSON parser and encoder description: This library parses JSON into a @Value@ type that is consistent with the
src/Json.hs view
@@ -39,7 +39,10 @@ , bool , text , shortText+ -- * Array Construction+ , arrayFromList -- * Object Construction+ , objectFromList , object1 , object2 , object3@@ -452,6 +455,88 @@ -- | Infix pattern synonym for 'Member'. pattern (:->) :: ShortText -> Value -> Member pattern key :-> value = Member{key,value}++-- | Construct a JSON array from a list of JSON values.+--+-- Unlike 'objectFromList', this is not currently equipped with a+-- rewrite rule.+arrayFromList :: [Value] -> Value+arrayFromList ms = Array $ PM.smallArrayFromList ms++-- | Construct a JSON object from a list of members.+--+-- Note: When the argument is a list literal with 16 or fewer elements,+-- a rewrite rule transforms this into the appropriate @objectN@ function.+-- When the argument is not a list literal, this function just calls+-- @smallArrayFromList@ on the members, which has poor performance.+objectFromList :: [Member] -> Value+objectFromList ms = Object $ PM.smallArrayFromList ms++{-# NOINLINE objectFromList #-}+{-# RULES "objectFromList/1" forall a.+ objectFromList (a : []) =+ object1 a+#-}+{-# RULES "objectFromList/2" forall a b.+ objectFromList (a : b : []) =+ object2 a b+#-}+{-# RULES "objectFromList/3" forall a b c.+ objectFromList (a : b : c : []) =+ object3 a b c+#-}+{-# RULES "objectFromList/4" forall a b c d.+ objectFromList (a : b : c : d : []) =+ object4 a b c d+#-}+{-# RULES "objectFromList/5" forall a b c d e.+ objectFromList (a : b : c : d : e : []) =+ object5 a b c d e+#-}+{-# RULES "objectFromList/6" forall a b c d e f.+ objectFromList (a : b : c : d : e : f : []) =+ object6 a b c d e f+#-}+{-# RULES "objectFromList/7" forall a b c d e f g.+ objectFromList (a : b : c : d : e : f : g : []) =+ object7 a b c d e f g+#-}+{-# RULES "objectFromList/8" forall a b c d e f g h.+ objectFromList (a : b : c : d : e : f : g : h : []) =+ object8 a b c d e f g h+#-}+{-# RULES "objectFromList/9" forall a b c d e f g h i.+ objectFromList (a : b : c : d : e : f : g : h : i : []) =+ object9 a b c d e f g h i+#-}+{-# RULES "objectFromList/10" forall a b c d e f g h i j.+ objectFromList (a : b : c : d : e : f : g : h : i : j : []) =+ object10 a b c d e f g h i j+#-}+{-# RULES "objectFromList/11" forall a b c d e f g h i j k.+ objectFromList (a : b : c : d : e : f : g : h : i : j : k : []) =+ object11 a b c d e f g h i j k+#-}+{-# RULES "objectFromList/12" forall a b c d e f g h i j k l.+ objectFromList (a : b : c : d : e : f : g : h : i : j : k : l : []) =+ object12 a b c d e f g h i j k l+#-}+{-# RULES "objectFromList/13" forall a b c d e f g h i j k l m.+ objectFromList (a : b : c : d : e : f : g : h : i : j : k : l : m : []) =+ object13 a b c d e f g h i j k l m+#-}+{-# RULES "objectFromList/14" forall a b c d e f g h i j k l m n.+ objectFromList (a : b : c : d : e : f : g : h : i : j : k : l : m : n : []) =+ object14 a b c d e f g h i j k l m n+#-}+{-# RULES "objectFromList/15" forall a b c d e f g h i j k l m n o.+ objectFromList (a : b : c : d : e : f : g : h : i : j : k : l : m : n : o : []) =+ object15 a b c d e f g h i j k l m n o+#-}+{-# RULES "objectFromList/16" forall a b c d e f g h i j k l m n o p.+ objectFromList (a : b : c : d : e : f : g : h : i : j : k : l : m : n : o : p : []) =+ object16 a b c d e f g h i j k l m n o p+#-} -- | Construct a JSON object with one member. object1 :: Member -> Value
test/Main.hs view
@@ -123,6 +123,26 @@ @=? BChunks.concat (Builder.run 4 (J.encode (J.String "It\2019s over now"))) ]+ , testGroup "objectFromList"+ [ THU.testCase "empty object" $+ J.objectFromList []+ @=?+ J.emptyObject+ , THU.testCase "one member" $+ J.objectFromList [J.Member {J.key = "one", J.value = J.String "value1"}]+ @=?+ J.object1 J.Member {J.key = "one", J.value = J.String "value1"}+ , THU.testCase "two members" $ do+ let members = [+ J.Member {J.key = "1", J.value = J.String "1"},+ J.Member {J.key = "2", J.value = J.String "2"}+ ]+ J.objectFromList members+ @=?+ J.object2+ J.Member {J.key = "1", J.value = J.String "1"}+ J.Member {J.key = "2", J.value = J.String "2"}+ ] , testGroup "smile-fragment" [ THU.testCase "biginteger-65535" $ let enc = BChunks.concat (Builder.run 128 (Smile.encodeBigInteger 65535))