harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 576ed6c24483d8bc92564e8cdd0ec663ada38966
parent 556fa4d8842a97bdf7b4c6186fb784a20be38471
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 24 Jan 2021 13:03:22 -0500

parse: fix identifier reordering

Diffstat:
Msrc/parse.c | 25+++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/parse.c b/src/parse.c @@ -188,22 +188,39 @@ static void parse_parameter_list(struct lexer *lexer, struct ast_function_type *type) { trenter(TR_PARSE, "parameter-list"); - struct token tok = {0}; + struct token tok = {0}, tok2 = {0}; bool more = true; type->params = mkfuncparams(&lexer->loc); struct ast_function_parameters *next = type->params; while (more) { switch (lex(lexer, &tok)) { case T_NAME: - next->name = tok.name; - want(lexer, T_COLON, NULL); + switch (lex(lexer, &tok2)) { + case T_COLON: + next->name = tok.name; // Assumes ownership + next->type = parse_type(lexer); + break; + case T_DOUBLE_COLON: + next->type = parse_type(lexer); + synassert(next->type->storage == TYPE_STORAGE_ALIAS, + &tok, T_NAME, T_EOF); + struct identifier *ident = + xcalloc(1, sizeof(struct identifier)); + struct identifier *ns; + ident->name = tok.name; // Assumes ownership + for (ns = &next->type->alias; ns->ns; ns = ns->ns); + ns->ns = ident; + break; + default: + synassert(false, &tok2, T_COLON, T_DOUBLE_COLON, T_EOF); + } break; default: unlex(lexer, &tok); + next->type = parse_type(lexer); break; } - next->type = parse_type(lexer); trace(TR_PARSE, "%s: [type]", next->name); switch (lex(lexer, &tok)) { case T_COMMA: