Organize members, tweak eof

This commit is contained in:
2025-05-17 17:52:19 -04:00
parent 99e9688efe
commit 01ffe4e15d

View File

@@ -99,7 +99,6 @@ struct Parser2 {
static constexpr int kMaxStackSize = 1 << 10; static constexpr int kMaxStackSize = 1 << 10;
private: private:
bool complete = false;
// Helpers // Helpers
void maybeSkipWs() { void maybeSkipWs() {
while (buf != bufEnd && tables.whitespace[*buf]) { while (buf != bufEnd && tables.whitespace[*buf]) {
@@ -389,11 +388,11 @@ private:
MUSTTAIL return keepGoing(self); MUSTTAIL return keepGoing(self);
} }
static Status eof(Parser2 *self) { static Status eof(Parser2 *self) {
if (self->complete) { if (self->len() > 0) {
return S_OK;
}
return S_REJECT; return S_REJECT;
} }
return self->complete ? S_OK : S_AGAIN;
}
static constexpr continuation table[] = { static constexpr continuation table[] = {
/*T_COLON*/ singleChar<':'>, /*T_COLON*/ singleChar<':'>,
@@ -420,13 +419,6 @@ private:
static_assert(sizeof(table) / sizeof(table[0]) == N_PAST_END); static_assert(sizeof(table) / sizeof(table[0]) == N_PAST_END);
char *buf = nullptr;
char *bufEnd = nullptr;
int len() const { return bufEnd - buf; }
const Callbacks *const callbacks;
void *const data;
Symbol stack[kMaxStackSize];
Symbol *stackPtr = stack;
bool empty() const { return stackPtr == stack; } bool empty() const { return stackPtr == stack; }
void pop() { void pop() {
assert(!empty()); assert(!empty());
@@ -441,4 +433,17 @@ private:
} }
return S_OK; return S_OK;
} }
int len() const {
auto result = bufEnd - buf;
assert(result >= 0);
return result;
}
char *buf = nullptr;
char *bufEnd = nullptr;
const Callbacks *const callbacks;
void *const data;
Symbol stack[kMaxStackSize];
Symbol *stackPtr = stack;
bool complete = false;
}; };