Have std/json decode null, false and true

This commit is contained in:
Nigel Tao committed 2020-02-21 11:16:27 +11:00
1 parent 9a5b635778
commit c92c0f50e4
7 files changed
+194 -12

No files matched your search

+92 -2
View File
@@ -6332,6 +6332,41 @@ wuffs_base__io_writer__copy_n32_from_slice(uint8_t** ptr_iop_w,
return (uint32_t)(n);
}
// wuffs_base__io_reader__match7 returns whether the io_reader's upcoming bytes
// start with the given prefix (up to 7 bytes long). It is peek-like, not
// read-like, in that there are no side-effects.
//
// The low 3 bits of a hold the prefix length, n.
//
// The high 56 bits of a hold the prefix itself, in little-endian order. The
// first prefix byte is in bits 8..=15, the second prefix byte is in bits
// 16..=23, etc. The high (8 * (7 - n)) bits are ignored.
//
// There are three possible return values:
// - 0 means success.
// - 1 means inconclusive, equivalent to "$short read".
// - 2 means failure.
static inline uint32_t //
wuffs_base__io_reader__match7(uint8_t* iop_r, uint8_t* io2_r, uint64_t a) {
uint32_t n = a & 7;
a >>= 8;
if ((io2_r - iop_r) >= 8) {
uint64_t x = wuffs_base__load_u64le(iop_r);
uint32_t shift = 8 * (8 - n);
return ((a << shift) == (x << shift)) ? 0 : 2;
}
for (; n > 0; n--) {
if (iop_r >= io2_r) {
return 1;
} else if (*iop_r != ((uint8_t)(a))) {
return 2;
}
iop_r++;
a >>= 8;
}
return 0;
}
static inline wuffs_base__io_buffer* //
wuffs_base__io_reader__set(wuffs_base__io_buffer* b,
uint8_t** ptr_iop_r,
@@ -18508,6 +18543,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
uint32_t v_depth = 0;
uint32_t v_stack_byte = 0;
uint32_t v_stack_bit = 0;
uint32_t v_match = 0;
uint8_t v_c = 0;
uint8_t v_expect = 0;
uint8_t v_expect_after_value = 0;
@@ -18894,8 +18930,62 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
}
goto label_0_continue;
} else {
status = wuffs_base__make_status(wuffs_json__error__bad_input);
goto exit;
if (0 == (v_expect & 1)) {
status = wuffs_base__make_status(wuffs_json__error__bad_input);
goto exit;
}
v_match = 2;
if (v_c == 110) {
v_match =
wuffs_base__io_reader__match7(iop_a_src, io2_a_src, 465676103172);
if (v_match == 0) {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(4194337)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
if (((uint64_t)(io2_a_src - iop_a_src)) < 4) {
status = wuffs_base__make_status(
wuffs_json__error__internal_error_inconsistent_i_o);
goto exit;
}
(iop_a_src += 4, wuffs_base__make_empty_struct());
}
} else if (v_c == 102) {
v_match = wuffs_base__io_reader__match7(iop_a_src, io2_a_src,
111546413966853);
if (v_match == 0) {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(4194369)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
(((uint64_t)(5)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
if (((uint64_t)(io2_a_src - iop_a_src)) < 5) {
status = wuffs_base__make_status(
wuffs_json__error__internal_error_inconsistent_i_o);
goto exit;
}
(iop_a_src += 5, wuffs_base__make_empty_struct());
}
} else if (v_c == 116) {
v_match =
wuffs_base__io_reader__match7(iop_a_src, io2_a_src, 435762131972);
if (v_match == 0) {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(4194433)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
if (((uint64_t)(io2_a_src - iop_a_src)) < 4) {
status = wuffs_base__make_status(
wuffs_json__error__internal_error_inconsistent_i_o);
goto exit;
}
(iop_a_src += 4, wuffs_base__make_empty_struct());
}
}
if (v_match == 1) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
goto label_0_continue;
} else if (v_match == 2) {
status = wuffs_base__make_status(wuffs_json__error__bad_input);
goto exit;
}
}
if (v_depth == 0) {
goto label_0_break;