From aed58078e92d8b7165876c443e1927fc47314bd4 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 24 Jun 2025 09:47:17 +0300 Subject: [PATCH] Revert "parser: experimental syntax that doesn't require an extra indent" This reverts commit cb3a106e1dcf1eb9200ecf4d7ca08e8c0c19b6e3. --- vlib/v/ast/ast.v | 1 - vlib/v/fmt/fmt.v | 14 ++--- vlib/v/parser/if_match.v | 3 +- vlib/v/tests/options/option_match_test.v | 76 +++++++++++++----------- 4 files changed, 45 insertions(+), 49 deletions(-) diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index e6df84d0d..e696a215c 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -1267,7 +1267,6 @@ pub mut: cond_type Type // type of `x` in `match x {` expected_type Type // for debugging only is_sum_type bool - no_lcbr bool // for match statements without {} } pub struct MatchBranch { diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 569f691e5..7029ee7c9 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -2858,12 +2858,8 @@ fn (mut f Fmt) match_branch(branch ast.MatchBranch, single_line bool) { pub fn (mut f Fmt) match_expr(node ast.MatchExpr) { f.write('match ') f.expr(node.cond) - if node.no_lcbr { - f.writeln('') - } else { - f.writeln(' {') - f.indent++ - } + f.writeln(' {') + f.indent++ f.comments(node.comments) mut single_line := true for branch in node.branches { @@ -2890,10 +2886,8 @@ pub fn (mut f Fmt) match_expr(node ast.MatchExpr) { if else_idx >= 0 { f.match_branch(node.branches[else_idx], single_line) } - if !node.no_lcbr { - f.indent-- - f.write('}') - } + f.indent-- + f.write('}') } pub fn (mut f Fmt) offset_of(node ast.OffsetOf) { diff --git a/vlib/v/parser/if_match.v b/vlib/v/parser/if_match.v index 3edb3da7f..0327d306f 100644 --- a/vlib/v/parser/if_match.v +++ b/vlib/v/parser/if_match.v @@ -375,7 +375,7 @@ fn (mut p Parser) match_expr() ast.MatchExpr { len: match_last_pos.pos - match_first_pos.pos + match_last_pos.len col: match_first_pos.col } - if p.tok.kind == .rcbr && !no_lcbr { + if p.tok.kind == .rcbr { p.check(.rcbr) } // return ast.StructInit{} @@ -386,7 +386,6 @@ fn (mut p Parser) match_expr() ast.MatchExpr { is_sum_type: is_sum_type pos: pos comments: comments - no_lcbr: no_lcbr } } diff --git a/vlib/v/tests/options/option_match_test.v b/vlib/v/tests/options/option_match_test.v index 24995910a..ef9e08221 100644 --- a/vlib/v/tests/options/option_match_test.v +++ b/vlib/v/tests/options/option_match_test.v @@ -1,32 +1,35 @@ fn test_simple_match_expr() { mut a := ?int(12) - match a? - 12 { - println(a) - } - else { - println('else') - assert false + match a? { + 12 { + println(a) + } + else { + println('else') + assert false + } } - match a - none { - println('none') - assert false - } - else { - println('else') + match a { + none { + println('none') + assert false + } + else { + println('else') + } } a = none - match a - none { - println('none') - } - else { - println('else') - assert false + match a { + none { + println('none') + } + else { + println('else') + assert false + } } mut b := ?string('aaa') @@ -40,23 +43,24 @@ fn test_simple_match_expr() { } } - match b - none { - println('none') - assert false - } - else { - println('else') + match b { + none { + println('none') + assert false + } + else { + println('else') + } } b = none - match b - none { - println('none') - } - else { - println('else') - assert false + match b { + none { + println('none') + } + else { + println('else') + assert false + } } - } -- 2.39.5