From 1f17da04f677fc95305219d10834f4dc4e590cf7 Mon Sep 17 00:00:00 2001 From: Blendi Date: Tue, 28 Apr 2026 14:09:55 +0200 Subject: [PATCH] parser: variable attributes --- src/main.c | 2 +- src/parser.c | 34 ++++++++++++++++++++++++++++++++++ src/parser.h | 2 ++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 2641803..3273b21 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,b; a,b = test(), test2() test3()"; + const char* code = "local str , test = 5, 5;"; noom_uint_t pos = 0; printf("LEX OUTPUT:\n"); diff --git a/src/parser.c b/src/parser.c index 886305c..1e1b1bf 100644 --- a/src/parser.c +++ b/src/parser.c @@ -15,6 +15,8 @@ const char *noomP_formatNodeType(noomP_NodeType node_type) { return "while loop"; case NOOMP_NODE_BLOCK: return "block"; + case NOOMP_NODE_ATTRIBUTE: + return "attribute"; case NOOMP_NODE_BREAK: return "break"; case NOOMP_NODE_VARIABLE: @@ -590,6 +592,38 @@ noomP_Node* noomP_parseRawStatement(noomP_Parser* parser) { varname->type = NOOMP_NODE_VARNAME; varname->source_offset = token.offset; + if (parser->version >= NOOM_VERSION_54) { + noomP_peek(parser, &token); + + if (token.type == NOOML_TOKEN_SYMBOL && noom_streql(parser->code + token.offset, token.length, "<", 1)) { + // attribute yay + noomP_skip(parser, &token); + + // the attribute is an identifier. + noomP_peek(parser, &token); + if (token.type != NOOML_TOKEN_IDENTIFIER) return 0; // unexpected + noom_uint_t attr = token.offset; + noomP_skip(parser, &token); + + if (!noom_streql(parser->code + token.offset, token.length, "const", 5) && !noom_streql(parser->code + token.offset, token.length, "close", 5)) { + return 0; // not a real attribute smh my head + } + + noomP_peek(parser, &token); + if (token.type != NOOML_TOKEN_SYMBOL) return 0; + if (!noom_streql(parser->code + token.offset, token.length, ">", 1)) return 0; + noomP_skip(parser, &token); + + noomP_Node* attrn = noomP_allocNode(parser); + if (attr == 0) return 0; + + attrn->type = NOOMP_NODE_ATTRIBUTE; + attrn->source_offset = attr; + + noomP_addSubnode(varname, attrn); + } + } + noomP_addSubnode(localNode, varname); noomP_peek(parser, &token); diff --git a/src/parser.h b/src/parser.h index b926d05..8955c90 100644 --- a/src/parser.h +++ b/src/parser.h @@ -11,6 +11,8 @@ typedef enum noomP_NodeType { NOOMP_NODE_WHILELOOP, NOOMP_NODE_BLOCK, + NOOMP_NODE_ATTRIBUTE, + NOOMP_NODE_BREAK, NOOMP_NODE_VARIABLE,