From ae4b74a6269c8afa624d915daa5634f2a6e3c778 Mon Sep 17 00:00:00 2001 From: Simon Zeni Date: Sun, 19 Dec 2021 16:29:38 -0500 Subject: [PATCH] lexer: fix lineno on push_back --- src/lexer.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lexer.c b/src/lexer.c index 39483fb..b8ee5fe 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -64,7 +64,7 @@ next(struct lexer *lexer, struct location *loc) { int c = getc(lexer->file); if (c == '\n') { - lexer->loc.lineno++; + lexer->loc.lineno += 1; lexer->loc.colno = 1; } else if (c == '\t') { lexer->loc.colno += 8; @@ -86,6 +86,13 @@ static int push_back(struct lexer *lexer) { int c = ungetc(lexer->cur, lexer->file); + + if (c == EOF) { + fatal("failed to ungetc"); + } else if (c == '\n') { + lexer->loc.lineno -= 1; + } + lexer->cur = 0; return c; } -- 2.45.2