mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 16:52:18 +01:00
Have std/json decode ',' and ':'
This commit is contained in:
1 parent
91454e911e
commit
40778f0665
2 files changed
+71
No files matched your search
@@ -5146,6 +5146,7 @@ struct wuffs_json__decoder__struct {
|
|||||||
struct {
|
struct {
|
||||||
uint32_t v_depth;
|
uint32_t v_depth;
|
||||||
uint8_t v_expect;
|
uint8_t v_expect;
|
||||||
|
uint8_t v_expect_after_value;
|
||||||
} s_decode_tokens[1];
|
} s_decode_tokens[1];
|
||||||
} private_data;
|
} private_data;
|
||||||
|
|
||||||
@@ -18230,6 +18231,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
|||||||
uint32_t v_stack_bit = 0;
|
uint32_t v_stack_bit = 0;
|
||||||
uint8_t v_c = 0;
|
uint8_t v_c = 0;
|
||||||
uint8_t v_expect = 0;
|
uint8_t v_expect = 0;
|
||||||
|
uint8_t v_expect_after_value = 0;
|
||||||
|
|
||||||
wuffs_base__token* iop_a_dst = NULL;
|
wuffs_base__token* iop_a_dst = NULL;
|
||||||
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = 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) {
|
if (coro_susp_point) {
|
||||||
v_depth = self->private_data.s_decode_tokens[0].v_depth;
|
v_depth = self->private_data.s_decode_tokens[0].v_depth;
|
||||||
v_expect = self->private_data.s_decode_tokens[0].v_expect;
|
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) {
|
switch (coro_susp_point) {
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||||
@@ -18391,10 +18395,36 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
|||||||
v_expect = 8;
|
v_expect = 8;
|
||||||
goto label_0_continue;
|
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 {
|
} else {
|
||||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||||
goto exit;
|
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) {
|
} else if (v_c == 91) {
|
||||||
if (0 == (v_expect & 1)) {
|
if (0 == (v_expect & 1)) {
|
||||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
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)(2097168)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||||
v_expect = 19;
|
v_expect = 19;
|
||||||
|
v_expect_after_value = 20;
|
||||||
|
goto label_0_continue;
|
||||||
} else if (v_c == 123) {
|
} else if (v_c == 123) {
|
||||||
if (0 == (v_expect & 1)) {
|
if (0 == (v_expect & 1)) {
|
||||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
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)(2097184)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||||
v_expect = 34;
|
v_expect = 34;
|
||||||
|
v_expect_after_value = 36;
|
||||||
|
goto label_0_continue;
|
||||||
} else {
|
} else {
|
||||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||||
goto exit;
|
goto exit;
|
||||||
@@ -18442,6 +18476,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
|||||||
if (v_depth == 0) {
|
if (v_depth == 0) {
|
||||||
goto label_0_break;
|
goto label_0_break;
|
||||||
}
|
}
|
||||||
|
v_expect = v_expect_after_value;
|
||||||
}
|
}
|
||||||
label_0_break:;
|
label_0_break:;
|
||||||
|
|
||||||
@@ -18459,6 +18494,8 @@ suspend:
|
|||||||
wuffs_base__status__is_suspension(&status) ? 1 : 0;
|
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_depth = v_depth;
|
||||||
self->private_data.s_decode_tokens[0].v_expect = v_expect;
|
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;
|
goto exit;
|
||||||
exit:
|
exit:
|
||||||
|
|||||||
@@ -74,6 +74,11 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
|||||||
// "String value" includes "this" and "th\u0061t".
|
// "String value" includes "this" and "th\u0061t".
|
||||||
var expect : base.u8
|
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
|
expect = 0x03 // EXPECT_VALUE
|
||||||
|
|
||||||
while.outer true {
|
while.outer true {
|
||||||
@@ -203,11 +208,35 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
|||||||
}
|
}
|
||||||
// -------- END parse strings.
|
// -------- 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 {
|
} else {
|
||||||
// TODO: numbers.
|
// TODO: numbers.
|
||||||
return "#bad input"
|
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 '['.
|
} else if c == 0x5B { // 0x5B is '['.
|
||||||
if 0 == (expect & 0x01) { // 0x01 is EXPECT_NON_STRING_VALUE.
|
if 0 == (expect & 0x01) { // 0x01 is EXPECT_NON_STRING_VALUE.
|
||||||
return "#bad input"
|
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.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
args.dst.write_fast_token!(value: 0x20_0010, length: 1)
|
args.dst.write_fast_token!(value: 0x20_0010, length: 1)
|
||||||
expect = 0x13 // 0x13 is (EXPECT_CLOSE_BRACKET | EXPECT_VALUE).
|
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 '{'.
|
} else if c == 0x7B { // 0x7B is '{'.
|
||||||
if 0 == (expect & 0x01) { // 0x01 is EXPECT_NON_STRING_VALUE.
|
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.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
args.dst.write_fast_token!(value: 0x20_0020, length: 1)
|
args.dst.write_fast_token!(value: 0x20_0020, length: 1)
|
||||||
expect = 0x22 // 0x22 is (EXPECT_CLOSE_BRACE | EXPECT_STRING_VALUE).
|
expect = 0x22 // 0x22 is (EXPECT_CLOSE_BRACE | EXPECT_STRING_VALUE).
|
||||||
|
expect_after_value = 0x24 // 0x14 is (EXPECT_CLOSE_BRACE | EXPECT_COMMA).
|
||||||
|
continue.outer
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// TODO: literals (false, true, null).
|
// 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 {
|
if depth == 0 {
|
||||||
break.outer
|
break.outer
|
||||||
}
|
}
|
||||||
|
expect = expect_after_value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user