From 6bc9249094c3de468726f59649dbe45ec7460d5d Mon Sep 17 00:00:00 2001 From: Blendi Date: Mon, 20 Apr 2026 21:48:06 +0200 Subject: [PATCH] lexer: disallow weird lexer number jank --- src/lexer.c | 16 ++++++++++++++++ src/main.c | 2 +- src/noom.h | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/lexer.c b/src/lexer.c index 0508e77..8b8d136 100644 --- a/src/lexer.c +++ b/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; } diff --git a/src/main.c b/src/main.c index 1582e5f..6bf3524 100644 --- a/src/main.c +++ b/src/main.c @@ -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"); diff --git a/src/noom.h b/src/noom.h index 98e0eb9..864f978 100644 --- a/src/noom.h +++ b/src/noom.h @@ -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;