From 37ff28a3b5700a9f7e3542edd78de3082798a507 Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Sat, 28 Apr 2012 16:30:44 -0400 Subject: [PATCH 1/1] This should fix line counting issues with the lexer --- lex.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lex.c b/lex.c index 671d7a5..deee270 100644 --- a/lex.c +++ b/lex.c @@ -77,14 +77,25 @@ static inline void lex_clear(lex_file *file) { * it's own internal state for this. */ static int lex_inget(lex_file *file) { + char get; file->length --; - if (file->last > 0) - return file->peek[--file->last]; - return fgetc(file->file); + + if (file->last > 0) { + if ((get = file->peek[--file->last]) == '\n') + file->line ++; + return get; + } + if ((get = fgetc(file->file)) == '\n') + file->line++; + + return get; } static void lex_unget(int ch, lex_file *file) { - if (file->last < sizeof(file->peek)) + if (file->last < sizeof(file->peek)) { + if (ch == '\n') + file->line --; file->peek[file->last++] = ch; + } file->length ++; } -- 2.39.2