aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-12-20 13:02:37 +0100
committerlemon <lsof@mailbox.org>2025-12-20 13:16:41 +0100
commitbad03d3c0ba2d438b067a9689c7544108f62289a (patch)
tree2c77f9a73e2f590cd409b526c9f6829abf2d601d
parent2b424fd89b12d7f2eb3a8c9ca872bb4318179d46 (diff)
lexer: fix remnant use of TKEOF for character
-rw-r--r--c/lex.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/c/lex.c b/c/lex.c
index 7bd6ecc..99db463 100644
--- a/c/lex.c
+++ b/c/lex.c
@@ -62,21 +62,19 @@ fillchrbuf(struct lexer *lx)
lx->idx = idx;
}
-static int
+static uchar
next(struct lexer *lx)
{
- int c;
-
if (lx->chrbuf0 >= countof(lx->chrbuf))
fillchrbuf(lx);
lx->chridx = lx->chridxbuf[lx->chrbuf0];
- c = lx->chrbuf[lx->chrbuf0];
+ uchar c = lx->chrbuf[lx->chrbuf0];
lx->eof = lx->chridx >= lx->ndat;
++lx->chrbuf0;
return c;
}
-static int
+static uchar
peek(struct lexer *lx, int off)
{
assert(off < countof(lx->chrbuf));
@@ -86,7 +84,7 @@ peek(struct lexer *lx, int off)
}
static bool
-match(struct lexer *lx, int c)
+match(struct lexer *lx, uchar c)
{
if (!lx->eof && peek(lx, 0) == c) {
next(lx);
@@ -356,7 +354,7 @@ readheadername(struct lexer *lx, struct token *tk, char delim)
beginoff = idx = lx->chridx;
while ((c = next(lx)) != delim) {
- if (c == '\n' || c == TKEOF) {
+ if (c == '\n' || lx->eof) {
span.sl = (struct span0) { idx, lx->chridx - idx, lx->fileid };
error(&span, "missing terminating %c character", delim);
break;
@@ -453,7 +451,7 @@ Begin:
} else if (match(lx, '*')) {
/* comment */
while (!(peek(lx, 0) == '*' && peek(lx, 1) == '/')) {
- if (next(lx) == TKEOF) {
+ if (!next(lx) && lx->eof) {
struct span span = {{ idx, lx->chridx - idx, lx->fileid }};
fatal(&span, "unterminated multiline comment");
}
@@ -693,7 +691,7 @@ static void
ppskipline(struct lexer *lx)
{
while (lx->macstk) popmac(lx);
- while (peek(lx, 0) != '\n' && peek(lx, 0) != TKEOF)
+ while (peek(lx, 0) != '\n' && !lx->eof)
next(lx);
}