forked from NeoFlock/noom
parser: vararg expr
This commit is contained in:
@@ -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");
|
||||
|
||||
12
src/parser.c
12
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ typedef enum noomP_NodeType {
|
||||
NOOMP_NODE_NILLITERAL,
|
||||
NOOMP_NODE_STRINGLITERAL,
|
||||
|
||||
NOOMP_NODE_VARARGLITERAL,
|
||||
|
||||
NOOMP_NODE_TABLELITERAL,
|
||||
NOOMP_NODE_TABLEENTRY,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user