diff options
Diffstat (limited to 'stdlib/source/lux/data/format/json.lux')
-rw-r--r-- | stdlib/source/lux/data/format/json.lux | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux index 8f664d6ea..ddc2b48cf 100644 --- a/stdlib/source/lux/data/format/json.lux +++ b/stdlib/source/lux/data/format/json.lux @@ -11,7 +11,7 @@ (text ["l" lexer]) [number "frac/" Codec<Text,Frac> "nat/" Codec<Text,Nat>] [maybe] - ["E" error] + ["e" error] [sum] [product] (coll [list "list/" Fold<List> Monad<List>] @@ -96,52 +96,52 @@ (def: #export (get-fields json) {#;doc "Get all the fields in a JSON object."} - (-> JSON (E;Error (List String))) + (-> JSON (e;Error (List String))) (case json (#Object obj) - (#E;Success (dict;keys obj)) + (#e;Success (dict;keys obj)) _ - (#E;Error ($_ text/compose "Cannot get the fields of a non-object.")))) + (#e;Error ($_ text/compose "Cannot get the fields of a non-object.")))) (def: #export (get key json) {#;doc "A JSON object field getter."} - (-> String JSON (E;Error JSON)) + (-> String JSON (e;Error JSON)) (case json (#Object obj) (case (dict;get key obj) (#;Some value) - (#E;Success value) + (#e;Success value) #;None - (#E;Error ($_ text/compose "Missing field \"" key "\" on object."))) + (#e;Error ($_ text/compose "Missing field \"" key "\" on object."))) _ - (#E;Error ($_ text/compose "Cannot get field \"" key "\" of a non-object.")))) + (#e;Error ($_ text/compose "Cannot get field \"" key "\" of a non-object.")))) (def: #export (set key value json) {#;doc "A JSON object field setter."} - (-> String JSON JSON (E;Error JSON)) + (-> String JSON JSON (e;Error JSON)) (case json (#Object obj) - (#E;Success (#Object (dict;put key value obj))) + (#e;Success (#Object (dict;put key value obj))) _ - (#E;Error ($_ text/compose "Cannot set field \"" key "\" of a non-object.")))) + (#e;Error ($_ text/compose "Cannot set field \"" key "\" of a non-object.")))) (do-template [<name> <tag> <type> <desc>] [(def: #export (<name> key json) {#;doc (code;text ($_ text/compose "A JSON object field getter for " <desc> "."))} - (-> Text JSON (E;Error <type>)) + (-> Text JSON (e;Error <type>)) (case (get key json) - (#E;Success (<tag> value)) - (#E;Success value) + (#e;Success (<tag> value)) + (#e;Success value) - (#E;Success _) - (#E;Error ($_ text/compose "Wrong value type at key: " key)) + (#e;Success _) + (#e;Error ($_ text/compose "Wrong value type at key: " key)) - (#E;Error error) - (#E;Error error)))] + (#e;Error error) + (#e;Error error)))] [get-boolean #Boolean Boolean "booleans"] [get-number #Number Number "numbers"] @@ -195,23 +195,23 @@ (def: unconsumed-input-error Text "Unconsumed JSON.") (def: #export (run json parser) - (All [a] (-> JSON (Reader a) (E;Error a))) + (All [a] (-> JSON (Reader a) (e;Error a))) (case (p;run (list json) parser) - (#E;Success [remainder output]) + (#e;Success [remainder output]) (case remainder #;Nil - (#E;Success output) + (#e;Success output) _ - (#E;Error unconsumed-input-error)) + (#e;Error unconsumed-input-error)) - (#E;Error error) - (#E;Error error))) + (#e;Error error) + (#e;Error error))) (def: #export (fail error) (All [a] (-> Text (Reader a))) (function [inputs] - (#E;Error error))) + (#e;Error error))) (def: #export any {#;doc "Just returns the JSON input without applying any logic."} @@ -219,10 +219,10 @@ (<| (function [inputs]) (case inputs #;Nil - (#E;Error "Empty JSON stream.") + (#e;Error "Empty JSON stream.") (#;Cons head tail) - (#E;Success [tail head])))) + (#e;Success [tail head])))) (do-template [<name> <type> <tag> <desc>] [(def: #export <name> @@ -289,10 +289,10 @@ (case head (#Array values) (case (p;run (sequence;to-list values) parser) - (#E;Error error) + (#e;Error error) (fail error) - (#E;Success [remainder output]) + (#e;Success [remainder output]) (case remainder #;Nil (wrap output) @@ -310,7 +310,7 @@ [head any] (case head (#Object object) - (case (do E;Monad<Error> + (case (do e;Monad<Error> [] (|> (dict;entries object) (monad;map @ (function [[key val]] @@ -318,10 +318,10 @@ [val (run val parser)] (wrap [key val])))) (:: @ map (dict;from-list text;Hash<Text>)))) - (#E;Success table) + (#e;Success table) (wrap table) - (#E;Error error) + (#e;Error error) (fail error)) _ @@ -337,13 +337,13 @@ (case (dict;get field-name object) (#;Some value) (case (run value parser) - (#E;Success output) + (#e;Success output) (function [tail] - (#E;Success [(#;Cons (#Object (dict;remove field-name object)) + (#e;Success [(#;Cons (#Object (dict;remove field-name object)) tail) output])) - (#E;Error error) + (#e;Error error) (fail error)) _ @@ -438,10 +438,10 @@ offset (l;many l;decimal)] (wrap ($_ text/compose mark (if signed?' "-" "") offset))))] (case (frac/decode ($_ text/compose (if signed? "-" "") digits "." decimals exp)) - (#E;Error message) + (#e;Error message) (p;fail message) - (#E;Success value) + (#e;Success value) (wrap value)))) (def: escaped~ |