From e5cc5fd068f798cfa7e879cf7a14aa737f33aae9 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sun, 27 Nov 2016 21:59:42 -0800 Subject: [PATCH] improve variable name checks --- lips/Lexer.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lips/Lexer.lua b/lips/Lexer.lua index ed01e27..ed7c738 100644 --- a/lips/Lexer.lua +++ b/lips/Lexer.lua @@ -393,10 +393,10 @@ function Lexer:lex(_yield) yield('SEP', ',') elseif self.chr == '[' then self:nextc() - local buff = self:read_chars('[%w_]') - if buff:match('^%d') then + if self.chr:find('%d') then self:error('variable names cannot begin with a number') end + local buff = self:read_chars('[%w_]') if self.chr ~= ']' then self:error('invalid variable name') end @@ -444,6 +444,9 @@ function Lexer:lex(_yield) self:lex_string(yield) elseif self.chr == '@' then self:nextc() + if self.chr:find('%d') then + self:error('variable names cannot begin with a number') + end local buff = self:read_chars('[%w_]') yield('VARSYM', buff) elseif self.chr == '%' then