diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-11-30 14:59:28 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-11-30 14:59:28 -0500 |
| commit | e38ecde989fe378c49a61d6975784ccfb703cfee (patch) | |
| tree | de045602fdc032854a7c2838706d1aaaccdc9746 /parse.c | |
| parent | 18c1ce7fd18c02abda235781db780c9d5fe73ad4 (diff) | |
Explicitly forbid nested optional types
Diffstat (limited to 'parse.c')
| -rw-r--r-- | parse.c | 14 |
1 files changed, 6 insertions, 8 deletions
@@ -632,10 +632,9 @@ type_ast_t *parse_pointer_type(parse_ctx_t *ctx, const char *pos) { "I couldn't parse a pointer type after this point"); type_ast_t *ptr_type = NewTypeAST(ctx->file, start, pos, PointerTypeAST, .pointed=type, .is_view=is_view); spaces(&pos); - if (match(&pos, "?")) - return NewTypeAST(ctx->file, start, pos, OptionalTypeAST, .type=ptr_type); - else - return ptr_type; + while (match(&pos, "?")) + ptr_type = NewTypeAST(ctx->file, start, pos, OptionalTypeAST, .type=ptr_type); + return ptr_type; } type_ast_t *parse_type_name(parse_ctx_t *ctx, const char *pos) { @@ -685,10 +684,9 @@ type_ast_t *parse_type(parse_ctx_t *ctx, const char *pos) { if (!type) return NULL; pos = type->end; spaces(&pos); - if (match(&pos, "?")) - return NewTypeAST(ctx->file, start, pos, OptionalTypeAST, .type=type); - else - return type; + while (match(&pos, "?")) + type = NewTypeAST(ctx->file, start, pos, OptionalTypeAST, .type=type); + return type; } PARSER(parse_num) { |
