diff options
Diffstat (limited to 'stdlib/source/lux/macro/poly/json.lux')
-rw-r--r-- | stdlib/source/lux/macro/poly/json.lux | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/stdlib/source/lux/macro/poly/json.lux b/stdlib/source/lux/macro/poly/json.lux index 1253ec328..f30c26437 100644 --- a/stdlib/source/lux/macro/poly/json.lux +++ b/stdlib/source/lux/macro/poly/json.lux @@ -7,6 +7,7 @@ [control ["p" parser ["<.>" type] + ["</>" json] ["l" text]]] [data ["." bit] @@ -60,11 +61,11 @@ (#/.Array (row (|> high .int int-to-frac #/.Number) (|> low .int int-to-frac #/.Number))))) (def: (decode input) - (<| (/.run input) - /.array + (<| (</>.run input) + </>.array (do p.monad - [high /.number - low /.number]) + [high </>.number + low </>.number]) (wrap (n/+ (|> high frac-to-int .nat (i64.left-shift 32)) (|> low frac-to-int .nat)))))) @@ -214,17 +215,17 @@ (wrap (` (: (~ (@JSON//decode inputT)) (~! <decoder>)))))] - [(<type>.exactly Any) /.null] - [(<type>.sub Bit) /.boolean] - [(<type>.sub Nat) (p.codec ..nat-codec /.any)] - [(<type>.sub Int) (p.codec ..int-codec /.any)] - [(<type>.sub Frac) /.number] - [(<type>.sub Text) /.string]) + [(<type>.exactly Any) </>.null] + [(<type>.sub Bit) </>.boolean] + [(<type>.sub Nat) (p.codec ..nat-codec </>.any)] + [(<type>.sub Int) (p.codec ..int-codec </>.any)] + [(<type>.sub Frac) </>.number] + [(<type>.sub Text) </>.string]) <time> (template [<type> <codec>] [(do @ [_ (<type>.exactly <type>)] (wrap (` (: (~ (@JSON//decode inputT)) - ((~! p.codec) (~! <codec>) (~! /.string))))))] + ((~! p.codec) (~! <codec>) (~! </>.string))))))] ## [duration.Duration duration.codec] ## [instant.Instant instant.codec] @@ -236,7 +237,7 @@ [*env* <type>.env #let [@JSON//decode (: (-> Type Code) (function (_ type) - (` (/.Reader (~ (poly.to-code *env* type))))))] + (` (</>.Parser (~ (poly.to-code *env* type))))))] inputT <type>.peek] ($_ p.either <basic> @@ -245,37 +246,37 @@ [unitT (<type>.apply (p.after (<type>.exactly unit.Qty) <type>.any))] (wrap (` (: (~ (@JSON//decode inputT)) - ((~! p.codec) (~! qty-codec) (~! /.any)))))) + ((~! p.codec) (~! qty-codec) (~! </>.any)))))) (do @ [[_ _ valC] (<type>.apply ($_ p.and (<type>.exactly d.Dictionary) (<type>.exactly .Text) codec//decode))] (wrap (` (: (~ (@JSON//decode inputT)) - ((~! /.dictionary) (~ valC)))))) + ((~! </>.dictionary) (~ valC)))))) (do @ [[_ subC] (<type>.apply (p.and (<type>.exactly .Maybe) codec//decode))] (wrap (` (: (~ (@JSON//decode inputT)) - ((~! /.nullable) (~ subC)))))) + ((~! </>.nullable) (~ subC)))))) (do @ [[_ subC] (<type>.apply (p.and (<type>.exactly .List) codec//decode))] (wrap (` (: (~ (@JSON//decode inputT)) - ((~! /.array) ((~! p.some) (~ subC))))))) + ((~! </>.array) ((~! p.some) (~ subC))))))) (do @ [members (<type>.variant (p.many codec//decode))] (wrap (` (: (~ (@JSON//decode inputT)) ($_ ((~! p.or)) (~+ (list@map (function (_ [tag memberC]) (` (|> (~ memberC) - ((~! p.after) ((~! /.number!) (~ (code.frac (..tag tag))))) - ((~! /.array))))) + ((~! p.after) ((~! </>.number!) (~ (code.frac (..tag tag))))) + ((~! </>.array))))) (list.enumerate members)))))))) (do @ [g!decoders (<type>.tuple (p.many codec//decode))] (wrap (` (: (~ (@JSON//decode inputT)) - ((~! /.array) ($_ ((~! p.and)) (~+ g!decoders))))))) + ((~! </>.array) ($_ ((~! p.and)) (~+ g!decoders))))))) ## Type recursion (do @ [[selfC bodyC] (<type>.recursive codec//decode) @@ -292,8 +293,8 @@ (do @ [[funcC varsC bodyC] (<type>.polymorphic codec//decode)] (wrap (` (: (All [(~+ varsC)] - (-> (~+ (list@map (|>> (~) /.Reader (`)) varsC)) - (/.Reader ((~ (poly.to-code *env* inputT)) (~+ varsC))))) + (-> (~+ (list@map (|>> (~) </>.Parser (`)) varsC)) + (</>.Parser ((~ (poly.to-code *env* inputT)) (~+ varsC))))) (function ((~ funcC) (~+ varsC)) (~ bodyC)))))) <type>.parameter @@ -325,6 +326,6 @@ (structure (def: (~' encode) (..codec//encode (~ inputT))) (def: ((~' decode) (~ g!inputs)) - ((~! /.run) (~ g!inputs) + ((~! </>.run) (~ g!inputs) (..codec//decode (~ inputT)))) ))))))) |