aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/data/format/json.lux
diff options
context:
space:
mode:
authorEduardo Julian2021-09-10 01:21:23 -0400
committerEduardo Julian2021-09-10 01:21:23 -0400
commitcd71a864ad5be13ed6ec6d046e0a2cb1087bdf94 (patch)
treeaf6366578f98f1a8e551f4da9f3ad230fd63a4dd /stdlib/source/library/lux/data/format/json.lux
parentef77466323f85a3d1b65b46a3deb93652ef22085 (diff)
Migrated variants to the new syntax.
Diffstat (limited to 'stdlib/source/library/lux/data/format/json.lux')
-rw-r--r--stdlib/source/library/lux/data/format/json.lux76
1 files changed, 38 insertions, 38 deletions
diff --git a/stdlib/source/library/lux/data/format/json.lux b/stdlib/source/library/lux/data/format/json.lux
index 052ce1c18..aa6ef2279 100644
--- a/stdlib/source/library/lux/data/format/json.lux
+++ b/stdlib/source/library/lux/data/format/json.lux
@@ -43,12 +43,12 @@
(type: .public JSON
(Rec JSON
(Variant
- (#Null Null)
- (#Boolean Boolean)
- (#Number Number)
- (#String String)
- (#Array (Row JSON))
- (#Object (Dictionary String JSON)))))
+ {#Null Null}
+ {#Boolean Boolean}
+ {#Number Number}
+ {#String String}
+ {#Array (Row JSON)}
+ {#Object (Dictionary String JSON)})))
(template [<name> <type>]
[(type: .public <name>
@@ -85,26 +85,26 @@
(def: (jsonF token)
(-> JSON Code)
(case token
- (#Null _)
+ {#Null _}
(` #..Null)
(^template [<ctor> <json_tag>]
- [(<json_tag> value)
- (` (<json_tag> (~ (<ctor> value))))])
+ [{<json_tag> value}
+ (` {<json_tag> (~ (<ctor> value))})])
([code.bit #..Boolean]
[code.frac #..Number]
[code.text #..String])
- (#Array members)
- (` (#..Array ((~! row.row) (~+ (row.list (row\each jsonF members))))))
+ {#Array members}
+ (` {#..Array ((~! row.row) (~+ (row.list (row\each jsonF members))))})
- (#Object pairs)
- (` (#..Object ((~! dictionary.of_list)
+ {#Object pairs}
+ (` {#..Object ((~! dictionary.of_list)
(~! text.hash)
(list (~+ (|> pairs
dictionary.entries
(list\each (function (_ [key_name value])
- (` [(~ (code.text key_name)) (~ (jsonF value))])))))))))))
+ (` [(~ (code.text key_name)) (~ (jsonF value))])))))))})))
(syntax: .public (json [token ..jsonP])
(in (list (` (: JSON (~ (jsonF token)))))))
@@ -112,47 +112,47 @@
(def: .public (fields json)
(-> JSON (Try (List String)))
(case json
- (#Object obj)
- (#try.Success (dictionary.keys obj))
+ {#Object obj}
+ {#try.Success (dictionary.keys obj)}
_
- (#try.Failure ($_ text\composite "Cannot get the fields of a non-object."))))
+ {#try.Failure ($_ text\composite "Cannot get the fields of a non-object.")}))
(def: .public (field key json)
(-> String JSON (Try JSON))
(case json
- (#Object obj)
+ {#Object obj}
(case (dictionary.value key obj)
- (#.Some value)
- (#try.Success value)
+ {#.Some value}
+ {#try.Success value}
#.None
- (#try.Failure ($_ text\composite "Missing field '" key "' on object.")))
+ {#try.Failure ($_ text\composite "Missing field '" key "' on object.")})
_
- (#try.Failure ($_ text\composite "Cannot get field '" key "' on a non-object."))))
+ {#try.Failure ($_ text\composite "Cannot get field '" key "' on a non-object.")}))
(def: .public (has key value json)
(-> String JSON JSON (Try JSON))
(case json
- (#Object obj)
- (#try.Success (#Object (dictionary.has key value obj)))
+ {#Object obj}
+ {#try.Success {#Object (dictionary.has key value obj)}}
_
- (#try.Failure ($_ text\composite "Cannot set field '" key "' on a non-object."))))
+ {#try.Failure ($_ text\composite "Cannot set field '" key "' on a non-object.")}))
(template [<name> <tag> <type>]
[(def: .public (<name> key json)
(-> Text JSON (Try <type>))
(case (field key json)
- (#try.Success (<tag> value))
- (#try.Success value)
+ {#try.Success {<tag> value}}
+ {#try.Success value}
- (#try.Success _)
- (#try.Failure ($_ text\composite "Wrong value type at key: " key))
+ {#try.Success _}
+ {#try.Failure ($_ text\composite "Wrong value type at key: " key)}
- (#try.Failure error)
- (#try.Failure error)))]
+ {#try.Failure error}
+ {#try.Failure error}))]
[boolean_field #Boolean Boolean]
[number_field #Number Number]
@@ -170,13 +170,13 @@
#1
(^template [<tag> <struct>]
- [[(<tag> x') (<tag> y')]
+ [[{<tag> x'} {<tag> y'}]
(\ <struct> = x' y')])
([#Boolean bit.equivalence]
[#Number f.equivalence]
[#String text.equivalence])
- [(#Array xs) (#Array ys)]
+ [{#Array xs} {#Array ys}]
(and (n.= (row.size xs) (row.size ys))
(list\mix (function (_ idx prev)
(and prev
@@ -188,13 +188,13 @@
#1
(list.indices (row.size xs))))
- [(#Object xs) (#Object ys)]
+ [{#Object xs} {#Object ys}]
(and (n.= (dictionary.size xs) (dictionary.size ys))
(list\mix (function (_ [xk xv] prev)
(and prev
(case (dictionary.value xk ys)
#.None #0
- (#.Some yv) (= xv yv))))
+ {#.Some yv} (= xv yv))))
#1
(dictionary.entries xs)))
@@ -273,7 +273,7 @@
(-> JSON Text)
(case json
(^template [<tag> <format>]
- [(<tag> value)
+ [{<tag> value}
(<format> value)])
([#Null ..null_format]
[#Boolean ..boolean_format]
@@ -337,10 +337,10 @@
offset (<text>.many <text>.decimal)]
(in ($_ text\composite mark (if signed?' "-" "") offset))))]
(case (f\decoded ($_ text\composite (if signed? "-" "") digits "." decimals exp))
- (#try.Failure message)
+ {#try.Failure message}
(<>.failure message)
- (#try.Success value)
+ {#try.Success value}
(in value))))
(def: escaped_parser