1
0
Fork 0
mirror of https://github.com/notwa/lips synced 2024-11-14 09:59:03 -08:00

fix parsing of files lacking a trailing newline

ensures files yield an EOL token before EOF
This commit is contained in:
Connor Olding 2016-03-13 20:26:17 -07:00
parent 54f28dc333
commit 3febafef02

View file

@ -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