parser: vararg expr

This commit is contained in:
2026-05-05 20:08:08 +02:00
parent 67eb3fc552
commit 861fffb244
3 changed files with 15 additions and 1 deletions

View File

@@ -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");

View File

@@ -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;
}
}

View File

@@ -25,6 +25,8 @@ typedef enum noomP_NodeType {
NOOMP_NODE_NILLITERAL,
NOOMP_NODE_STRINGLITERAL,
NOOMP_NODE_VARARGLITERAL,
NOOMP_NODE_TABLELITERAL,
NOOMP_NODE_TABLEENTRY,