From 3afa3b6e9a35ebe5662eb5f496f88d6f9407720b Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Thu, 22 May 2025 11:55:27 -0400 Subject: [PATCH] Skip N_OBJECT and N_ARRAY --- src/parser3.h | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/src/parser3.h b/src/parser3.h index 6ecd808..13a99c9 100644 --- a/src/parser3.h +++ b/src/parser3.h @@ -22,10 +22,8 @@ typedef WeaselJsonStatus (*Continuation)(struct Parser3 *); // automata enum Symbol : uint8_t { N_VALUE, - N_OBJECT, N_OBJECT2, N_OBJECT3, - N_ARRAY, N_ARRAY2, N_ARRAY3, N_STRING, @@ -162,14 +160,18 @@ inline WeaselJsonStatus n_value(Parser3 *self) { } switch (*self->buf) { case '{': + self->callbacks->on_begin_object(self->data); + ++self->buf; self->pop(); - if (auto s = self->push({N_OBJECT})) { + if (auto s = self->push({N_OBJECT2})) { return s; } break; case '[': + self->callbacks->on_begin_array(self->data); + ++self->buf; self->pop(); - if (auto s = self->push({N_ARRAY})) { + if (auto s = self->push({N_ARRAY2})) { return s; } break; @@ -226,19 +228,6 @@ inline WeaselJsonStatus n_value(Parser3 *self) { MUSTTAIL return Parser3::keepGoing(self); } -inline WeaselJsonStatus n_object(Parser3 *self) { - if (*self->buf != '{') { - return WeaselJson_REJECT; - } - self->callbacks->on_begin_object(self->data); - ++self->buf; - self->pop(); - if (auto s = self->push({N_OBJECT2})) { - return s; - } - MUSTTAIL return Parser3::keepGoing(self); -} - inline WeaselJsonStatus n_object2(Parser3 *self) { assert(self->len() != 0); while (tables.whitespace[uint8_t(*self->buf)]) { @@ -293,19 +282,6 @@ inline WeaselJsonStatus n_object3(Parser3 *self) { } } -inline WeaselJsonStatus n_array(Parser3 *self) { - if (*self->buf != '[') { - return WeaselJson_REJECT; - } - self->callbacks->on_begin_array(self->data); - ++self->buf; - self->pop(); - if (auto s = self->push({N_ARRAY2})) { - return s; - } - MUSTTAIL return Parser3::keepGoing(self); -} - inline WeaselJsonStatus n_array2(Parser3 *self) { assert(self->len() != 0); while (tables.whitespace[uint8_t(*self->buf)]) { @@ -896,10 +872,8 @@ constexpr inline struct ContinuationTable { }; } continuations[N_VALUE] = n_value; - continuations[N_OBJECT] = n_object; continuations[N_OBJECT2] = n_object2; continuations[N_OBJECT3] = n_object3; - continuations[N_ARRAY] = n_array; continuations[N_ARRAY2] = n_array2; continuations[N_ARRAY3] = n_array3; continuations[N_STRING] = n_string; @@ -936,10 +910,8 @@ constexpr inline struct ContinuationTable { continuations[T_BACKSLASH] = singleChar<'\\'>; symbolNames[N_VALUE] = "n_value"; - symbolNames[N_OBJECT] = "n_object"; symbolNames[N_OBJECT2] = "n_object2"; symbolNames[N_OBJECT3] = "n_object3"; - symbolNames[N_ARRAY] = "n_array"; symbolNames[N_ARRAY2] = "n_array2"; symbolNames[N_ARRAY3] = "n_array3"; symbolNames[N_STRING] = "n_string"; @@ -1017,10 +989,8 @@ inline WeaselJsonStatus Parser3::keepGoing(Parser3 *self) { self->flushString(); break; case N_VALUE: - case N_OBJECT: case N_OBJECT2: case N_OBJECT3: - case N_ARRAY: case N_ARRAY2: case N_ARRAY3: case N_WHITESPACE: