Add json.EXPECT_ETC constants

This commit is contained in:
Nigel Tao committed 2020-06-09 23:50:35 +10:00
1 parent 3d31ac03eb
commit 66b0a12b6c
3 files changed
+62 -50

No files matched your search

+16
View File
@@ -21749,6 +21749,22 @@ WUFFS_JSON__LUT_CHARS[256]WUFFS_BASE__POTENTIALLY_UNUSED = {
#define WUFFS_JSON__CLASS_COMMENT 12
#define WUFFS_JSON__EXPECT_VALUE 7858
#define WUFFS_JSON__EXPECT_NON_STRING_VALUE 7856
#define WUFFS_JSON__EXPECT_STRING 4098
#define WUFFS_JSON__EXPECT_COMMA 4100
#define WUFFS_JSON__EXPECT_COLON 4104
#define WUFFS_JSON__EXPECT_NUMBER 4112
#define WUFFS_JSON__EXPECT_CLOSE_CURLY_BRACE 4160
#define WUFFS_JSON__EXPECT_CLOSE_SQUARE_BRACKET 4352
static const uint8_t
WUFFS_JSON__LUT_CLASSES[256]WUFFS_BASE__POTENTIALLY_UNUSED = {
15, 15, 15, 15, 15, 15, 15, 15,
+25 -25
View File
@@ -219,6 +219,30 @@ pri const CLASS_TRUE : base.u8 = 0x0A
pri const CLASS_NULL_NAN_INF : base.u8 = 0x0B
pri const CLASS_COMMENT : base.u8 = 0x0C
// EXPECT_ETC are unions of LUT_CLASSES bitmasks. See LUT_CLASSES below.
//
// Bitwise or'ing these together gives 0x1FFE. Whitespace is never expected, as
// it is handled separately.
//
// EXPECT_VALUE is also defined to be 0x1EB2, equivalent to (EXPECT_STRING |
// 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 EXPECT_VALUE : base.u32 = 0x1EB2
pri const EXPECT_NON_STRING_VALUE : base.u32 = 0x1EB0
pri const EXPECT_STRING : base.u32 = 0x1002
pri const EXPECT_COMMA : base.u32 = 0x1004
pri const EXPECT_COLON : base.u32 = 0x1008
pri const EXPECT_NUMBER : base.u32 = 0x1010
pri const EXPECT_CLOSE_CURLY_BRACE : base.u32 = 0x1040
pri const EXPECT_CLOSE_SQUARE_BRACKET : base.u32 = 0x1100
// LUT_CLASSES is:
// - 0x00 (bitmask 0x0001) is CLASS_WHITESPACE.
// - 0x01 (bitmask 0x0002) is CLASS_STRING.
@@ -238,31 +262,7 @@ pri const CLASS_COMMENT : base.u8 = 0x0C
// - 0x0F (bitmask 0x8000) is CLASS_BAD_INPUT.
//
// The bitmasks are used by the "expect" variable: what the next character
// class can be.
//
// - 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 0x1EB2, equivalent to (EXPECT_STRING |
// EXPECT_NON_STRING_VALUE).
//
// 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.
// class can be. See EXPECT_ETC above.
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
+21 -25
View File
@@ -121,7 +121,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
this.decode_leading?(dst: args.dst, src: args.src)
}
expect = 0x1EB2 // EXPECT_VALUE
expect = EXPECT_VALUE
while.outer true {
while.goto_parsed_a_leaf_value true {{
@@ -838,10 +838,10 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
} endwhile
// 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 ':'.
// also contain EXPECT_NUMBER (excluding EXPECT_COMMENT) then we
// were parsing an object key and the next token should be ':'.
if 0 == (expect & ((1 as base.u32) << CLASS_NUMBER)) {
expect = 0x1008 // 0x1008 is EXPECT_COLON.
expect = EXPECT_COLON
continue.outer
}
break.goto_parsed_a_leaf_value
@@ -859,15 +859,15 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
// array or an object.
if 0 == (expect & ((1 as base.u32) << CLASS_CLOSE_SQUARE_BRACKET)) {
if this.quirks[QUIRK_ALLOW_EXTRA_COMMA - QUIRKS_BASE] {
expect = 0x1042 // 0x1042 is EXPECT_STRING | EXPECT_CLOSE_CURLY_BRACE.
expect = EXPECT_STRING | EXPECT_CLOSE_CURLY_BRACE
} else {
expect = 0x1002 // 0x1002 is EXPECT_STRING.
expect = EXPECT_STRING
}
} else {
if this.quirks[QUIRK_ALLOW_EXTRA_COMMA - QUIRKS_BASE] {
expect = 0x1FB2 // 0x0FB2 is EXPECT_VALUE | EXPECT_CLOSE_SQUARE_BRACKET.
expect = EXPECT_VALUE | EXPECT_CLOSE_SQUARE_BRACKET
} else {
expect = 0x1EB2 // 0x0EB2 is EXPECT_VALUE.
expect = EXPECT_VALUE
}
}
continue.outer
@@ -880,7 +880,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
value_minor: 0,
continued: 0,
length: 1)
expect = 0x1EB2 // 0x1EB2 is EXPECT_VALUE.
expect = EXPECT_VALUE
continue.outer
} else if class == CLASS_NUMBER {
@@ -970,8 +970,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
value_minor: vminor,
continued: 0,
length: 1)
expect = 0x1042 // 0x1042 is (EXPECT_CLOSE_CURLY_BRACE | EXPECT_STRING).
expect_after_value = 0x1044 // 0x1044 is (EXPECT_CURLY_CLOSE_BRACE | EXPECT_COMMA).
expect = EXPECT_CLOSE_CURLY_BRACE | EXPECT_STRING
expect_after_value = EXPECT_CLOSE_CURLY_BRACE | EXPECT_COMMA
continue.outer
} else if class == CLASS_CLOSE_CURLY_BRACE {
@@ -999,9 +999,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
base.TOKEN__VBD__STRUCTURE__TO_LIST,
continued: 0,
length: 1)
// 0x1104 is (EXPECT_SQUARE_CLOSE_BRACKET | EXPECT_COMMA).
expect = 0x1104
expect_after_value = 0x1104
expect = EXPECT_CLOSE_SQUARE_BRACKET | EXPECT_COMMA
expect_after_value = EXPECT_CLOSE_SQUARE_BRACKET | EXPECT_COMMA
} else {
args.dst.write_simple_token_fast!(
value_major: 0,
@@ -1011,9 +1010,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
base.TOKEN__VBD__STRUCTURE__TO_DICT,
continued: 0,
length: 1)
// 0x1044 is (EXPECT_CURLY_CLOSE_BRACE | EXPECT_COMMA).
expect = 0x1044
expect_after_value = 0x1044
expect = EXPECT_CLOSE_CURLY_BRACE | EXPECT_COMMA
expect_after_value = EXPECT_CLOSE_CURLY_BRACE | EXPECT_COMMA
}
continue.outer
@@ -1049,8 +1047,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
value_minor: vminor,
continued: 0,
length: 1)
expect = 0x1FB2 // 0x1FB2 is (EXPECT_CLOSE_SQUARE_BRACKET | EXPECT_VALUE).
expect_after_value = 0x1104 // 0x1104 is (EXPECT_CLOSE_SQUARE_BRACKET | EXPECT_COMMA).
expect = EXPECT_CLOSE_SQUARE_BRACKET | EXPECT_VALUE
expect_after_value = EXPECT_CLOSE_SQUARE_BRACKET | EXPECT_COMMA
continue.outer
} else if class == CLASS_CLOSE_SQUARE_BRACKET {
@@ -1078,9 +1076,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
base.TOKEN__VBD__STRUCTURE__TO_LIST,
continued: 0,
length: 1)
// 0x1104 is (EXPECT_CLOSE_SQUARE_BRACKET | EXPECT_COMMA).
expect = 0x1104
expect_after_value = 0x1104
expect = EXPECT_CLOSE_SQUARE_BRACKET | EXPECT_COMMA
expect_after_value = EXPECT_CLOSE_SQUARE_BRACKET | EXPECT_COMMA
} else {
args.dst.write_simple_token_fast!(
value_major: 0,
@@ -1090,9 +1087,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
base.TOKEN__VBD__STRUCTURE__TO_DICT,
continued: 0,
length: 1)
// 0x1044 is (EXPECT_CLOSE_CURLY_BRACE | EXPECT_COMMA).
expect = 0x1044
expect_after_value = 0x1044
expect = EXPECT_CLOSE_CURLY_BRACE | EXPECT_COMMA
expect_after_value = EXPECT_CLOSE_CURLY_BRACE | EXPECT_COMMA
}
continue.outer