unify catch fallback value sources

This commit is contained in:
2026-07-22 00:37:48 +02:00
parent 17508ff751
commit 5f343ad2d3
12 changed files with 1048397 additions and 324314 deletions
+21 -1
View File
@@ -1470,8 +1470,9 @@ parse_expression_bp :: proc(parser: ^Parser, minimum_binding_power, nesting: int
skip_newlines(parser)
if operator.kind == .Keyword_Catch {
left_expr := parser.module.exprs[left]
capture := token.Token{}
if _, pipe_ok := allow(parser, .Pipe); pipe_ok {
capture := current(parser)
capture = current(parser)
if capture.kind != .Identifier && capture.kind != .Underscore {
source.add(parser.diagnostics, capture.span, "expected a catch capture name")
} else {
@@ -1480,6 +1481,9 @@ parse_expression_bp :: proc(parser: ^Parser, minimum_binding_power, nesting: int
if _, close_ok := allow(parser, .Pipe); !close_ok {
source.add(parser.diagnostics, current(parser).span, "expected '|' after catch capture")
}
skip_newlines(parser)
}
if current(parser).kind == .Left_Brace {
body := parse_block(parser)
end := previous(parser)
left = add_expr(parser, ast.Expr{
@@ -1493,11 +1497,27 @@ parse_expression_bp :: proc(parser: ^Parser, minimum_binding_power, nesting: int
})
continue
}
if cf, is_cf := parse_value_control_flow(parser); is_cf {
body := make([]ast.Stmt_Id, 1, parser.module.allocator)
body[0] = cf
left = add_expr(parser, ast.Expr{
kind=.Catch,
span=span_from(left_expr.span, parser.module.statements[cf].span),
name=capture.symbol,
left=left,
right=ast.INVALID_EXPR,
body=body,
integer=1,
diagnostic=source.INVALID_DIAGNOSTIC,
})
continue
}
right := parse_expression_bp(parser, right_power, nesting+1)
right_expr := parser.module.exprs[right]
left = add_expr(parser, ast.Expr{
kind=.Catch,
span=span_from(left_expr.span, right_expr.span),
name=capture.symbol,
left=left,
right=right,
diagnostic=source.INVALID_DIAGNOSTIC,