conditional optional unwrapping
This commit is contained in:
@@ -1079,6 +1079,18 @@ parse_if :: proc(parser: ^Parser) -> ast.Stmt_Id {
|
||||
parser.no_struct_literal = true
|
||||
condition := parse_expression(parser)
|
||||
parser.no_struct_literal = saved
|
||||
binding := symbol.INVALID
|
||||
if _, ok := allow(parser, .Pipe); ok {
|
||||
name_tok, name_ok := allow(parser, .Identifier)
|
||||
if name_ok {
|
||||
binding = name_tok.symbol
|
||||
} else {
|
||||
source.add(parser.diagnostics, current(parser).span, "expected a binding name after '|'")
|
||||
}
|
||||
if _, close_ok := allow(parser, .Pipe); !close_ok {
|
||||
source.add(parser.diagnostics, current(parser).span, "expected '|' to close the unwrap binding")
|
||||
}
|
||||
}
|
||||
skip_newlines(parser)
|
||||
then_body := parse_block(parser)
|
||||
else_body: []ast.Stmt_Id = nil
|
||||
@@ -1102,6 +1114,7 @@ parse_if :: proc(parser: ^Parser) -> ast.Stmt_Id {
|
||||
append(&parser.module.statements, ast.Stmt{
|
||||
kind=.If,
|
||||
span=span_from(start.span, previous(parser).span),
|
||||
name=binding,
|
||||
expr=condition,
|
||||
body=then_body,
|
||||
else_body=else_body,
|
||||
|
||||
Reference in New Issue
Block a user