mirror of https://github.com/rusefi/lua.git
Syntax should not allow numbers touching identifiers
Code like 'a = 1print()' should not be accepted.
This commit is contained in:
parent
8004798b03
commit
65d1aa7a77
2
llex.c
2
llex.c
|
@ -228,6 +228,8 @@ static int read_numeral (LexState *ls, SemInfo *seminfo) {
|
||||||
save_and_next(ls);
|
save_and_next(ls);
|
||||||
else break;
|
else break;
|
||||||
}
|
}
|
||||||
|
if (lislalnum(ls->current)) /* is numeral touching an alpha num? */
|
||||||
|
save_and_next(ls); /* force an error */
|
||||||
save(ls, '\0');
|
save(ls, '\0');
|
||||||
if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0) /* format error? */
|
if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0) /* format error? */
|
||||||
lexerror(ls, "malformed number", TK_FLT);
|
lexerror(ls, "malformed number", TK_FLT);
|
||||||
|
|
|
@ -306,4 +306,13 @@ assert(not load"a = 'non-ending string\n'")
|
||||||
assert(not load"a = '\\345'")
|
assert(not load"a = '\\345'")
|
||||||
assert(not load"a = [=x]")
|
assert(not load"a = [=x]")
|
||||||
|
|
||||||
|
local function malformednum (n, exp)
|
||||||
|
local s, msg = load("return " .. n)
|
||||||
|
assert(not s and string.find(msg, exp))
|
||||||
|
end
|
||||||
|
|
||||||
|
malformednum("0xe-", "near <eof>")
|
||||||
|
malformednum("0xep-p", "malformed number")
|
||||||
|
malformednum("1print()", "malformed number")
|
||||||
|
|
||||||
print('OK')
|
print('OK')
|
||||||
|
|
Loading…
Reference in New Issue