Minor rearrange for parsing field lists

This commit is contained in:
gingerBill
2025-02-22 17:58:14 +00:00
parent 875dbf3140
commit de755f95ec
+25 -22
View File
@@ -4342,7 +4342,31 @@ gb_internal Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_fl
} }
if (f->curr_token.kind == Token_Colon) { if (f->curr_token.kind != Token_Colon) {
// NOTE(bill): proc(Type, Type, Type)
for (AstAndFlags const &item : list) {
Ast *type = item.node;
Token token = blank_token;
if (allowed_flags&FieldFlag_Results) {
// NOTE(bill): Make this nothing and not `_`
token.string = str_lit("");
}
auto names = array_make<Ast *>(ast_allocator(f), 1);
token.pos = ast_token(type).pos;
names[0] = ast_ident(f, token);
u32 flags = check_field_prefixes(f, list.count, allowed_flags, item.flags);
Token tag = {};
Ast *param = ast_field(f, names, item.node, nullptr, flags, tag, docs, f->line_comment);
array_add(&params, param);
}
if (name_count_) *name_count_ = total_name_count;
return ast_field_list(f, start_token, params);
}
// NOTE(bill): proc(ident, ident, ident: Type)
if (f->prev_token.kind == Token_Comma) { if (f->prev_token.kind == Token_Comma) {
syntax_error(f->prev_token, "Trailing comma before a colon is not allowed"); syntax_error(f->prev_token, "Trailing comma before a colon is not allowed");
} }
@@ -4489,27 +4513,6 @@ gb_internal Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_fl
} }
} }
if (name_count_) *name_count_ = total_name_count;
return ast_field_list(f, start_token, params);
}
for (AstAndFlags const &item : list) {
Ast *type = item.node;
Token token = blank_token;
if (allowed_flags&FieldFlag_Results) {
// NOTE(bill): Make this nothing and not `_`
token.string = str_lit("");
}
auto names = array_make<Ast *>(ast_allocator(f), 1);
token.pos = ast_token(type).pos;
names[0] = ast_ident(f, token);
u32 flags = check_field_prefixes(f, list.count, allowed_flags, item.flags);
Token tag = {};
Ast *param = ast_field(f, names, item.node, nullptr, flags, tag, docs, f->line_comment);
array_add(&params, param);
}
if (name_count_) *name_count_ = total_name_count; if (name_count_) *name_count_ = total_name_count;
return ast_field_list(f, start_token, params); return ast_field_list(f, start_token, params);
} }