Return token from nextToken again

This commit is contained in:
2025-05-13 11:29:28 -04:00
parent 30c9ad8690
commit 64a3b8ac8c

View File

@@ -500,8 +500,8 @@ private:
typedef PRESERVE_NONE bool (*continuation)(Parser2 *);
[[maybe_unused]] void printStack() {
printf("token: %s\n", symbolNames[currentToken]);
[[maybe_unused]] void debugPrint(Symbol token) {
printf("token: %s\n", symbolNames[token]);
for (int i = 0; i < stackPtr - stack; ++i) {
printf("%s ", symbolNames[stack[i]]);
}
@@ -514,13 +514,13 @@ private:
}
PRESERVE_NONE static bool keepGoing(Parser2 *self) {
// self->printStack();
if (self->empty()) {
assert(self->currentToken == T_EOF);
return true;
}
self->nextToken();
MUSTTAIL return table[*(self->stackPtr - 1)][self->currentToken](self);
auto token = self->nextToken();
// self->debugPrint(token);
MUSTTAIL return table[*(self->stackPtr - 1)][token](self);
}
PRESERVE_NONE static bool reject(Parser2 *self) {
@@ -781,71 +781,55 @@ private:
},
};
Symbol currentToken;
const char *bufBefore;
void nextToken() {
Symbol nextToken() {
maybeSkipWs();
bufBefore = buf;
if (len == 0) {
currentToken = T_EOF;
return;
return T_EOF;
}
if (*buf == '{') {
parseLiteral("{");
currentToken = T_LBRACE;
return;
return T_LBRACE;
} else if (*buf == '[') {
parseLiteral("[");
currentToken = T_LBRACKET;
return;
return T_LBRACKET;
} else if (*buf == '}') {
parseLiteral("}");
currentToken = T_RBRACE;
return;
return T_RBRACE;
} else if (*buf == ']') {
parseLiteral("]");
currentToken = T_RBRACKET;
return;
return T_RBRACKET;
} else if (*buf == ':') {
parseLiteral(":");
currentToken = T_COLON;
return;
return T_COLON;
} else if (*buf == ',') {
parseLiteral(",");
currentToken = T_COMMA;
return;
return T_COMMA;
} else if (*buf == '"') {
if (!parse_string()) {
currentToken = T_INVALID;
return;
return T_INVALID;
}
currentToken = T_STRING;
return;
return T_STRING;
} else if (*buf == 't') {
if (!parseLiteral("true")) {
currentToken = T_INVALID;
return;
return T_INVALID;
}
currentToken = T_ATOM;
return;
return T_ATOM;
} else if (*buf == 'f') {
if (!parseLiteral("false")) {
currentToken = T_INVALID;
return;
return T_INVALID;
}
} else if (*buf == 'n') {
if (!parseLiteral("null")) {
currentToken = T_INVALID;
return;
return T_INVALID;
}
} else {
if (!parse_number()) {
currentToken = T_INVALID;
return;
return T_INVALID;
}
}
currentToken = T_ATOM;
return;
return T_ATOM;
}
char *buf;