aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/poly/lux/data/format/json.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/poly/lux/data/format/json.lux85
1 files changed, 40 insertions, 45 deletions
diff --git a/stdlib/source/poly/lux/data/format/json.lux b/stdlib/source/poly/lux/data/format/json.lux
index d8eecd816..c4cae2881 100644
--- a/stdlib/source/poly/lux/data/format/json.lux
+++ b/stdlib/source/poly/lux/data/format/json.lux
@@ -4,8 +4,7 @@
[lux #*
["." debug]
[abstract
- [monad (#+ Monad do)]
- [equivalence (#+ Equivalence)]
+ [monad (#+ do)]
["." codec]]
[control
["." try]
@@ -13,26 +12,22 @@
["<.>" type]
["</>" json]]]
[data
- ["." bit]
- maybe
- ["." sum]
- ["." product]
- ["." text ("#\." equivalence)
+ ["." text
["%" format (#+ format)]]
[collection
- ["." list ("#\." fold monad)]
- ["." row (#+ Row row) ("#\." monad)]
- ["d" dictionary]]]
+ ["." list ("#\." monad)]
+ ["." row (#+ row)]
+ ["." dictionary]]]
[macro
[syntax (#+ syntax:)]
["." code]
["." poly (#+ poly:)]]
[math
[number
- ["." i64]
["n" nat ("#\." decimal)]
+ ["." i64]
["." int]
- ["." frac ("#\." decimal)]]]
+ ["." frac]]]
[time
## ["." instant]
## ["." duration]
@@ -104,7 +99,7 @@
(with_expansions
[<basic> (template [<matcher> <encoder>]
[(do !
- [#let [g!_ (code.local_identifier "_______")]
+ [.let [g!_ (code.local_identifier "_______")]
_ <matcher>]
(in (` (: (~ (@JSON\encode inputT))
<encoder>))))]
@@ -128,9 +123,9 @@
[month.Month month.codec])]
(do {! <>.monad}
[*env* <type>.env
- #let [@JSON\encode (: (-> Type Code)
+ .let [@JSON\encode (: (-> Type Code)
(function (_ type)
- (` (-> (~ (poly.to_code *env* type)) /.JSON))))]
+ (` (-> (~ (poly.code *env* type)) /.JSON))))]
inputT <type>.peek]
($_ <>.either
<basic>
@@ -141,18 +136,18 @@
(in (` (: (~ (@JSON\encode inputT))
(\ (~! qty_codec) (~' encode))))))
(do !
- [#let [g!_ (code.local_identifier "_______")
+ [.let [g!_ (code.local_identifier "_______")
g!key (code.local_identifier "_______key")
g!val (code.local_identifier "_______val")]
[_ _ =val=] (<type>.applied ($_ <>.and
- (<type>.exactly d.Dictionary)
+ (<type>.exactly dictionary.Dictionary)
(<type>.exactly .Text)
encode))]
(in (` (: (~ (@JSON\encode inputT))
- (|>> ((~! d.entries))
+ (|>> ((~! dictionary.entries))
((~! list\map) (function ((~ g!_) [(~ g!key) (~ g!val)])
[(~ g!key) ((~ =val=) (~ g!val))]))
- ((~! d.of_list) (~! text.hash))
+ ((~! dictionary.of_list) (~! text.hash))
#/.Object)))))
(do !
[[_ =sub=] (<type>.applied ($_ <>.and
@@ -167,27 +162,27 @@
(in (` (: (~ (@JSON\encode inputT))
(|>> ((~! list\map) (~ =sub=)) ((~! row.of_list)) #/.Array)))))
(do !
- [#let [g!_ (code.local_identifier "_______")
+ [.let [g!_ (code.local_identifier "_______")
g!input (code.local_identifier "_______input")]
members (<type>.variant (<>.many encode))
- #let [last (dec (list.size members))]]
+ .let [last (dec (list.size members))]]
(in (` (: (~ (@JSON\encode inputT))
(function ((~ g!_) (~ g!input))
(case (~ g!input)
(~+ (list\join (list\map (function (_ [tag g!encode])
(if (n.= last tag)
- (list (` ((~ (code.nat (dec tag))) #1 (~ g!input)))
- (` ((~! /.json) [(~ (code.frac (..tag (dec tag))))
- #1
- ((~ g!encode) (~ g!input))])))
- (list (` ((~ (code.nat tag)) #0 (~ g!input)))
- (` ((~! /.json) [(~ (code.frac (..tag tag)))
- #0
- ((~ g!encode) (~ g!input))])))))
+ (.list (` ((~ (code.nat (dec tag))) #1 (~ g!input)))
+ (` ((~! /.json) [(~ (code.frac (..tag (dec tag))))
+ #1
+ ((~ g!encode) (~ g!input))])))
+ (.list (` ((~ (code.nat tag)) #0 (~ g!input)))
+ (` ((~! /.json) [(~ (code.frac (..tag tag)))
+ #0
+ ((~ g!encode) (~ g!input))])))))
(list.enumeration members))))))))))
(do !
[g!encoders (<type>.tuple (<>.many encode))
- #let [g!_ (code.local_identifier "_______")
+ .let [g!_ (code.local_identifier "_______")
g!members (|> (list.size g!encoders)
list.indices
(list\map (|>> n\encode code.local_identifier)))]]
@@ -199,7 +194,7 @@
## Type recursion
(do !
[[selfC non_recC] (<type>.recursive encode)
- #let [g! (code.local_identifier "____________")]]
+ .let [g! (code.local_identifier "____________")]]
(in (` (: (~ (@JSON\encode inputT))
((~! ..rec_encode) (.function ((~ g!) (~ selfC))
(~ non_recC)))))))
@@ -214,7 +209,7 @@
(in (` (: (All [(~+ varsC)]
(-> (~+ (list\map (function (_ varC) (` (-> (~ varC) /.JSON)))
varsC))
- (-> ((~ (poly.to_code *env* inputT)) (~+ varsC))
+ (-> ((~ (poly.code *env* inputT)) (~+ varsC))
/.JSON)))
(function ((~ funcC) (~+ varsC))
(~ bodyC))))))
@@ -251,9 +246,9 @@
[month.Month month.codec])]
(do {! <>.monad}
[*env* <type>.env
- #let [@JSON\decode (: (-> Type Code)
+ .let [@JSON\decode (: (-> Type Code)
(function (_ type)
- (` (</>.Parser (~ (poly.to_code *env* type))))))]
+ (` (</>.Parser (~ (poly.code *env* type))))))]
inputT <type>.peek]
($_ <>.either
<basic>
@@ -265,7 +260,7 @@
((~! <>.codec) (~! qty_codec) (~! </>.any))))))
(do !
[[_ _ valC] (<type>.applied ($_ <>.and
- (<type>.exactly d.Dictionary)
+ (<type>.exactly dictionary.Dictionary)
(<type>.exactly .Text)
decode))]
(in (` (: (~ (@JSON\decode inputT))
@@ -282,7 +277,7 @@
((~! </>.array) ((~! <>.some) (~ subC)))))))
(do !
[members (<type>.variant (<>.many decode))
- #let [last (dec (list.size members))]]
+ .let [last (dec (list.size members))]]
(in (` (: (~ (@JSON\decode inputT))
($_ ((~! <>.or))
(~+ (list\map (function (_ [tag memberC])
@@ -303,7 +298,7 @@
## Type recursion
(do !
[[selfC bodyC] (<type>.recursive decode)
- #let [g! (code.local_identifier "____________")]]
+ .let [g! (code.local_identifier "____________")]]
(in (` (: (~ (@JSON\decode inputT))
((~! <>.rec) (.function ((~ g!) (~ selfC))
(~ bodyC)))))))
@@ -317,7 +312,7 @@
[[funcC varsC bodyC] (<type>.polymorphic decode)]
(in (` (: (All [(~+ varsC)]
(-> (~+ (list\map (|>> (~) </>.Parser (`)) varsC))
- (</>.Parser ((~ (poly.to_code *env* inputT)) (~+ varsC)))))
+ (</>.Parser ((~ (poly.code *env* inputT)) (~+ varsC)))))
(function ((~ funcC) (~+ varsC))
(~ bodyC))))))
<type>.parameter
@@ -344,10 +339,10 @@
#dictionary (Dictionary Text Frac)})
(derived: (..codec Record)))}
- (in (list (` (: (codec.Codec /.JSON (~ inputT))
- (implementation
- (def: (~' encode)
- ((~! ..encode) (~ inputT)))
- (def: (~' decode)
- ((~! </>.run) ((~! ..decode) (~ inputT))))
- ))))))
+ (in (.list (` (: (codec.Codec /.JSON (~ inputT))
+ (implementation
+ (def: (~' encode)
+ ((~! ..encode) (~ inputT)))
+ (def: (~' decode)
+ ((~! </>.run) ((~! ..decode) (~ inputT))))
+ ))))))