From 21f6a5df4a6f7499900aa47171bc654a96d6fd4d Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sat, 21 Mar 2020 22:26:27 +1100 Subject: [PATCH] Add std/json CLASS_COMMENT --- release/c/wuffs-unsupported-snapshot.c | 36 +++++++++---------- std/json/common_consts.wuffs | 23 ++++++------ std/json/decode_json.wuffs | 50 +++++++++++++------------- 3 files changed, 56 insertions(+), 53 deletions(-) diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 52c844d7..9aadd1ad 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -20291,7 +20291,7 @@ static const uint8_t // WUFFS_BASE__POTENTIALLY_UNUSED = { 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 15, 15, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 15, 1, 15, - 15, 15, 15, 15, 15, 15, 15, 15, 2, 4, 15, 15, 4, 4, 4, 4, 4, 4, + 15, 15, 15, 15, 15, 15, 15, 15, 2, 4, 15, 12, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 15, 8, 15, 15, 15, 15, 15, 15, 15, 15, 9, 15, 15, 15, 15, 15, @@ -20605,7 +20605,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self, goto suspend; } } - v_expect = 3762; + v_expect = 7858; label__outer__continue:; while (true) { while (true) { @@ -21301,7 +21301,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self, } label__2__break:; if (0 == (v_expect & 16)) { - v_expect = 8; + v_expect = 4104; goto label__outer__continue; } goto label__goto_parsed_a_leaf_value__break; @@ -21311,9 +21311,9 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self, (((uint64_t)(0)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | (((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); if (0 == (v_expect & 256)) { - v_expect = 2; + v_expect = 4098; } else { - v_expect = 3762; + v_expect = 7858; } goto label__outer__continue; } else if (v_class == 3) { @@ -21321,7 +21321,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self, *iop_a_dst++ = wuffs_base__make_token( (((uint64_t)(0)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | (((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); - v_expect = 3762; + v_expect = 7858; goto label__outer__continue; } else if (v_class == 4) { while (true) { @@ -21399,8 +21399,8 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self, (((uint64_t)(v_vminor)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | (((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); - v_expect = 66; - v_expect_after_value = 68; + v_expect = 4162; + v_expect_after_value = 4164; goto label__outer__continue; } else if (v_class == 6) { (iop_a_src += 1, wuffs_base__make_empty_struct()); @@ -21420,15 +21420,15 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self, (((uint64_t)(2105410)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | (((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); - v_expect = 260; - v_expect_after_value = 260; + v_expect = 4356; + v_expect_after_value = 4356; } else { *iop_a_dst++ = wuffs_base__make_token( (((uint64_t)(2113602)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | (((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); - v_expect = 68; - v_expect_after_value = 68; + v_expect = 4164; + v_expect_after_value = 4164; } goto label__outer__continue; } else if (v_class == 7) { @@ -21454,8 +21454,8 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self, (((uint64_t)(v_vminor)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | (((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); - v_expect = 4018; - v_expect_after_value = 260; + v_expect = 8114; + v_expect_after_value = 4356; goto label__outer__continue; } else if (v_class == 8) { (iop_a_src += 1, wuffs_base__make_empty_struct()); @@ -21475,15 +21475,15 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self, (((uint64_t)(2105378)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | (((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); - v_expect = 260; - v_expect_after_value = 260; + v_expect = 4356; + v_expect_after_value = 4356; } else { *iop_a_dst++ = wuffs_base__make_token( (((uint64_t)(2113570)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | (((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); - v_expect = 68; - v_expect_after_value = 68; + v_expect = 4164; + v_expect_after_value = 4164; } goto label__outer__continue; } else if (v_class == 9) { diff --git a/std/json/common_consts.wuffs b/std/json/common_consts.wuffs index 5414d70a..8a43b711 100644 --- a/std/json/common_consts.wuffs +++ b/std/json/common_consts.wuffs @@ -197,7 +197,7 @@ pri const lut_chars array[256] base.u8 = [ // - 0x09 (bitmask 0x0200) is CLASS_FALSE. // - 0x0A (bitmask 0x0400) is CLASS_TRUE. // - 0x0B (bitmask 0x0800) is CLASS_NULL. -// - 0x0C (bitmask 0x1000) is reserved. +// - 0x0C (bitmask 0x1000) is CLASS_COMMENT. // - 0x0D (bitmask 0x2000) is reserved. // - 0x0E (bitmask 0x4000) is reserved. // - 0x0F (bitmask 0x8000) is CLASS_BAD_INPUT. @@ -205,26 +205,29 @@ pri const lut_chars array[256] base.u8 = [ // The bitmasks are used by the "expect" variable: what the next character // class can be. // -// - 0x0002 is EXPECT_STRING. -// - 0x0EB0 is EXPECT_NON_STRING_VALUE. -// - 0x0004 is EXPECT_COMMA. -// - 0x0008 is EXPECT_COLON. -// - 0x0040 is EXPECT_CLOSE_CURLY_BRACE. -// - 0x0100 is EXPECT_CLOSE_SQUARE_BRACKET. +// - 0x1002 is EXPECT_STRING. +// - 0x1EB0 is EXPECT_NON_STRING_VALUE. +// - 0x1004 is EXPECT_COMMA. +// - 0x1008 is EXPECT_COLON. +// - 0x1040 is EXPECT_CLOSE_CURLY_BRACE. +// - 0x1100 is EXPECT_CLOSE_SQUARE_BRACKET. // // Bitwise or'ing these together gives 0x0FFE. Whitespace is never expected, as // it is handled separately. // -// EXPECT_VALUE is also defined to be 0x0EB2, equivalent to (EXPECT_STRING | +// EXPECT_VALUE is also defined to be 0x1EB2, equivalent to (EXPECT_STRING | // EXPECT_NON_STRING_VALUE). // -// EXPECT_NUMBER is also defined to be 0x0010. Testing for EXPECT_NUMBER's +// EXPECT_NUMBER is also defined to be 0x1010. Testing for EXPECT_NUMBER's // presence is equivalent to testing for EXPECT_NON_STRING_VALUE. // // "Non-string value" includes literals (false, true, null), numbers, arrays // and objects. // // "String value" includes "this" and "th\u0061t". +// +// Comments are always expected. Whether the relevant quirks are enabled are +// checked elsewhere. pri const lut_classes array[256] base.u8[..= 0x0F] = [ // 0 1 2 3 4 5 6 7 // 8 9 A B C D E F @@ -233,7 +236,7 @@ pri const lut_classes array[256] base.u8[..= 0x0F] = [ 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, // 0x10 ..= 0x17. 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, // 0x18 ..= 0x1F. 0x00, 0x0F, 0x01, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, // 0x20 ..= 0x27. ' ', '"'. - 0x0F, 0x0F, 0x0F, 0x0F, 0x02, 0x04, 0x0F, 0x0F, // 0x28 ..= 0x2F. ',', '-'. + 0x0F, 0x0F, 0x0F, 0x0F, 0x02, 0x04, 0x0F, 0x0C, // 0x28 ..= 0x2F. ',', '-', '/'. 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, // 0x30 ..= 0x37. '0'-'7'. 0x04, 0x04, 0x03, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, // 0x38 ..= 0x3F. '8'-'9', ':'. diff --git a/std/json/decode_json.wuffs b/std/json/decode_json.wuffs index db5113ef..e297898c 100644 --- a/std/json/decode_json.wuffs +++ b/std/json/decode_json.wuffs @@ -148,7 +148,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) { this.decode_leading?(dst: args.dst, src: args.src) } - expect = 0x0EB2 // EXPECT_VALUE + expect = 0x1EB2 // EXPECT_VALUE while.outer true { while.goto_parsed_a_leaf_value true { @@ -814,8 +814,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) { // As above, expect must have contained EXPECT_STRING. If it // didn't also contain EXPECT_NUMBER then we were parsing an // object key and the next token should be ':'. - if 0 == (expect & 0x0010) { // 0x0010 is EXPECT_NUMBER. - expect = 0x0008 // 0x0008 is EXPECT_COLON. + if 0 == (expect & 0x0010) { // 0x0010 is (1 << CLASS_NUMBER). + expect = 0x1008 // 0x1008 is EXPECT_COLON. continue.outer } break.goto_parsed_a_leaf_value @@ -831,10 +831,10 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) { length: 1) // What's valid after a comma depends on whether or not we're // in an array or an object. - if 0 == (expect & 0x0100) { // 0x0100 is EXPECT_CLOSE_SQUARE_BRACKET - expect = 0x0002 // 0x0002 is EXPECT_STRING. + if 0 == (expect & 0x0100) { // 0x0100 is (1 << CLASS_CLOSE_SQUARE_BRACKET). + expect = 0x1002 // 0x1002 is EXPECT_STRING. } else { - expect = 0x0EB2 // 0x0EB2 is EXPECT_VALUE. + expect = 0x1EB2 // 0x0EB2 is EXPECT_VALUE. } continue.outer @@ -846,7 +846,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) { value_minor: 0, link: 0x0, length: 1) - expect = 0x0EB2 // 0x0EB2 is EXPECT_VALUE. + expect = 0x1EB2 // 0x1EB2 is EXPECT_VALUE. continue.outer } else if class == 0x04 { // 0x04 is CLASS_NUMBER. @@ -899,7 +899,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) { vminor = 0x20_4011 if depth == 0 { // No-op. - } else if 0 <> (expect_after_value & 0x0040) { // 0x0040 is EXPECT_CLOSE_CURLY_BRACE. + } else if 0 <> (expect_after_value & 0x0040) { // 0x0040 is (1 << CLASS_CLOSE_CURLY_BRACE). vminor = 0x20_4041 } else { vminor = 0x20_4021 @@ -918,8 +918,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) { value_minor: vminor, link: 0x0, length: 1) - expect = 0x0042 // 0x0042 is (EXPECT_CLOSE_CURLY_BRACE | EXPECT_STRING). - expect_after_value = 0x0044 // 0x0044 is (EXPECT_CURLY_CLOSE_BRACE | EXPECT_COMMA). + expect = 0x1042 // 0x1042 is (EXPECT_CLOSE_CURLY_BRACE | EXPECT_STRING). + expect_after_value = 0x1044 // 0x1044 is (EXPECT_CURLY_CLOSE_BRACE | EXPECT_COMMA). continue.outer } else if class == 0x06 { // 0x06 is CLASS_CLOSE_CURLY_BRACE. @@ -941,18 +941,18 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) { value_minor: 0x20_2042, link: 0x0, length: 1) - // 0x0104 is (EXPECT_SQUARE_CLOSE_BRACKET | EXPECT_COMMA). - expect = 0x0104 - expect_after_value = 0x0104 + // 0x1104 is (EXPECT_SQUARE_CLOSE_BRACKET | EXPECT_COMMA). + expect = 0x1104 + expect_after_value = 0x1104 } else { args.dst.write_fast_token!( value_major: 0, value_minor: 0x20_4042, link: 0x0, length: 1) - // 0x0044 is (EXPECT_CURLY_CLOSE_BRACE | EXPECT_COMMA). - expect = 0x0044 - expect_after_value = 0x0044 + // 0x1044 is (EXPECT_CURLY_CLOSE_BRACE | EXPECT_COMMA). + expect = 0x1044 + expect_after_value = 0x1044 } continue.outer @@ -960,7 +960,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) { vminor = 0x20_2011 if depth == 0 { // No-op. - } else if 0 <> (expect_after_value & 0x0040) { // 0x0040 is EXPECT_CLOSE_CURLY_BRACE. + } else if 0 <> (expect_after_value & 0x0040) { // 0x0040 is (1 << CLASS_CLOSE_CURLY_BRACE). vminor = 0x20_2041 } else { vminor = 0x20_2021 @@ -979,8 +979,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) { value_minor: vminor, link: 0x0, length: 1) - expect = 0x0FB2 // 0x0FB2 is (EXPECT_CLOSE_SQUARE_BRACKET | EXPECT_VALUE). - expect_after_value = 0x0104 // 0x0104 is (EXPECT_CLOSE_SQUARE_BRACKET | EXPECT_COMMA). + expect = 0x1FB2 // 0x1FB2 is (EXPECT_CLOSE_SQUARE_BRACKET | EXPECT_VALUE). + expect_after_value = 0x1104 // 0x1104 is (EXPECT_CLOSE_SQUARE_BRACKET | EXPECT_COMMA). continue.outer } else if class == 0x08 { // 0x08 is CLASS_CLOSE_SQUARE_BRACKET. @@ -1002,18 +1002,18 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) { value_minor: 0x20_2022, link: 0x0, length: 1) - // 0x0104 is (EXPECT_CLOSE_SQUARE_BRACKET | EXPECT_COMMA). - expect = 0x0104 - expect_after_value = 0x0104 + // 0x1104 is (EXPECT_CLOSE_SQUARE_BRACKET | EXPECT_COMMA). + expect = 0x1104 + expect_after_value = 0x1104 } else { args.dst.write_fast_token!( value_major: 0, value_minor: 0x20_4022, link: 0x0, length: 1) - // 0x0044 is (EXPECT_CLOSE_CURLY_BRACE | EXPECT_COMMA). - expect = 0x0044 - expect_after_value = 0x0044 + // 0x1044 is (EXPECT_CLOSE_CURLY_BRACE | EXPECT_COMMA). + expect = 0x1044 + expect_after_value = 0x1044 } continue.outer