aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/data/format/json.lux
diff options
context:
space:
mode:
authorEduardo Julian2022-10-24 16:58:07 -0400
committerEduardo Julian2022-10-24 16:58:07 -0400
commit45c599e49ae2659331d13222948f7e755967fdf9 (patch)
tree1f1b0be2423b69562d7479fd8db9abb509aaaf7f /stdlib/source/library/lux/data/format/json.lux
parent99d196a528804b3b136ac6c45cb872a5e7c70cde (diff)
New module just for the Char type + fixes to JSON parsing.
Diffstat (limited to 'stdlib/source/library/lux/data/format/json.lux')
-rw-r--r--stdlib/source/library/lux/data/format/json.lux63
1 files changed, 35 insertions, 28 deletions
diff --git a/stdlib/source/library/lux/data/format/json.lux b/stdlib/source/library/lux/data/format/json.lux
index a5b036478..32cfd2a3e 100644
--- a/stdlib/source/library/lux/data/format/json.lux
+++ b/stdlib/source/library/lux/data/format/json.lux
@@ -360,29 +360,34 @@
offset (<text>.many <text>.decimal)]
(in (all text#composite mark (if signed?' "-" "") offset))))]
(when (f#decoded (all text#composite (if signed? "-" "") digits "." decimals exp))
- {try.#Failure message}
- (<>.failure message)
-
{try.#Success value}
- (in value))))
+ (in value)
+
+ {try.#Failure message}
+ (<>.failure message))))
(def escaped_parser
(Parser Text)
- (all <>.either
- (<>.after (<text>.this "\t")
- (<>#in text.tab))
- (<>.after (<text>.this "\b")
- (<>#in text.back_space))
- (<>.after (<text>.this "\n")
- (<>#in text.new_line))
- (<>.after (<text>.this "\r")
- (<>#in text.carriage_return))
- (<>.after (<text>.this "\f")
- (<>#in text.form_feed))
- (<>.after (<text>.this (text#composite "\" text.double_quote))
- (<>#in text.double_quote))
- (<>.after (<text>.this "\\")
- (<>#in "\"))))
+ (`` (all <>.either
+ (,, (with_template [<when> <then>]
+ [(<>.after (<text>.this <when>)
+ (<>#in <then>))]
+
+ ["\t" text.tab]
+ ["\b" text.back_space]
+ ["\n" text.new_line]
+ ["\r" text.carriage_return]
+ ["\f" text.form_feed]
+ [(text#composite "\" text.double_quote) text.double_quote]
+ ["\\" "\"]
+ ))
+ (<>.after (<text>.this "\u")
+ (|> <text>.hexadecimal!
+ (<text>.exactly! 4)
+ <text>.slice
+ (<>.codec n.hex)
+ (<>#each text.of_char)))
+ )))
(def string_parser
(Parser String)
@@ -425,15 +430,17 @@
(def json_parser
(Parser JSON)
- (<>.rec
- (function (_ json_parser)
- (all <>.or
- null_parser
- boolean_parser
- number_parser
- string_parser
- (array_parser json_parser)
- (object_parser json_parser)))))
+ (<| (<>.after ..space_parser)
+ (<>.before ..space_parser)
+ (<>.rec
+ (function (_ json_parser)
+ (all <>.or
+ null_parser
+ boolean_parser
+ number_parser
+ string_parser
+ (array_parser json_parser)
+ (object_parser json_parser))))))
(def .public codec
(Codec Text JSON)