From 861fffb244501e27c0490d0b47bc3605aefe8cc2 Mon Sep 17 00:00:00 2001 From: Blendi Date: Tue, 5 May 2026 20:08:08 +0200 Subject: [PATCH] parser: vararg expr --- src/main.c | 2 +- src/parser.c | 12 ++++++++++++ src/parser.h | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 5a61af0..debc961 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 = "repeat print('hi') until false"; + const char* code = "function a(...) print(...) end"; noom_uint_t pos = 0; printf("LEX OUTPUT:\n"); diff --git a/src/parser.c b/src/parser.c index 25a1ff8..b6a2128 100644 --- a/src/parser.c +++ b/src/parser.c @@ -37,6 +37,8 @@ const char *noomP_formatNodeType(noomP_NodeType node_type) { return "nil literal"; case NOOMP_NODE_STRINGLITERAL: return "string literal"; + case NOOMP_NODE_VARARGLITERAL: + return "vararg literal"; case NOOMP_NODE_TABLELITERAL: return "table literal"; case NOOMP_NODE_TABLEENTRY: @@ -597,6 +599,16 @@ noomP_Node* noomP_parseRawExpression(noomP_Parser* parser) { if (table == 0) return 0; return table; + } else if (noom_streql(parser->code + token.offset, token.length, "...", 3)) { + noomP_skip(parser, &token); + + noomP_Node* new = noomP_allocNode(parser); + if (new == 0) return 0; + + new->type = NOOMP_NODE_VARARGLITERAL; + new->source_offset = token.offset; + + return new; } } diff --git a/src/parser.h b/src/parser.h index 60e04c2..726b912 100644 --- a/src/parser.h +++ b/src/parser.h @@ -25,6 +25,8 @@ typedef enum noomP_NodeType { NOOMP_NODE_NILLITERAL, NOOMP_NODE_STRINGLITERAL, + NOOMP_NODE_VARARGLITERAL, + NOOMP_NODE_TABLELITERAL, NOOMP_NODE_TABLEENTRY,