Add some comments

This commit is contained in:
2025-06-24 15:10:01 -04:00
parent 63a1be497b
commit a8aab0187e

View File

@@ -17,6 +17,7 @@
namespace parser3 {
// Calling a continuation with buf == bufEnd means end of input
typedef PRESERVE_NONE WeaselJsonStatus (*Continuation)(struct Parser3 *,
char *buf, char *bufEnd);
@@ -92,6 +93,9 @@ struct Parser3 {
assert(!empty());
--stackPtr;
}
// Pushing symbols onto the stack roughly corresponds with "parse these
// nonterminals/terminals in order"
[[nodiscard]] WeaselJsonStatus push(std::initializer_list<Symbol> symbols) {
if (stackEnd - stackPtr < ptrdiff_t(symbols.size())) [[unlikely]] {
return WeaselJson_OVERFLOW;
@@ -101,6 +105,7 @@ struct Parser3 {
}
return WeaselJson_OK;
}
[[nodiscard]] Symbol top() const {
assert(!empty());
return *(stackPtr - 1);
@@ -165,12 +170,13 @@ inline PRESERVE_NONE WeaselJsonStatus n_whitespace(Parser3 *self, char *buf,
inline PRESERVE_NONE WeaselJsonStatus n_number(Parser3 *self, char *buf,
char *bufEnd) {
bool complete = buf == bufEnd;
if (buf != bufEnd) {
buf = (char *)self->numDfa.scan(buf, bufEnd);
if (buf == bufEnd && !complete) {
if (buf == bufEnd) {
self->flushNumber(false, buf);
return WeaselJson_AGAIN;
}
}
if (!self->numDfa.accept()) [[unlikely]] {
return WeaselJson_REJECT;
}