diff options
author | Eduardo Julian | 2021-08-24 05:23:45 -0400 |
---|---|---|
committer | Eduardo Julian | 2021-08-24 05:23:45 -0400 |
commit | 36303d6cb2ce3ab9e36d045b9516c997bd461862 (patch) | |
tree | b9d2f1495143054d61d9af129f36833624db9dac /stdlib/source/poly/lux/data/format/json.lux | |
parent | ec1f31b5a1492d5e0ab260397291d4449483bbd9 (diff) |
Outsourced the syntax for labelled type definitions to macros.
Diffstat (limited to 'stdlib/source/poly/lux/data/format/json.lux')
-rw-r--r-- | stdlib/source/poly/lux/data/format/json.lux | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/stdlib/source/poly/lux/data/format/json.lux b/stdlib/source/poly/lux/data/format/json.lux index be290d301..8de72193b 100644 --- a/stdlib/source/poly/lux/data/format/json.lux +++ b/stdlib/source/poly/lux/data/format/json.lux @@ -76,7 +76,7 @@ (def: encoded (|>> .nat (\ nat_codec encoded))) (def: decoded - (|>> (\ nat_codec decoded) (\ try.functor map .int)))) + (|>> (\ nat_codec decoded) (\ try.functor each .int)))) (def: (nullable writer) {#.doc "Builds a JSON generator for potentially inexistent values."} @@ -95,7 +95,7 @@ (\ ..int_codec encoded))) (def: decoded (|>> (\ ..int_codec decoded) - (\ try.functor map (debug.private unit.in))))) + (\ try.functor each (debug.private unit.in))))) (poly: encoded (with_expansions @@ -147,8 +147,8 @@ encoded))] (in (` (: (~ (@JSON\encoded inputT)) (|>> ((~! dictionary.entries)) - ((~! list\map) (function ((~ g!_) [(~ g!key) (~ g!val)]) - [(~ g!key) ((~ =val=) (~ g!val))])) + ((~! list\each) (function ((~ g!_) [(~ g!key) (~ g!val)]) + [(~ g!key) ((~ =val=) (~ g!val))])) ((~! dictionary.of_list) (~! text.hash)) #/.Object))))) (do ! @@ -162,7 +162,7 @@ (<type>.exactly .List) encoded))] (in (` (: (~ (@JSON\encoded inputT)) - (|>> ((~! list\map) (~ =sub=)) ((~! row.of_list)) #/.Array))))) + (|>> ((~! list\each) (~ =sub=)) ((~! row.of_list)) #/.Array))))) (do ! [.let [g!_ (code.local_identifier "_______") g!input (code.local_identifier "_______input")] @@ -171,28 +171,28 @@ (in (` (: (~ (@JSON\encoded inputT)) (function ((~ g!_) (~ g!input)) (case (~ g!input) - (~+ (list\join (list\map (function (_ [tag g!encoded]) - (if (n.= last tag) - (.list (` ((~ (code.nat (-- tag))) #1 (~ g!input))) - (` ((~! /.json) [(~ (code.frac (..tag (-- tag)))) - #1 - ((~ g!encoded) (~ g!input))]))) - (.list (` ((~ (code.nat tag)) #0 (~ g!input))) - (` ((~! /.json) [(~ (code.frac (..tag tag))) - #0 - ((~ g!encoded) (~ g!input))]))))) - (list.enumeration members)))))))))) + (~+ (list\conjoint (list\each (function (_ [tag g!encoded]) + (if (n.= last tag) + (.list (` ((~ (code.nat (-- tag))) #1 (~ g!input))) + (` ((~! /.json) [(~ (code.frac (..tag (-- tag)))) + #1 + ((~ g!encoded) (~ g!input))]))) + (.list (` ((~ (code.nat tag)) #0 (~ g!input))) + (` ((~! /.json) [(~ (code.frac (..tag tag))) + #0 + ((~ g!encoded) (~ g!input))]))))) + (list.enumeration members)))))))))) (do ! [g!encoders (<type>.tuple (<>.many encoded)) .let [g!_ (code.local_identifier "_______") g!members (|> (list.size g!encoders) list.indices - (list\map (|>> n\encoded code.local_identifier)))]] + (list\each (|>> n\encoded code.local_identifier)))]] (in (` (: (~ (@JSON\encoded inputT)) (function ((~ g!_) [(~+ g!members)]) - ((~! /.json) [(~+ (list\map (function (_ [g!member g!encoded]) - (` ((~ g!encoded) (~ g!member)))) - (list.zipped/2 g!members g!encoders)))])))))) + ((~! /.json) [(~+ (list\each (function (_ [g!member g!encoded]) + (` ((~ g!encoded) (~ g!member)))) + (list.zipped/2 g!members g!encoders)))])))))) ... Type recursion (do ! [[selfC non_recC] (<type>.recursive encoded) @@ -209,8 +209,8 @@ (do ! [[funcC varsC bodyC] (<type>.polymorphic encoded)] (in (` (: (All [(~+ varsC)] - (-> (~+ (list\map (function (_ varC) (` (-> (~ varC) /.JSON))) - varsC)) + (-> (~+ (list\each (function (_ varC) (` (-> (~ varC) /.JSON))) + varsC)) (-> ((~ (poly.code *env* inputT)) (~+ varsC)) /.JSON))) (function ((~ funcC) (~+ varsC)) @@ -282,17 +282,17 @@ .let [last (-- (list.size members))]] (in (` (: (~ (@JSON\decoded inputT)) ($_ ((~! <>.or)) - (~+ (list\map (function (_ [tag memberC]) - (if (n.= last tag) - (` (|> (~ memberC) - ((~! <>.after) ((~! </>.boolean!) (~ (code.bit #1)))) - ((~! <>.after) ((~! </>.number!) (~ (code.frac (..tag (-- tag)))))) - ((~! </>.array)))) - (` (|> (~ memberC) - ((~! <>.after) ((~! </>.boolean!) (~ (code.bit #0)))) - ((~! <>.after) ((~! </>.number!) (~ (code.frac (..tag tag))))) - ((~! </>.array)))))) - (list.enumeration members)))))))) + (~+ (list\each (function (_ [tag memberC]) + (if (n.= last tag) + (` (|> (~ memberC) + ((~! <>.after) ((~! </>.boolean!) (~ (code.bit #1)))) + ((~! <>.after) ((~! </>.number!) (~ (code.frac (..tag (-- tag)))))) + ((~! </>.array)))) + (` (|> (~ memberC) + ((~! <>.after) ((~! </>.boolean!) (~ (code.bit #0)))) + ((~! <>.after) ((~! </>.number!) (~ (code.frac (..tag tag))))) + ((~! </>.array)))))) + (list.enumeration members)))))))) (do ! [g!decoders (<type>.tuple (<>.many decoded))] (in (` (: (~ (@JSON\decoded inputT)) @@ -313,7 +313,7 @@ (do ! [[funcC varsC bodyC] (<type>.polymorphic decoded)] (in (` (: (All [(~+ varsC)] - (-> (~+ (list\map (|>> (~) </>.Parser (`)) varsC)) + (-> (~+ (list\each (|>> (~) </>.Parser (`)) varsC)) (</>.Parser ((~ (poly.code *env* inputT)) (~+ varsC))))) (function ((~ funcC) (~+ varsC)) (~ bodyC)))))) |