summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-18 12:46:05 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-18 12:46:05 +0000
commita7eceb21faf04762379f2ce4d23d21bbc8c11929 (patch)
tree96816551dab17c4255e9fce32fbb48ce47bb539e /src
parent1d25e066fc1092ecc71a9e593b55427903d697ed (diff)
Deprecate 'repeat' (superfluous), and add named uses.
Diffstat (limited to 'src')
-rw-r--r--src/parser/parser_stmt.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/parser/parser_stmt.c b/src/parser/parser_stmt.c
index d78a9e8..6a0f50d 100644
--- a/src/parser/parser_stmt.c
+++ b/src/parser/parser_stmt.c
@@ -382,7 +382,8 @@ ASTNode *parse_loop(ParserContext *ctx, Lexer *l)
ASTNode *parse_repeat(ParserContext *ctx, Lexer *l)
{
- lexer_next(l);
+ Token t = lexer_next(l);
+ zwarn_at(t, "repeat is deprecated. Use 'for _ in 0..N' instead.");
char *c = rewrite_expr_methods(ctx, parse_condition_raw(ctx, l));
ASTNode *b = parse_block(ctx, l);
ASTNode *n = ast_create(NODE_REPEAT);
@@ -3330,6 +3331,36 @@ ASTNode *parse_struct(ParserContext *ctx, Lexer *l, int is_union)
if (t.type == TOK_USE)
{
lexer_next(l); // eat use
+
+ // Check for named use: use name: Type;
+ Token t1 = lexer_peek(l);
+ Token t2 = lexer_peek2(l);
+
+ if (t1.type == TOK_IDENT && t2.type == TOK_COLON)
+ {
+ // Named use -> Composition (Add field, don't flatten)
+ Token field_name = lexer_next(l);
+ lexer_next(l); // eat :
+ char *field_type_str = parse_type(ctx, l);
+ expect(l, TOK_SEMICOLON, "Expected ;");
+
+ ASTNode *nf = ast_create(NODE_FIELD);
+ nf->field.name = token_strdup(field_name);
+ nf->field.type = field_type_str;
+
+ if (!h)
+ {
+ h = nf;
+ }
+ else
+ {
+ tl->next = nf;
+ }
+ tl = nf;
+ continue;
+ }
+
+ // Normal use -> Mixin (Flatten)
// Parse the type (e.g. Header<I32>)
Type *use_type = parse_type_formal(ctx, l);
char *use_name = type_to_string(use_type);