mirror of
https://github.com/notwa/lips
synced 2024-05-04 02:23:23 -07:00
move arg_types to TokenIter
This commit is contained in:
parent
0d1527a773
commit
fb2e588f79
|
@ -11,14 +11,6 @@ function Collector:init(options)
|
||||||
self.options = options or {}
|
self.options = options or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
Collector.arg_types = { -- for instructions
|
|
||||||
NUM = true,
|
|
||||||
REG = true,
|
|
||||||
VARSYM = true,
|
|
||||||
LABELSYM = true,
|
|
||||||
RELLABELSYM = true,
|
|
||||||
}
|
|
||||||
|
|
||||||
function Collector:statement(...)
|
function Collector:statement(...)
|
||||||
local I = self.iter
|
local I = self.iter
|
||||||
local s = Statement(I.fn, I.line, ...)
|
local s = Statement(I.fn, I.line, ...)
|
||||||
|
@ -186,7 +178,7 @@ function Collector:instruction(name)
|
||||||
I:next()
|
I:next()
|
||||||
elseif I.tt == 'SEP' then
|
elseif I.tt == 'SEP' then
|
||||||
I:error('extraneous comma')
|
I:error('extraneous comma')
|
||||||
elseif not self.arg_types[I.tt] then
|
elseif not I.arg_types[I.tt] then
|
||||||
I:error('unexpected argument type in instruction', I.tt)
|
I:error('unexpected argument type in instruction', I.tt)
|
||||||
else
|
else
|
||||||
insert(s, t)
|
insert(s, t)
|
||||||
|
|
|
@ -16,6 +16,14 @@ function TokenIter:init(tokens)
|
||||||
self:reset()
|
self:reset()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
TokenIter.arg_types = {
|
||||||
|
NUM = true,
|
||||||
|
REG = true,
|
||||||
|
VARSYM = true,
|
||||||
|
LABELSYM = true,
|
||||||
|
RELLABELSYM = true,
|
||||||
|
}
|
||||||
|
|
||||||
function TokenIter:error(msg, got)
|
function TokenIter:error(msg, got)
|
||||||
if got ~= nil then
|
if got ~= nil then
|
||||||
msg = msg..', got '..tostring(got)
|
msg = msg..', got '..tostring(got)
|
||||||
|
@ -176,7 +184,7 @@ function TokenIter:special()
|
||||||
local args = {}
|
local args = {}
|
||||||
while true do
|
while true do
|
||||||
local arg = self:advance()
|
local arg = self:advance()
|
||||||
if not arg_types[arg.tt] then
|
if not self.arg_types[arg.tt] then
|
||||||
self:error('invalid argument type', arg.tt)
|
self:error('invalid argument type', arg.tt)
|
||||||
else
|
else
|
||||||
self:advance()
|
self:advance()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user