forked from NeoFlock/noom
lexer: disallow weird lexer number jank
This commit is contained in:
16
src/lexer.c
16
src/lexer.c
@@ -131,6 +131,14 @@ noom_uint_t noomL_getnumber(const char* s, noomL_ErrorType* error, noom_LuaVersi
|
||||
*error = NOOML_ERROR_MALFORMED_NUM;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// check if identifier starter, if so, it's malformed (you can't do a=0xffl=2 or whatevs)
|
||||
if (version >= NOOM_VERSION_51) { // always true for now, but if 5.0 this shouldn't happen.
|
||||
if (noomL_isalpha(s[len]) || s[len] == '_') {
|
||||
*error = NOOML_ERROR_MALFORMED_NUM;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
} else {
|
||||
@@ -170,6 +178,14 @@ noom_uint_t noomL_getnumber(const char* s, noomL_ErrorType* error, noom_LuaVersi
|
||||
}
|
||||
}
|
||||
|
||||
// check if identifier starter, if so, it's malformed (you can't do a=53b=2 or whatevs)
|
||||
if (version >= NOOM_VERSION_51) { // always true for now, but if 5.0 this shouldn't happen.
|
||||
if (noomL_isalpha(s[len]) || s[len] == '_') {
|
||||
*error = NOOML_ERROR_MALFORMED_NUM;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ void print_node(noomP_Node* node, noom_uint_t depth) {
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// uhh uhhh uhhhhh
|
||||
const char* code = "local a = 0x0.1E";
|
||||
const char* code = "local a = 52 local b = 2";
|
||||
noom_uint_t pos = 0;
|
||||
|
||||
printf("LEX OUTPUT:\n");
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
typedef enum noom_LuaVersion {
|
||||
// no 5.0, at least for now, cause it doesn't seem to be used much and is a bit *weird*
|
||||
NOOM_VERSION_51,
|
||||
NOOM_VERSION_52,
|
||||
NOOM_VERSION_53,
|
||||
NOOM_VERSION_54
|
||||
// no you don't get 5.5; if someone wants to do it and maintain it, they can, i'm not gonna.
|
||||
} noom_LuaVersion;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user