support shorthand enums in value-if

This commit is contained in:
2026-08-02 19:44:50 +02:00
parent f25f76adff
commit c92723bc14
3 changed files with 57 additions and 14 deletions
+9
View File
@@ -29,6 +29,8 @@ Parser :: struct {
// At the top level of if/for headers, `|` begins captures. Bitwise OR in
// those headers remains available inside parentheses.
capture_pipe: bool,
// A parenthesized `if` condition ends before a leading-dot brace-less body.
if_condition: bool,
hidden_names: [dynamic]symbol.Id,
}
@@ -1331,6 +1333,10 @@ parse_expression_bp :: proc(parser: ^Parser, minimum_binding_power, nesting: int
})
continue
}
if parser.if_condition && parser.delimiter_depth == 0 &&
parser.module.exprs[left].parenthesized && current(parser).kind == .Dot {
break
}
if current(parser).kind == .Dot {
advance(parser)
if current(parser).kind == .Integer {
@@ -2160,8 +2166,11 @@ parse_if :: proc(parser: ^Parser) -> ast.Stmt_Id {
saved := parser.no_struct_literal
parser.no_struct_literal = true
saved_capture_pipe := parser.capture_pipe
saved_if_condition := parser.if_condition
parser.capture_pipe = true
parser.if_condition = true
condition := parse_expression(parser)
parser.if_condition = saved_if_condition
parser.capture_pipe = saved_capture_pipe
parser.no_struct_literal = saved
captures: [dynamic]symbol.Id