diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index be5b3b94..3b18a376 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -5146,6 +5146,7 @@ struct wuffs_json__decoder__struct { struct { uint32_t v_depth; uint8_t v_expect; + uint8_t v_expect_after_value; } s_decode_tokens[1]; } private_data; @@ -18230,6 +18231,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self, uint32_t v_stack_bit = 0; uint8_t v_c = 0; uint8_t v_expect = 0; + uint8_t v_expect_after_value = 0; wuffs_base__token* iop_a_dst = NULL; wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL; @@ -18259,6 +18261,8 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self, if (coro_susp_point) { v_depth = self->private_data.s_decode_tokens[0].v_depth; v_expect = self->private_data.s_decode_tokens[0].v_expect; + v_expect_after_value = + self->private_data.s_decode_tokens[0].v_expect_after_value; } switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; @@ -18391,10 +18395,36 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self, v_expect = 8; goto label_0_continue; } + } else if (v_c == 44) { + if (0 == (v_expect & 4)) { + status = wuffs_base__make_status(wuffs_json__error__bad_input); + goto exit; + } + (iop_a_src += 1, wuffs_base__make_empty_struct()); + *iop_a_dst++ = wuffs_base__make_token( + (((uint64_t)(0)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) | + (((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); + if (0 == (v_expect & 16)) { + v_expect = 2; + } else { + v_expect = 3; + } + goto label_0_continue; } else { status = wuffs_base__make_status(wuffs_json__error__bad_input); goto exit; } + } else if (v_c == 58) { + if (0 == (v_expect & 8)) { + status = wuffs_base__make_status(wuffs_json__error__bad_input); + goto exit; + } + (iop_a_src += 1, wuffs_base__make_empty_struct()); + *iop_a_dst++ = wuffs_base__make_token( + (((uint64_t)(0)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) | + (((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); + v_expect = 3; + goto label_0_continue; } else if (v_c == 91) { if (0 == (v_expect & 1)) { status = wuffs_base__make_status(wuffs_json__error__bad_input); @@ -18415,6 +18445,8 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self, (((uint64_t)(2097168)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) | (((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); v_expect = 19; + v_expect_after_value = 20; + goto label_0_continue; } else if (v_c == 123) { if (0 == (v_expect & 1)) { status = wuffs_base__make_status(wuffs_json__error__bad_input); @@ -18435,6 +18467,8 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self, (((uint64_t)(2097184)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) | (((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); v_expect = 34; + v_expect_after_value = 36; + goto label_0_continue; } else { status = wuffs_base__make_status(wuffs_json__error__bad_input); goto exit; @@ -18442,6 +18476,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self, if (v_depth == 0) { goto label_0_break; } + v_expect = v_expect_after_value; } label_0_break:; @@ -18459,6 +18494,8 @@ suspend: wuffs_base__status__is_suspension(&status) ? 1 : 0; self->private_data.s_decode_tokens[0].v_depth = v_depth; self->private_data.s_decode_tokens[0].v_expect = v_expect; + self->private_data.s_decode_tokens[0].v_expect_after_value = + v_expect_after_value; goto exit; exit: diff --git a/std/json/decode_json.wuffs b/std/json/decode_json.wuffs index fd5c3c09..461604cc 100644 --- a/std/json/decode_json.wuffs +++ b/std/json/decode_json.wuffs @@ -74,6 +74,11 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) { // "String value" includes "this" and "th\u0061t". var expect : base.u8 + // expect_after_value is what to expect after seeing a value. For depth 0, + // this is ignored. Otherwise, it should be (EXPECT_CLOSE_FOO | + // EXPECT_COMMA), for some value of FOO. + var expect_after_value : base.u8 + expect = 0x03 // EXPECT_VALUE while.outer true { @@ -203,11 +208,35 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) { } // -------- END parse strings. + } else if c == 0x2C { // 0x2C is ','. + if 0 == (expect & 0x04) { // 0x01 is EXPECT_COMMA. + return "#bad input" + } + args.src.skip32_fast!(actual: 1, worst_case: 1) + args.dst.write_fast_token!(value: 0, length: 1) // The ',' is filler. + // What's valid after a comma depends on whether or not we're + // in an array or an object. + if 0 == (expect & 0x10) { // 0x10 is EXPECT_CLOSE_BRACKET + expect = 0x02 // 0x02 is EXPECT_STRING_VALUE. + } else { + expect = 0x03 // 0x03 is EXPECT_VALUE. + } + continue.outer + } else { // TODO: numbers. return "#bad input" } + } else if c == 0x3A { // 0x3A is ':'. + if 0 == (expect & 0x08) { // 0x08 is EXPECT_COLON. + return "#bad input" + } + args.src.skip32_fast!(actual: 1, worst_case: 1) + args.dst.write_fast_token!(value: 0, length: 1) // The ':' is filler. + expect = 0x03 // 0x03 is EXPECT_VALUE. + continue.outer + } else if c == 0x5B { // 0x5B is '['. if 0 == (expect & 0x01) { // 0x01 is EXPECT_NON_STRING_VALUE. return "#bad input" @@ -223,6 +252,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) { args.src.skip32_fast!(actual: 1, worst_case: 1) args.dst.write_fast_token!(value: 0x20_0010, length: 1) expect = 0x13 // 0x13 is (EXPECT_CLOSE_BRACKET | EXPECT_VALUE). + expect_after_value = 0x14 // 0x14 is (EXPECT_CLOSE_BRACKET | EXPECT_COMMA). + continue.outer } else if c == 0x7B { // 0x7B is '{'. if 0 == (expect & 0x01) { // 0x01 is EXPECT_NON_STRING_VALUE. @@ -239,6 +270,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) { args.src.skip32_fast!(actual: 1, worst_case: 1) args.dst.write_fast_token!(value: 0x20_0020, length: 1) expect = 0x22 // 0x22 is (EXPECT_CLOSE_BRACE | EXPECT_STRING_VALUE). + expect_after_value = 0x24 // 0x14 is (EXPECT_CLOSE_BRACE | EXPECT_COMMA). + continue.outer } else { // TODO: literals (false, true, null). @@ -249,5 +282,6 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) { if depth == 0 { break.outer } + expect = expect_after_value } }