Remove Parser2::parseLiteral
This commit is contained in:
49
src/test.cpp
49
src/test.cpp
@@ -472,17 +472,6 @@ private:
|
||||
++buf;
|
||||
}
|
||||
}
|
||||
Status parseLiteral(const char *literal) {
|
||||
const int litLen = strlen(literal);
|
||||
if (len() < litLen) {
|
||||
return S_REJECT;
|
||||
}
|
||||
if (memcmp(buf, literal, litLen) == 0) {
|
||||
buf += litLen;
|
||||
return S_OK;
|
||||
}
|
||||
return S_REJECT;
|
||||
}
|
||||
Status parse_number() {
|
||||
char *const bufBefore = buf;
|
||||
if (len() == 0 || !('0' <= *buf && *buf <= '9' || (*buf == '.'))) {
|
||||
@@ -509,10 +498,7 @@ private:
|
||||
}
|
||||
int stringLen = result - buf;
|
||||
callbacks->on_string_data(data, buf, stringLen);
|
||||
buf += stringLen;
|
||||
if (Status s = parseLiteral("\"")) {
|
||||
return s;
|
||||
}
|
||||
buf += stringLen + 1;
|
||||
callbacks->on_end_string(data);
|
||||
return S_OK;
|
||||
}
|
||||
@@ -609,7 +595,8 @@ private:
|
||||
MUSTTAIL return keepGoing(self);
|
||||
}
|
||||
static Status arrayOrEnd(Parser2 *self) {
|
||||
if (self->parseLiteral("]") == S_OK) {
|
||||
if (*self->buf == ']') {
|
||||
++self->buf;
|
||||
self->pop();
|
||||
self->callbacks->on_end_array(self->data);
|
||||
MUSTTAIL return keepGoing(self);
|
||||
@@ -622,11 +609,13 @@ private:
|
||||
}
|
||||
}
|
||||
static Status objectOrEnd(Parser2 *self) {
|
||||
if (self->parseLiteral("}") == S_OK) {
|
||||
if (*self->buf == '}') {
|
||||
++self->buf;
|
||||
self->pop();
|
||||
self->callbacks->on_end_object(self->data);
|
||||
MUSTTAIL return keepGoing(self);
|
||||
} else if (self->parseLiteral("\"") == S_OK) {
|
||||
} else if (*self->buf == '"') {
|
||||
++self->buf;
|
||||
self->pop();
|
||||
if (Status s = self->push(
|
||||
{N_STRING, T_COLON, N_VALUE, N_OBJECT_MAYBE_CONTINUE})) {
|
||||
@@ -637,13 +626,15 @@ private:
|
||||
return S_REJECT;
|
||||
}
|
||||
static Status arrayContinue(Parser2 *self) {
|
||||
if (self->parseLiteral(",") == S_OK) {
|
||||
if (*self->buf == ',') {
|
||||
++self->buf;
|
||||
self->pop();
|
||||
if (Status s = self->push({N_VALUE, N_ARRAY_MAYBE_CONTINUE})) {
|
||||
return s;
|
||||
}
|
||||
MUSTTAIL return keepGoing(self);
|
||||
} else if (self->parseLiteral("]") == S_OK) {
|
||||
} else if (*self->buf == ']') {
|
||||
++self->buf;
|
||||
self->pop();
|
||||
self->callbacks->on_end_array(self->data);
|
||||
MUSTTAIL return keepGoing(self);
|
||||
@@ -651,27 +642,22 @@ private:
|
||||
return S_REJECT;
|
||||
}
|
||||
static Status objectContinue(Parser2 *self) {
|
||||
if (self->parseLiteral(",") == S_OK) {
|
||||
if (*self->buf == ',') {
|
||||
++self->buf;
|
||||
self->pop();
|
||||
if (Status s = self->push({T_DUBQUOTE, N_STRING, T_COLON, N_VALUE,
|
||||
N_OBJECT_MAYBE_CONTINUE})) {
|
||||
return s;
|
||||
}
|
||||
MUSTTAIL return keepGoing(self);
|
||||
} else if (self->parseLiteral("}") == S_OK) {
|
||||
} else if (*self->buf == '}') {
|
||||
++self->buf;
|
||||
self->pop();
|
||||
self->callbacks->on_end_object(self->data);
|
||||
MUSTTAIL return keepGoing(self);
|
||||
}
|
||||
return S_REJECT;
|
||||
}
|
||||
static Status colon(Parser2 *self) {
|
||||
if (*self->buf++ == ':') {
|
||||
self->pop();
|
||||
MUSTTAIL return keepGoing(self);
|
||||
}
|
||||
return S_REJECT;
|
||||
}
|
||||
static Status finishTrue(Parser2 *self) {
|
||||
if (*self->buf++ == 'e') {
|
||||
self->pop();
|
||||
@@ -697,8 +683,7 @@ private:
|
||||
return S_REJECT;
|
||||
}
|
||||
template <char kChar> static Status singleChar(Parser2 *self) {
|
||||
if (*self->buf == kChar) {
|
||||
++self->buf;
|
||||
if (*self->buf++ == kChar) {
|
||||
self->pop();
|
||||
MUSTTAIL return keepGoing(self);
|
||||
}
|
||||
@@ -706,7 +691,7 @@ private:
|
||||
}
|
||||
|
||||
static constexpr continuation table[N_PAST_END] = {
|
||||
/*T_COLON*/ colon,
|
||||
/*T_COLON*/ singleChar<':'>,
|
||||
/*T_TRUE*/ finishTrue,
|
||||
/*T_FALSE*/ finishFalse,
|
||||
/*T_NULL*/ finishNull,
|
||||
|
||||
Reference in New Issue
Block a user