From 4ca397765805eda5ddee393901ed3a02001a960a Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 25 Dec 2020 09:22:38 -0400 Subject: Replaced kebab-case with snake_case for naming convention. --- stdlib/source/lux/data/format/json.lux | 178 ++++++++++++++++----------------- 1 file changed, 89 insertions(+), 89 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 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 [ ] - [[_ ( value)] - (wrap (list (` (: JSON ( (~ ( value)))))))]) + (^template [ ] + [[_ ( value)] + (wrap (list (` (: JSON ( (~ ( 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 [ ] [(def: @@ -239,36 +239,36 @@ )] ["," 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 [ ] [( value) ( 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) (.some .space)) -(def: parse-separator +(def: parse_separator (Parser [Text Any Text]) ($_ <>.and - ..parse-space + ..parse_space (.this ..separator) - ..parse-space)) + ..parse_space)) -(def: parse-null +(def: parse_null (Parser Null) (do <>.monad [_ (.this "null")] @@ -312,17 +312,17 @@ [_ (.this )] (wrap )))] - [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? (.this "-")) @@ -333,7 +333,7 @@ (.many .decimal))) exp (<>.default "" (do ! - [mark (.one-of "eE") + [mark (.one_of "eE") signed?' (<>.parses? (.this "-")) offset (.many .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 (.this "\t") (<>\wrap text.tab)) (<>.after (.this "\b") - (<>\wrap text.back-space)) + (<>\wrap text.back_space)) (<>.after (.this "\n") - (<>\wrap text.new-line)) + (<>\wrap text.new_line)) (<>.after (.this "\r") - (<>\wrap text.carriage-return)) + (<>\wrap text.carriage_return)) (<>.after (.this "\f") - (<>\wrap text.form-feed)) - (<>.after (.this (text\compose "\" text.double-quote)) - (<>\wrap text.double-quote)) + (<>\wrap text.form_feed)) + (<>.after (.this (text\compose "\" text.double_quote)) + (<>\wrap text.double_quote)) (<>.after (.this "\\") (<>\wrap "\")))) -(def: parse-string +(def: parse_string (Parser String) - (<| (.enclosed [text.double-quote text.double-quote]) + (<| (.enclosed [text.double_quote text.double_quote]) (loop [_ []]) (do {! <>.monad} - [chars (.some (.none-of (text\compose "\" text.double-quote))) + [chars (.some (.none_of (text\compose "\" text.double_quote))) stop .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 - _ (.this ..entry-separator) - _ ..parse-space - value parse-json] + [key ..parse_string + _ ..parse_space + _ (.this ..entry_separator) + _ ..parse_space + value parse_json] (wrap [key value]))) -(template [ ] - [(def: ( parse-json) +(template [ ] + [(def: ( parse_json) (-> (Parser JSON) (Parser )) (do <>.monad [_ (.this ) - _ parse-space - elems (<>.sep-by ..parse-separator ) - _ parse-space + _ parse_space + elems (<>.sep_by ..parse_separator ) + _ parse_space _ (.this )] (wrap ( 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 (.run parse-json))) + (def: decode (.run parse_json))) -- cgit v1.2.3