summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-07-29 08:05:46 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-07-29 08:05:46 -0700
commitd0923800e0b2b2476ff39d8144549172b5c668cb (patch)
tree5f660647eee1ad1e469c168f07ec5353673dcf9c /tests
parent53872969cc7c6a52ff2d92b9da1bba8000c45522 (diff)
downloadtxr-d0923800e0b2b2476ff39d8144549172b5c668cb.tar.gz
txr-d0923800e0b2b2476ff39d8144549172b5c668cb.tar.bz2
txr-d0923800e0b2b2476ff39d8144549172b5c668cb.zip
parser: allow trailing commas in json, via opt-in flag.
* parser.c (read_bad_json_s): New symbol variable. (parser_common_init): Propagate value of *read-bad-json* into read_bad_json flag in parser structure. (parser_init): Initialize read_bad_json_s and register the *read-bad-json* dynamic variable. * parser.h (struct parser): New member, read_bad_json. (read_bad_json_s): Declared. * parser.y (json_val): Support an opt_comma symbol just before the closing bracket or brace. (opt_comma): New nonterminal symbol. Recognizes ',' or nothing. Error is flagged if ',' is recognized, and *read-bad-json* is nil. * y.tab.c.shipped: Updated. * tests/010/json.tl: New tests. * txr.1: Documented.
Diffstat (limited to 'tests')
-rw-r--r--tests/010/json.tl17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/010/json.tl b/tests/010/json.tl
index a7a73623..e23d36d4 100644
--- a/tests/010/json.tl
+++ b/tests/010/json.tl
@@ -133,6 +133,23 @@
(get-jsons "1 1 [2] {3:4}") (1.0 1.0 #(2.0) #H(() (3.0 4.0))))
(mtest
+ (get-json "{ , }") :error
+ (get-json "{ 1:2, }") :error
+ (get-json "{ 1:2, 3:4, }") :error
+ (get-json "[ , ]") :error
+ (get-json "[ 1, ]") :error
+ (get-json "[ 1, 2, ]") :error)
+
+(let ((*read-bad-json* t))
+ (mtest
+ (get-json "{ , }") :error
+ (get-json "{ 1:2, }") #H(() (1.0 2.0))
+ (get-json "{ 1:2, 3:4, }") #H(() (1.0 2.0) (3.0 4.0))
+ (get-json "[ , ]") :error
+ (get-json "[ 1, ]") #(1.0)
+ (get-json "[ 1, 2, ]") #(1.0 2.0)))
+
+(mtest
(with-out-string-stream (s) (put-json nil s)) "false"
(with-out-string-stream (s) (put-jsons nil s)) ""
(with-out-string-stream (s) (put-jsons '(1.0 t nil) s)) "1\ntrue\nfalse\n")