From 3febafef02bcf1ed68bd7aea9ab504b9785d779a Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sun, 13 Mar 2016 20:26:17 -0700 Subject: [PATCH] fix parsing of files lacking a trailing newline ensures files yield an EOL token before EOF --- lips/Lexer.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lips/Lexer.lua b/lips/Lexer.lua index 33f6ebd..d97883f 100644 --- a/lips/Lexer.lua +++ b/lips/Lexer.lua @@ -28,6 +28,7 @@ function Lexer:init(asm, fn, options) self.pos = 1 self.line = 1 self.EOF = -1 + self.was_EOL = false self:nextc() end @@ -59,6 +60,7 @@ function Lexer:nextc() end self.ord = 10 end + self.was_EOL = self.ord == 10 self.chr = char(self.ord) if self.pos <= #self.asm then @@ -281,6 +283,9 @@ function Lexer:lex(_yield) yield('EOL', '\n') self:nextc() elseif self.ord == self.EOF then + if not self.was_EOL then + yield('EOL', '\n') + end yield('EOF', self.EOF) break elseif self.chr == ';' then