diff --git a/lips/Collector.lua b/lips/Collector.lua index a41b535..0e3a5b2 100644 --- a/lips/Collector.lua +++ b/lips/Collector.lua @@ -109,8 +109,24 @@ function Collector:directive() self:optional_comma() self:push_data(self:const().tok, name) end + elseif name == 'HEX' then + if self.tt ~= 'OPEN' then + self:error('expected opening brace for hex directive', self.tt) + end + self:advance() + + while self.tt ~= 'CLOSE' do + if self.tt == 'EOL' then + self:advance() + else + self:push_data(self:const().tok, 'BYTE') + end + end + self:advance() elseif name == 'INC' or name == 'INCBIN' then -- noop, handled by lexer + self:string() + return -- don't expect EOL elseif name == 'ASCII' or name == 'ASCIIZ' then local bytes = self:string() for i, number in ipairs(bytes.tok) do diff --git a/lips/Lexer.lua b/lips/Lexer.lua index d035991..3bde74e 100644 --- a/lips/Lexer.lua +++ b/lips/Lexer.lua @@ -193,11 +193,13 @@ function Lexer:lex_hex(yield) end self:nextc() entered = true + yield('OPEN', '{') elseif self.chr == '}' then if not entered then self:error('expected opening brace') end self:nextc() + yield('CLOSE', '}') break elseif self.chr == ',' then self:error('commas are not allowed in HEX directives') @@ -208,7 +210,6 @@ function Lexer:lex_hex(yield) if self.chr:find(hexmatch) then self:error('too many hex digits to be a single byte') end - yield('DIR', 'BYTE') yield('NUM', num) elseif self.chr:find(hexmatch) then self:error('expected two hex digits to make a byte') @@ -294,6 +295,8 @@ function Lexer:lex_include(_yield) self:lex_string_naive(function(tt, tok) fn = tok end) + _yield('STRING', fn, self.fn, self.line) + if self.options.path then fn = self.options.path..fn end @@ -307,6 +310,8 @@ function Lexer:lex_include_binary(_yield) self:lex_string_naive(function(tt, tok) fn = tok end) + _yield('STRING', fn, self.fn, self.line) + -- TODO: allow optional offset and size arguments if self.options.path then fn = self.options.path..fn @@ -414,6 +419,7 @@ function Lexer:lex(_yield) self:nextc() yield('LABEL', buff) elseif up == 'HEX' then + yield('DIR', 'HEX') self:lex_hex(yield) elseif data.all_registers[up] then yield('REG', up)