From 21777826feb4affa53bf150588b70fc11bb92512 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 4 Mar 2020 00:38:54 -0400 Subject: Test for codec composition + adjustments to JS-generation code. --- stdlib/source/lux/data/format/json.lux | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'stdlib/source/lux/data/format/json.lux') diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux index 60d57abab..c42093710 100644 --- a/stdlib/source/lux/data/format/json.lux +++ b/stdlib/source/lux/data/format/json.lux @@ -51,6 +51,10 @@ [Object (Dictionary String JSON)] ) +(def: #export object + (-> (List [String JSON]) JSON) + (|>> (dictionary.from-list text.hash) #..Object)) + (syntax: #export (json token) {#.doc (doc "A simple way to produce JSON literals." (json #1) @@ -66,15 +70,15 @@ (^template [ ] [_ ( value)] (wrap (list (` (: JSON ( (~ ( value)))))))) - ([#.Bit code.bit #Boolean] - [#.Frac code.frac #Number] - [#.Text code.text #String]) + ([#.Bit code.bit #..Boolean] + [#.Frac code.frac #..Number] + [#.Text code.text #..String]) [_ (#.Tag ["" "null"])] - (wrap (list (` (: JSON #Null)))) + (wrap (list (` (: JSON #..Null)))) [_ (#.Tuple members)] - (wrap (list (` (: JSON (#Array ((~! row) (~+ (list@map wrapper members)))))))) + (wrap (list (` (: JSON (#..Array ((~! row) (~+ (list@map wrapper members)))))))) [_ (#.Record pairs)] (do ..monad @@ -87,7 +91,9 @@ _ (macro.fail "Wrong syntax for JSON object."))) pairs)] - (wrap (list (` (: JSON (#Object ((~! dictionary.from-list) (~! text.hash) (list (~+ pairs'))))))))) + (wrap (list (` (: JSON (#..Object ((~! dictionary.from-list) + (~! text.hash) + (list (~+ pairs'))))))))) _ (wrap (list token))))) @@ -115,7 +121,7 @@ (#try.Failure ($_ text@compose "Missing field '" key "' on object."))) _ - (#try.Failure ($_ text@compose "Cannot get field '" key "' of a non-object.")))) + (#try.Failure ($_ text@compose "Cannot get field '" key "' on a non-object.")))) (def: #export (set key value json) {#.doc "A JSON object field setter."} @@ -125,7 +131,7 @@ (#try.Success (#Object (dictionary.put key value obj))) _ - (#try.Failure ($_ text@compose "Cannot set field '" key "' of a non-object.")))) + (#try.Failure ($_ text@compose "Cannot set field '" key "' on a non-object.")))) (template [ ] [(def: #export ( key json) -- cgit v1.2.3