From e0ffcfb74bdb3cfe37d53911ea91a18cc7518224 Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Mon, 20 Aug 2012 18:12:04 +0200 Subject: [PATCH] Lexer now returns TOKEN_EOF only once and afterwards TOKEN_FATAL --- lexer.c | 8 +++++++- lexer.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lexer.c b/lexer.c index d9483d8..8416255 100644 --- a/lexer.c +++ b/lexer.c @@ -146,6 +146,7 @@ lex_file* lex_open(const char *file) lex->line = 1; /* we start counting at 1 */ lex->peekpos = 0; + lex->eof = false; lex_filenames_add(lex->name); @@ -557,8 +558,13 @@ int lex_do(lex_file *lex) lex->tok->ctx.line = lex->sline; lex->tok->ctx.file = lex->name; - if (ch == EOF) + if (lex->eof) + return (lex->tok->ttype = TOKEN_FATAL); + + if (ch == EOF) { + lex->eof = true; return (lex->tok->ttype = TOKEN_EOF); + } /* modelgen / spiritgen commands */ if (ch == '$') { diff --git a/lexer.h b/lexer.h index b3114ec..6cdb5a5 100644 --- a/lexer.h +++ b/lexer.h @@ -95,6 +95,8 @@ typedef struct { char peek[256]; size_t peekpos; + bool eof; + token *tok; struct { -- 2.39.2