[Nickle] nickle: Branch 'master'
Keith Packard
keithp at keithp.com
Fri Dec 1 11:59:40 PST 2023
json.5c | 14 ++++++++++----
test/jsontest.5c | 2 ++
2 files changed, 12 insertions(+), 4 deletions(-)
New commits:
commit a3fbac39b79f15a9eecf2edb2b56daacea289e98
Author: Keith Packard <keithp at keithp.com>
Date: Fri Dec 1 11:58:17 2023 -0800
json: Handle empty arrays and objects
Need to be able to parse "[]" and "{}" correctly.
Signed-off-by: Keith Packard <keithp at keithp.com>
diff --git a/json.5c b/json.5c
index 2ae7c04..fccf6c8 100644
--- a/json.5c
+++ b/json.5c
@@ -315,6 +315,10 @@ namespace JSON {
poly[string] hash() {
poly[string] ret = {};
for (;;) {
+ if (token.token == term_t._cc) {
+ next();
+ return ret;
+ }
expect(term_t._string);
string name = token.val.sval;
next();
@@ -327,8 +331,7 @@ namespace JSON {
next();
continue;
case term_t._cc:
- next();
- return ret;
+ break;
default:
raise json_parse_error(f.line, f.token);
}
@@ -338,6 +341,10 @@ namespace JSON {
poly[] array() {
poly[...] ret = {};
for (;;) {
+ if (token.token == term_t._cs) {
+ next();
+ return ret;
+ }
poly val = value();
ret[dim(ret)] = val;
switch (token.token) {
@@ -345,8 +352,7 @@ namespace JSON {
next();
continue;
case term_t._cs:
- next();
- return ret;
+ break;
default:
raise json_parse_error(f.line, f.token);
}
diff --git a/test/jsontest.5c b/test/jsontest.5c
index b1405f6..2eba97a 100644
--- a/test/jsontest.5c
+++ b/test/jsontest.5c
@@ -19,6 +19,8 @@ json_test_val("hello world", "\"hello world\"");
json_test_val(true, "true");
json_test_val(false, "false");
json_test_val(<>, "null");
+json_test_val((poly[string]){}, "{\n}");
+json_test_val(([0]){}, "[\n]");
json_test_val((poly[string]) {
"false" => false,
"float" => 1.1,
More information about the Nickle
mailing list