diff options
author | Eduardo Julian | 2020-12-25 09:22:38 -0400 |
---|---|---|
committer | Eduardo Julian | 2020-12-25 09:22:38 -0400 |
commit | 4ca397765805eda5ddee393901ed3a02001a960a (patch) | |
tree | 2ab184a1a4e244f3a69e86c8a7bb3ad49c22b4a3 /stdlib/source/lux/data/format/json.lux | |
parent | d29e091e98dabb8dfcf816899ada480ecbf7e357 (diff) |
Replaced kebab-case with snake_case for naming convention.
Diffstat (limited to 'stdlib/source/lux/data/format/json.lux')
-rw-r--r-- | stdlib/source/lux/data/format/json.lux | 178 |
1 files changed, 89 insertions, 89 deletions
diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux index 04b7a51d1..0ac868859 100644 --- a/stdlib/source/lux/data/format/json.lux +++ b/stdlib/source/lux/data/format/json.lux @@ -1,7 +1,7 @@ (.module: {#.doc (.doc "Functionality for reading and writing values in the JSON format." "For more information, please see: http://www.json.org/")} [lux #* - ["." meta (#+ monad with-gensyms)] + ["." meta (#+ monad with_gensyms)] [abstract [equivalence (#+ Equivalence)] [codec (#+ Codec)] @@ -61,7 +61,7 @@ (def: #export object (-> (List [String JSON]) JSON) - (|>> (dictionary.from-list text.hash) #..Object)) + (|>> (dictionary.from_list text.hash) #..Object)) (syntax: #export (json token) {#.doc (doc "A simple way to produce JSON literals." @@ -75,9 +75,9 @@ (let [(^open ".") ..monad wrapper (function (_ x) (` (..json (~ x))))] (case token - (^template [<ast-tag> <ctor> <json-tag>] - [[_ (<ast-tag> value)] - (wrap (list (` (: JSON (<json-tag> (~ (<ctor> value)))))))]) + (^template [<ast_tag> <ctor> <json_tag>] + [[_ (<ast_tag> value)] + (wrap (list (` (: JSON (<json_tag> (~ (<ctor> value)))))))]) ([#.Bit code.bit #..Boolean] [#.Frac code.frac #..Number] [#.Text code.text #..String]) @@ -93,13 +93,13 @@ [pairs' (monad.map ! (function (_ [slot value]) (case slot - [_ (#.Text key-name)] - (wrap (` [(~ (code.text key-name)) (~ (wrapper value))])) + [_ (#.Text key_name)] + (wrap (` [(~ (code.text key_name)) (~ (wrapper value))])) _ (meta.fail "Wrong syntax for JSON object."))) pairs)] - (wrap (list (` (: JSON (#..Object ((~! dictionary.from-list) + (wrap (list (` (: JSON (#..Object ((~! dictionary.from_list) (~! text.hash) (list (~+ pairs'))))))))) @@ -155,11 +155,11 @@ (#try.Failure error) (#try.Failure error)))] - [get-boolean #Boolean Boolean "booleans"] - [get-number #Number Number "numbers"] - [get-string #String String "strings"] - [get-array #Array Array "arrays"] - [get-object #Object Object "objects"] + [get_boolean #Boolean Boolean "booleans"] + [get_number #Number Number "numbers"] + [get_string #String String "strings"] + [get_array #Array Array "arrays"] + [get_object #Object Object "objects"] ) (structure: #export equivalence @@ -206,17 +206,17 @@ ############################################################ ############################################################ -(def: (format-null _) +(def: (format_null _) (-> Null Text) "null") -(def: format-boolean +(def: format_boolean (-> Boolean Text) (|>> (case> #0 "false" #1 "true"))) -(def: format-number +(def: format_number (-> Number Text) (|>> (case> (^or +0.0 -0.0) "0.0" @@ -226,12 +226,12 @@ (|> raw (text.split 1) maybe.assume product.right)))))) (def: escape "\") -(def: escaped-dq (text\compose ..escape text.double-quote)) +(def: escaped_dq (text\compose ..escape text.double_quote)) -(def: format-string +(def: format_string (-> String Text) - (|>> (text.replace-all text.double-quote ..escaped-dq) - (text.enclose [text.double-quote text.double-quote]))) + (|>> (text.replace_all text.double_quote ..escaped_dq) + (text.enclose [text.double_quote text.double_quote]))) (template [<token> <name>] [(def: <name> @@ -239,36 +239,36 @@ <token>)] ["," separator] - [":" entry-separator] + [":" entry_separator] - ["[" open-array] - ["]" close-array] + ["[" open_array] + ["]" close_array] - ["{" open-object] - ["}" close-object] + ["{" open_object] + ["}" close_object] ) -(def: (format-array format) +(def: (format_array format) (-> (-> JSON Text) (-> Array Text)) (|>> (row\map format) - row.to-list - (text.join-with ..separator) - (text.enclose [..open-array ..close-array]))) + row.to_list + (text.join_with ..separator) + (text.enclose [..open_array ..close_array]))) -(def: (format-kv format [key value]) +(def: (format_kv format [key value]) (-> (-> JSON Text) (-> [String JSON] Text)) ($_ text\compose - (..format-string key) - ..entry-separator + (..format_string key) + ..entry_separator (format value) )) -(def: (format-object format) +(def: (format_object format) (-> (-> JSON Text) (-> Object Text)) (|>> dictionary.entries - (list\map (..format-kv format)) - (text.join-with ..separator) - (text.enclose [..open-object ..close-object]))) + (list\map (..format_kv format)) + (text.join_with ..separator) + (text.enclose [..open_object ..close_object]))) (def: #export (format json) (-> JSON Text) @@ -276,30 +276,30 @@ (^template [<tag> <format>] [(<tag> value) (<format> value)]) - ([#Null ..format-null] - [#Boolean ..format-boolean] - [#Number ..format-number] - [#String ..format-string] - [#Array (..format-array format)] - [#Object (..format-object format)]) + ([#Null ..format_null] + [#Boolean ..format_boolean] + [#Number ..format_number] + [#String ..format_string] + [#Array (..format_array format)] + [#Object (..format_object format)]) )) ############################################################ ############################################################ ############################################################ -(def: parse-space +(def: parse_space (Parser Text) (<text>.some <text>.space)) -(def: parse-separator +(def: parse_separator (Parser [Text Any Text]) ($_ <>.and - ..parse-space + ..parse_space (<text>.this ..separator) - ..parse-space)) + ..parse_space)) -(def: parse-null +(def: parse_null (Parser Null) (do <>.monad [_ (<text>.this "null")] @@ -312,17 +312,17 @@ [_ (<text>.this <token>)] (wrap <value>)))] - [parse-true "true" #1] - [parse-false "false" #0] + [parse_true "true" #1] + [parse_false "false" #0] ) -(def: parse-boolean +(def: parse_boolean (Parser Boolean) ($_ <>.either - ..parse-true - ..parse-false)) + ..parse_true + ..parse_false)) -(def: parse-number +(def: parse_number (Parser Number) (do {! <>.monad} [signed? (<>.parses? (<text>.this "-")) @@ -333,7 +333,7 @@ (<text>.many <text>.decimal))) exp (<>.default "" (do ! - [mark (<text>.one-of "eE") + [mark (<text>.one_of "eE") signed?' (<>.parses? (<text>.this "-")) offset (<text>.many <text>.decimal)] (wrap ($_ text\compose mark (if signed?' "-" "") offset))))] @@ -344,77 +344,77 @@ (#try.Success value) (wrap value)))) -(def: parse-escaped +(def: parse_escaped (Parser Text) ($_ <>.either (<>.after (<text>.this "\t") (<>\wrap text.tab)) (<>.after (<text>.this "\b") - (<>\wrap text.back-space)) + (<>\wrap text.back_space)) (<>.after (<text>.this "\n") - (<>\wrap text.new-line)) + (<>\wrap text.new_line)) (<>.after (<text>.this "\r") - (<>\wrap text.carriage-return)) + (<>\wrap text.carriage_return)) (<>.after (<text>.this "\f") - (<>\wrap text.form-feed)) - (<>.after (<text>.this (text\compose "\" text.double-quote)) - (<>\wrap text.double-quote)) + (<>\wrap text.form_feed)) + (<>.after (<text>.this (text\compose "\" text.double_quote)) + (<>\wrap text.double_quote)) (<>.after (<text>.this "\\") (<>\wrap "\")))) -(def: parse-string +(def: parse_string (Parser String) - (<| (<text>.enclosed [text.double-quote text.double-quote]) + (<| (<text>.enclosed [text.double_quote text.double_quote]) (loop [_ []]) (do {! <>.monad} - [chars (<text>.some (<text>.none-of (text\compose "\" text.double-quote))) + [chars (<text>.some (<text>.none_of (text\compose "\" text.double_quote))) stop <text>.peek]) (if (text\= "\" stop) (do ! - [escaped parse-escaped - next-chars (recur [])] - (wrap ($_ text\compose chars escaped next-chars))) + [escaped parse_escaped + next_chars (recur [])] + (wrap ($_ text\compose chars escaped next_chars))) (wrap chars)))) -(def: (parse-kv parse-json) +(def: (parse_kv parse_json) (-> (Parser JSON) (Parser [String JSON])) (do <>.monad - [key ..parse-string - _ ..parse-space - _ (<text>.this ..entry-separator) - _ ..parse-space - value parse-json] + [key ..parse_string + _ ..parse_space + _ (<text>.this ..entry_separator) + _ ..parse_space + value parse_json] (wrap [key value]))) -(template [<name> <type> <open> <close> <elem-parser> <prep>] - [(def: (<name> parse-json) +(template [<name> <type> <open> <close> <elem_parser> <prep>] + [(def: (<name> parse_json) (-> (Parser JSON) (Parser <type>)) (do <>.monad [_ (<text>.this <open>) - _ parse-space - elems (<>.sep-by ..parse-separator <elem-parser>) - _ parse-space + _ parse_space + elems (<>.sep_by ..parse_separator <elem_parser>) + _ parse_space _ (<text>.this <close>)] (wrap (<prep> elems))))] - [parse-array Array ..open-array ..close-array parse-json row.from-list] - [parse-object Object ..open-object ..close-object (parse-kv parse-json) (dictionary.from-list text.hash)] + [parse_array Array ..open_array ..close_array parse_json row.from_list] + [parse_object Object ..open_object ..close_object (parse_kv parse_json) (dictionary.from_list text.hash)] ) -(def: parse-json +(def: parse_json (Parser JSON) (<>.rec - (function (_ parse-json) + (function (_ parse_json) ($_ <>.or - parse-null - parse-boolean - parse-number - parse-string - (parse-array parse-json) - (parse-object parse-json))))) + parse_null + parse_boolean + parse_number + parse_string + (parse_array parse_json) + (parse_object parse_json))))) (structure: #export codec (Codec Text JSON) (def: encode ..format) - (def: decode (<text>.run parse-json))) + (def: decode (<text>.run parse_json))) |