mirror of
https://github.com/vlang/v.git
synced 2025-09-11 08:25:42 -04:00
parser: experimental syntax that doesn't require an extra indent
This commit is contained in:
parent
21cc3c31fe
commit
cb3a106e1d
@ -1267,6 +1267,7 @@ pub mut:
|
|||||||
cond_type Type // type of `x` in `match x {`
|
cond_type Type // type of `x` in `match x {`
|
||||||
expected_type Type // for debugging only
|
expected_type Type // for debugging only
|
||||||
is_sum_type bool
|
is_sum_type bool
|
||||||
|
no_lcbr bool // for match statements without {}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MatchBranch {
|
pub struct MatchBranch {
|
||||||
|
@ -2858,8 +2858,12 @@ fn (mut f Fmt) match_branch(branch ast.MatchBranch, single_line bool) {
|
|||||||
pub fn (mut f Fmt) match_expr(node ast.MatchExpr) {
|
pub fn (mut f Fmt) match_expr(node ast.MatchExpr) {
|
||||||
f.write('match ')
|
f.write('match ')
|
||||||
f.expr(node.cond)
|
f.expr(node.cond)
|
||||||
|
if node.no_lcbr {
|
||||||
|
f.writeln('')
|
||||||
|
} else {
|
||||||
f.writeln(' {')
|
f.writeln(' {')
|
||||||
f.indent++
|
f.indent++
|
||||||
|
}
|
||||||
f.comments(node.comments)
|
f.comments(node.comments)
|
||||||
mut single_line := true
|
mut single_line := true
|
||||||
for branch in node.branches {
|
for branch in node.branches {
|
||||||
@ -2886,8 +2890,10 @@ pub fn (mut f Fmt) match_expr(node ast.MatchExpr) {
|
|||||||
if else_idx >= 0 {
|
if else_idx >= 0 {
|
||||||
f.match_branch(node.branches[else_idx], single_line)
|
f.match_branch(node.branches[else_idx], single_line)
|
||||||
}
|
}
|
||||||
|
if !node.no_lcbr {
|
||||||
f.indent--
|
f.indent--
|
||||||
f.write('}')
|
f.write('}')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut f Fmt) offset_of(node ast.OffsetOf) {
|
pub fn (mut f Fmt) offset_of(node ast.OffsetOf) {
|
||||||
|
@ -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
|
len: match_last_pos.pos - match_first_pos.pos + match_last_pos.len
|
||||||
col: match_first_pos.col
|
col: match_first_pos.col
|
||||||
}
|
}
|
||||||
if p.tok.kind == .rcbr {
|
if p.tok.kind == .rcbr && !no_lcbr {
|
||||||
p.check(.rcbr)
|
p.check(.rcbr)
|
||||||
}
|
}
|
||||||
// return ast.StructInit{}
|
// return ast.StructInit{}
|
||||||
@ -386,6 +386,7 @@ fn (mut p Parser) match_expr() ast.MatchExpr {
|
|||||||
is_sum_type: is_sum_type
|
is_sum_type: is_sum_type
|
||||||
pos: pos
|
pos: pos
|
||||||
comments: comments
|
comments: comments
|
||||||
|
no_lcbr: no_lcbr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
fn test_simple_match_expr() {
|
fn test_simple_match_expr() {
|
||||||
mut a := ?int(12)
|
mut a := ?int(12)
|
||||||
match a? {
|
match a?
|
||||||
12 {
|
12 {
|
||||||
println(a)
|
println(a)
|
||||||
}
|
}
|
||||||
@ -8,9 +8,8 @@ fn test_simple_match_expr() {
|
|||||||
println('else')
|
println('else')
|
||||||
assert false
|
assert false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
match a {
|
match a
|
||||||
none {
|
none {
|
||||||
println('none')
|
println('none')
|
||||||
assert false
|
assert false
|
||||||
@ -18,11 +17,10 @@ fn test_simple_match_expr() {
|
|||||||
else {
|
else {
|
||||||
println('else')
|
println('else')
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
a = none
|
a = none
|
||||||
|
|
||||||
match a {
|
match a
|
||||||
none {
|
none {
|
||||||
println('none')
|
println('none')
|
||||||
}
|
}
|
||||||
@ -30,7 +28,6 @@ fn test_simple_match_expr() {
|
|||||||
println('else')
|
println('else')
|
||||||
assert false
|
assert false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
mut b := ?string('aaa')
|
mut b := ?string('aaa')
|
||||||
match b? {
|
match b? {
|
||||||
@ -43,7 +40,7 @@ fn test_simple_match_expr() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match b {
|
match b
|
||||||
none {
|
none {
|
||||||
println('none')
|
println('none')
|
||||||
assert false
|
assert false
|
||||||
@ -51,10 +48,9 @@ fn test_simple_match_expr() {
|
|||||||
else {
|
else {
|
||||||
println('else')
|
println('else')
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
b = none
|
b = none
|
||||||
match b {
|
match b
|
||||||
none {
|
none {
|
||||||
println('none')
|
println('none')
|
||||||
}
|
}
|
||||||
@ -62,5 +58,5 @@ fn test_simple_match_expr() {
|
|||||||
println('else')
|
println('else')
|
||||||
assert false
|
assert false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user