aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/data/format/json.lux
diff options
context:
space:
mode:
authorEduardo Julian2021-09-10 03:53:29 -0400
committerEduardo Julian2021-09-10 03:53:29 -0400
commitd48270f43c404ba19ca04da2553455ecaaf2caba (patch)
tree850f3a240267fd8b944fbd221ace130c8f7b8606 /stdlib/source/library/lux/data/format/json.lux
parent343fda007c09deb70917a4afda19891cacf54504 (diff)
Adjusted new compilers to work with the new variant syntax.
Diffstat (limited to 'stdlib/source/library/lux/data/format/json.lux')
-rw-r--r--stdlib/source/library/lux/data/format/json.lux39
1 files changed, 27 insertions, 12 deletions
diff --git a/stdlib/source/library/lux/data/format/json.lux b/stdlib/source/library/lux/data/format/json.lux
index aa6ef2279..f29042a83 100644
--- a/stdlib/source/library/lux/data/format/json.lux
+++ b/stdlib/source/library/lux/data/format/json.lux
@@ -67,8 +67,19 @@
(-> (List [String JSON]) JSON)
(|>> (dictionary.of_list text.hash) #..Object))
+(type: JSON'
+ (Rec JSON'
+ (Variant
+ {#Null' Null}
+ {#Boolean' Boolean}
+ {#Number' Number}
+ {#String' String}
+ {#Array' (Row JSON')}
+ {#Object' (Dictionary String JSON')}
+ {#Code' Code})))
+
(def: jsonP
- (<code>.Parser JSON)
+ (<code>.Parser JSON')
(<>.rec
(function (_ jsonP)
($_ <>.or
@@ -80,31 +91,35 @@
(<code>.tuple (<>.some jsonP)))
(<>\each (dictionary.of_list text.hash)
(<code>.variant (<>.some (<>.and <code>.text jsonP))))
+ <code>.any
))))
(def: (jsonF token)
- (-> JSON Code)
+ (-> JSON' Code)
(case token
- {#Null _}
+ {#Null' _}
(` #..Null)
- (^template [<ctor> <json_tag>]
- [{<json_tag> value}
- (` {<json_tag> (~ (<ctor> value))})])
- ([code.bit #..Boolean]
- [code.frac #..Number]
- [code.text #..String])
+ (^template [<ctor> <input_tag> <output_tag>]
+ [{<input_tag> value}
+ (` {<output_tag> (~ (<ctor> value))})])
+ ([code.bit #..Boolean' #..Boolean]
+ [code.frac #..Number' #..Number]
+ [code.text #..String' #..String])
- {#Array members}
+ {#Array' members}
(` {#..Array ((~! row.row) (~+ (row.list (row\each jsonF members))))})
- {#Object pairs}
+ {#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))])))))))})
+
+ {#Code' code}
+ code))
(syntax: .public (json [token ..jsonP])
(in (list (` (: JSON (~ (jsonF token)))))))