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

don't use coroutines for lexing

this turned out to be unnecessary,
and some flavors of Lua don't even have coroutines!
This commit is contained in:
Connor Olding 2016-04-20 02:43:01 -07:00
parent a655e67bd3
commit c47136442e

View file

@ -226,27 +226,20 @@ end
function Parser:tokenize(asm) function Parser:tokenize(asm)
self.i = 0 self.i = 0
local routine = coroutine.create(function() local lexer = Lexer(asm, self.main_fn, self.options)
local lexer = Lexer(asm, self.main_fn, self.options)
lexer:lex(coroutine.yield)
end)
local tokens = {} local tokens = {}
while true do
local ok, a, b, c, d = coroutine.resume(routine)
if not ok then
a = a or 'Internal Error: lexer coroutine has stopped'
error(a)
end
assert(a, 'Internal Error: missing token')
local t = Token(c, d, a, b) local loop = true
insert(tokens, t) while loop do
lexer:lex(function(tt, tok, fn, line)
-- don't break if this is an included file's EOF assert(tt, 'Internal Error: missing token')
if t.tt == 'EOF' and t.fn == self.main_fn then local t = Token(fn, line, tt, tok)
break insert(tokens, t)
end -- don't break if this is an included file's EOF
if tt == 'EOF' and fn == self.main_fn then
loop = false
end
end)
end end
local preproc = Preproc(self.options) local preproc = Preproc(self.options)