diff options
| author | suresh <sureshkrishnan.ai@gmail.com> | 2026-01-25 11:43:23 -0500 |
|---|---|---|
| committer | suresh <sureshkrishnan.ai@gmail.com> | 2026-01-25 11:43:23 -0500 |
| commit | 26a0b55ed5bce4ad0ba2af109cfc96da7be2e34c (patch) | |
| tree | 35ba8d7742b8ac727bfc6c4c73ab8b70f6eedb53 /src/parser/parser_type.c | |
| parent | 0bb69cb67078dfa921b5b8a42275ef31dfbc9a56 (diff) | |
| parent | 489336b2101bf16edeec7bfc4379408eb19b936e (diff) | |
Merge branch 'main' into JsonType
# Conflicts:
# examples/data/json_config.zc
Diffstat (limited to 'src/parser/parser_type.c')
| -rw-r--r-- | src/parser/parser_type.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/parser/parser_type.c b/src/parser/parser_type.c index 5774571..0585baa 100644 --- a/src/parser/parser_type.c +++ b/src/parser/parser_type.c @@ -751,14 +751,31 @@ Type *parse_type_formal(ParserContext *ctx, Lexer *l) } } + Type *t = NULL; + // Example: fn(int, int) -> int if (lexer_peek(l).type == TOK_IDENT && strncmp(lexer_peek(l).start, "fn", 2) == 0 && lexer_peek(l).len == 2) { lexer_next(l); // eat 'fn' + + int star_count = 0; + while (lexer_peek(l).type == TOK_OP && strncmp(lexer_peek(l).start, "*", 1) == 0) + { + lexer_next(l); + star_count++; + } + Type *fn_type = type_new(TYPE_FUNCTION); + fn_type->is_raw = (star_count > 0); fn_type->is_varargs = 0; + Type *wrapped = fn_type; + for (int i = 1; i < star_count; i++) + { + wrapped = type_new_ptr(wrapped); + } + expect(l, TOK_LPAREN, "Expected '(' for function type"); // Parse Arguments @@ -794,11 +811,13 @@ Type *parse_type_formal(ParserContext *ctx, Lexer *l) fn_type->inner = type_new(TYPE_VOID); } - return fn_type; + t = wrapped; + } + else + { + // Handles: int, Struct, Generic<T>, [Slice], (Tuple) + t = parse_type_base(ctx, l); } - - // Handles: int, Struct, Generic<T>, [Slice], (Tuple) - Type *t = parse_type_base(ctx, l); // Handles: T*, T**, etc. while (lexer_peek(l).type == TOK_OP && *lexer_peek(l).start == '*') |
