diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-06-24 04:18:59 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-06-24 04:20:14 +0200 |
commit | fbaa65a2319745c8a236a5c9c66e3406f42447c3 (patch) | |
tree | d3200a0713af19432aa8aaa0fa7a3c52ae86e89c /src/parser.c | |
parent | 02ce35872c86d4ff056b8121121253fec40bafc0 (diff) |
Support ‘…’ and ‘...’ in initializers
Diffstat (limited to 'src/parser.c')
-rw-r--r-- | src/parser.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/parser.c b/src/parser.c index 5b12e21..46a1fb6 100644 --- a/src/parser.c +++ b/src/parser.c @@ -128,6 +128,7 @@ parsedecl(ast_t *ast, aux_t *aux, lexemes_t toks, bool toplvl) } aux->buf[j].decl.isstatic = toplvl; + aux->buf[j].decl.isundef = false; if (toplvl && toks.kinds[toksidx] == LEXIDENT && strview_eq(SV("pub"), toks.strs[toksidx])) { @@ -165,11 +166,27 @@ parsedecl(ast_t *ast, aux_t *aux, lexemes_t toks, bool toplvl) err("parser: Expected colon, equals, or semicolon"); } - bool func = toks.kinds[toksidx] == LEXLPAR; - if (func && ast->kinds[i] == ASTDECL) - err("Cannot assign function to mutable variable"); + idx_t rhs; + bool func = false; + + switch (toks.kinds[toksidx]) { + case LEXLPAR: + func = true; + if (ast->kinds[i] == ASTDECL) + err("Cannot assign function to mutable variable"); + rhs = parsefunc(ast, aux, toks); + break; + case LEXELIP: + toksidx++; + if (ast->kinds[i] == ASTCDECL) + err("parser: Cannot assign to ‘…’ in constant declaration"); + rhs = AST_EMPTY; + aux->buf[j].decl.isundef = true; + break; + default: + rhs = parseexpr(ast, aux, toks); + } - idx_t rhs = (func ? parsefunc : parseexpr)(ast, aux, toks); ast->kids[i].rhs = rhs; if (!func && toks.kinds[toksidx++] != LEXSEMI) err("parser: Expected semicolon"); |