Remove redundant nonterminals
This commit is contained in:
@@ -32,7 +32,6 @@ typedef Status (*Continuation)(struct Parser3 *);
|
|||||||
// These appear in the stack of the pushdown
|
// These appear in the stack of the pushdown
|
||||||
// automata
|
// automata
|
||||||
enum Symbol : uint8_t {
|
enum Symbol : uint8_t {
|
||||||
N_JSON,
|
|
||||||
N_VALUE,
|
N_VALUE,
|
||||||
N_OBJECT,
|
N_OBJECT,
|
||||||
N_OBJECT2,
|
N_OBJECT2,
|
||||||
@@ -40,11 +39,9 @@ enum Symbol : uint8_t {
|
|||||||
N_ARRAY,
|
N_ARRAY,
|
||||||
N_ARRAY2,
|
N_ARRAY2,
|
||||||
N_ARRAY3,
|
N_ARRAY3,
|
||||||
N_ELEMENT,
|
|
||||||
N_STRING,
|
N_STRING,
|
||||||
N_STRING2,
|
N_STRING2,
|
||||||
N_STRING_FOLLOWING_ESCAPE,
|
N_STRING_FOLLOWING_ESCAPE,
|
||||||
N_NUMBER,
|
|
||||||
N_INTEGER,
|
N_INTEGER,
|
||||||
N_INTEGER2,
|
N_INTEGER2,
|
||||||
N_DIGITS,
|
N_DIGITS,
|
||||||
@@ -79,7 +76,7 @@ enum Symbol : uint8_t {
|
|||||||
struct Parser3 {
|
struct Parser3 {
|
||||||
Parser3(const Callbacks *callbacks, void *data)
|
Parser3(const Callbacks *callbacks, void *data)
|
||||||
: callbacks(callbacks), data(data) {
|
: callbacks(callbacks), data(data) {
|
||||||
std::ignore = push({N_JSON, T_EOF});
|
std::ignore = push({N_WHITESPACE, N_VALUE, N_WHITESPACE, T_EOF});
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] Status parse(char *buf, int len) {
|
[[nodiscard]] Status parse(char *buf, int len) {
|
||||||
@@ -151,14 +148,6 @@ struct Parser3 {
|
|||||||
uint32_t minCodepoint;
|
uint32_t minCodepoint;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Status n_json(Parser3 *self) {
|
|
||||||
self->pop();
|
|
||||||
if (auto s = self->push({N_ELEMENT})) {
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
MUSTTAIL return Parser3::keepGoing(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Status n_value(Parser3 *self) {
|
inline Status n_value(Parser3 *self) {
|
||||||
switch (*self->buf) {
|
switch (*self->buf) {
|
||||||
case '{':
|
case '{':
|
||||||
@@ -191,7 +180,8 @@ inline Status n_value(Parser3 *self) {
|
|||||||
case '9':
|
case '9':
|
||||||
case '-':
|
case '-':
|
||||||
self->pop();
|
self->pop();
|
||||||
if (auto s = self->push({N_NUMBER})) {
|
if (auto s =
|
||||||
|
self->push({N_INTEGER, N_FRACTION, N_EXPONENT, T_END_NUMBER})) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -244,8 +234,8 @@ inline Status n_object2(Parser3 *self) {
|
|||||||
MUSTTAIL return Parser3::keepGoing(self);
|
MUSTTAIL return Parser3::keepGoing(self);
|
||||||
case '"':
|
case '"':
|
||||||
self->pop();
|
self->pop();
|
||||||
if (auto s = self->push(
|
if (auto s = self->push({N_STRING, N_WHITESPACE, T_COLON, N_WHITESPACE,
|
||||||
{N_STRING, N_WHITESPACE, T_COLON, N_ELEMENT, N_OBJECT3})) {
|
N_VALUE, N_WHITESPACE, N_OBJECT3})) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
MUSTTAIL return Parser3::keepGoing(self);
|
MUSTTAIL return Parser3::keepGoing(self);
|
||||||
@@ -265,7 +255,7 @@ inline Status n_object3(Parser3 *self) {
|
|||||||
++self->buf;
|
++self->buf;
|
||||||
self->pop();
|
self->pop();
|
||||||
if (auto s = self->push({N_WHITESPACE, N_STRING, N_WHITESPACE, T_COLON,
|
if (auto s = self->push({N_WHITESPACE, N_STRING, N_WHITESPACE, T_COLON,
|
||||||
N_ELEMENT, N_OBJECT3})) {
|
N_WHITESPACE, N_VALUE, N_WHITESPACE, N_OBJECT3})) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
MUSTTAIL return Parser3::keepGoing(self);
|
MUSTTAIL return Parser3::keepGoing(self);
|
||||||
@@ -313,7 +303,7 @@ inline Status n_array3(Parser3 *self) {
|
|||||||
case ',':
|
case ',':
|
||||||
++self->buf;
|
++self->buf;
|
||||||
self->pop();
|
self->pop();
|
||||||
if (auto s = self->push({N_ELEMENT, N_ARRAY3})) {
|
if (auto s = self->push({N_WHITESPACE, N_VALUE, N_WHITESPACE, N_ARRAY3})) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
MUSTTAIL return Parser3::keepGoing(self);
|
MUSTTAIL return Parser3::keepGoing(self);
|
||||||
@@ -322,14 +312,6 @@ inline Status n_array3(Parser3 *self) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Status n_element(Parser3 *self) {
|
|
||||||
self->pop();
|
|
||||||
if (auto s = self->push({N_WHITESPACE, N_VALUE, N_WHITESPACE})) {
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
MUSTTAIL return Parser3::keepGoing(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Status n_string(Parser3 *self) {
|
inline Status n_string(Parser3 *self) {
|
||||||
if (*self->buf != '"') {
|
if (*self->buf != '"') {
|
||||||
return S_REJECT;
|
return S_REJECT;
|
||||||
@@ -619,14 +601,6 @@ inline Status t_hex3(Parser3 *self) {
|
|||||||
MUSTTAIL return Parser3::keepGoing(self);
|
MUSTTAIL return Parser3::keepGoing(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Status n_number(Parser3 *self) {
|
|
||||||
self->pop();
|
|
||||||
if (auto s = self->push({N_INTEGER, N_FRACTION, N_EXPONENT, T_END_NUMBER})) {
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
MUSTTAIL return Parser3::keepGoing(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Status n_integer(Parser3 *self) {
|
inline Status n_integer(Parser3 *self) {
|
||||||
self->callbacks->on_begin_number(self->data);
|
self->callbacks->on_begin_number(self->data);
|
||||||
self->dataBegin = self->buf;
|
self->dataBegin = self->buf;
|
||||||
@@ -868,7 +842,6 @@ constexpr inline struct ContinuationTable {
|
|||||||
return S_REJECT;
|
return S_REJECT;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
continuations[N_JSON] = n_json;
|
|
||||||
continuations[N_VALUE] = n_value;
|
continuations[N_VALUE] = n_value;
|
||||||
continuations[N_OBJECT] = n_object;
|
continuations[N_OBJECT] = n_object;
|
||||||
continuations[N_OBJECT2] = n_object2;
|
continuations[N_OBJECT2] = n_object2;
|
||||||
@@ -876,11 +849,9 @@ constexpr inline struct ContinuationTable {
|
|||||||
continuations[N_ARRAY] = n_array;
|
continuations[N_ARRAY] = n_array;
|
||||||
continuations[N_ARRAY2] = n_array2;
|
continuations[N_ARRAY2] = n_array2;
|
||||||
continuations[N_ARRAY3] = n_array3;
|
continuations[N_ARRAY3] = n_array3;
|
||||||
continuations[N_ELEMENT] = n_element;
|
|
||||||
continuations[N_STRING] = n_string;
|
continuations[N_STRING] = n_string;
|
||||||
continuations[N_STRING2] = n_string2;
|
continuations[N_STRING2] = n_string2;
|
||||||
continuations[N_STRING_FOLLOWING_ESCAPE] = n_string_following_escape;
|
continuations[N_STRING_FOLLOWING_ESCAPE] = n_string_following_escape;
|
||||||
continuations[N_NUMBER] = n_number;
|
|
||||||
continuations[N_INTEGER] = n_integer;
|
continuations[N_INTEGER] = n_integer;
|
||||||
continuations[N_INTEGER2] = n_integer2;
|
continuations[N_INTEGER2] = n_integer2;
|
||||||
continuations[N_DIGITS] = n_digits;
|
continuations[N_DIGITS] = n_digits;
|
||||||
@@ -911,7 +882,6 @@ constexpr inline struct ContinuationTable {
|
|||||||
continuations[T_END_NUMBER] = t_end_number;
|
continuations[T_END_NUMBER] = t_end_number;
|
||||||
continuations[T_BACKSLASH] = singleChar<'\\'>;
|
continuations[T_BACKSLASH] = singleChar<'\\'>;
|
||||||
|
|
||||||
symbolNames[N_JSON] = "n_json";
|
|
||||||
symbolNames[N_VALUE] = "n_value";
|
symbolNames[N_VALUE] = "n_value";
|
||||||
symbolNames[N_OBJECT] = "n_object";
|
symbolNames[N_OBJECT] = "n_object";
|
||||||
symbolNames[N_OBJECT2] = "n_object2";
|
symbolNames[N_OBJECT2] = "n_object2";
|
||||||
@@ -919,11 +889,9 @@ constexpr inline struct ContinuationTable {
|
|||||||
symbolNames[N_ARRAY] = "n_array";
|
symbolNames[N_ARRAY] = "n_array";
|
||||||
symbolNames[N_ARRAY2] = "n_array2";
|
symbolNames[N_ARRAY2] = "n_array2";
|
||||||
symbolNames[N_ARRAY3] = "n_array3";
|
symbolNames[N_ARRAY3] = "n_array3";
|
||||||
symbolNames[N_ELEMENT] = "n_element";
|
|
||||||
symbolNames[N_STRING] = "n_string";
|
symbolNames[N_STRING] = "n_string";
|
||||||
symbolNames[N_STRING2] = "n_string2";
|
symbolNames[N_STRING2] = "n_string2";
|
||||||
symbolNames[N_STRING_FOLLOWING_ESCAPE] = "n_string_following_escape";
|
symbolNames[N_STRING_FOLLOWING_ESCAPE] = "n_string_following_escape";
|
||||||
symbolNames[N_NUMBER] = "n_number";
|
|
||||||
symbolNames[N_INTEGER] = "n_integer";
|
symbolNames[N_INTEGER] = "n_integer";
|
||||||
symbolNames[N_INTEGER2] = "n_integer2";
|
symbolNames[N_INTEGER2] = "n_integer2";
|
||||||
symbolNames[N_DIGITS] = "n_digits";
|
symbolNames[N_DIGITS] = "n_digits";
|
||||||
@@ -971,7 +939,6 @@ inline Status Parser3::keepGoing(Parser3 *self) {
|
|||||||
if (self->len() == 0) {
|
if (self->len() == 0) {
|
||||||
if (!self->complete) {
|
if (!self->complete) {
|
||||||
switch (self->top()) {
|
switch (self->top()) {
|
||||||
case N_NUMBER:
|
|
||||||
case N_INTEGER:
|
case N_INTEGER:
|
||||||
case N_INTEGER2:
|
case N_INTEGER2:
|
||||||
case N_DIGITS:
|
case N_DIGITS:
|
||||||
@@ -996,7 +963,6 @@ inline Status Parser3::keepGoing(Parser3 *self) {
|
|||||||
case T_U2:
|
case T_U2:
|
||||||
self->flushString();
|
self->flushString();
|
||||||
break;
|
break;
|
||||||
case N_JSON:
|
|
||||||
case N_VALUE:
|
case N_VALUE:
|
||||||
case N_OBJECT:
|
case N_OBJECT:
|
||||||
case N_OBJECT2:
|
case N_OBJECT2:
|
||||||
@@ -1004,7 +970,6 @@ inline Status Parser3::keepGoing(Parser3 *self) {
|
|||||||
case N_ARRAY:
|
case N_ARRAY:
|
||||||
case N_ARRAY2:
|
case N_ARRAY2:
|
||||||
case N_ARRAY3:
|
case N_ARRAY3:
|
||||||
case N_ELEMENT:
|
|
||||||
case N_WHITESPACE:
|
case N_WHITESPACE:
|
||||||
case N_TRUE:
|
case N_TRUE:
|
||||||
case N_FALSE:
|
case N_FALSE:
|
||||||
|
|||||||
Reference in New Issue
Block a user