fmt: process `MatchExpr`
parent
4e88c2286e
commit
c1e095e587
|
@ -438,6 +438,29 @@ fn (f mut Fmt) expr(node ast.Expr) {
|
||||||
f.indent--
|
f.indent--
|
||||||
f.write('}')
|
f.write('}')
|
||||||
}
|
}
|
||||||
|
ast.MatchExpr {
|
||||||
|
f.write('match ')
|
||||||
|
f.expr(it.cond)
|
||||||
|
f.writeln(' {')
|
||||||
|
f.indent++
|
||||||
|
for i, expr in it.match_exprs {
|
||||||
|
f.expr(expr)
|
||||||
|
f.writeln(' {')
|
||||||
|
f.stmts(it.blocks[i].stmts)
|
||||||
|
f.writeln('}')
|
||||||
|
}
|
||||||
|
|
||||||
|
else_stmts := it.blocks[it.blocks.len - 1].stmts
|
||||||
|
if (else_stmts.len == 0) {
|
||||||
|
f.writeln('else {}')
|
||||||
|
} else {
|
||||||
|
f.writeln('else {')
|
||||||
|
f.stmts(else_stmts)
|
||||||
|
f.writeln('}')
|
||||||
|
}
|
||||||
|
f.indent--
|
||||||
|
f.write('}')
|
||||||
|
}
|
||||||
ast.MethodCallExpr {
|
ast.MethodCallExpr {
|
||||||
f.expr(it.expr)
|
f.expr(it.expr)
|
||||||
f.write('.' + it.name + '(')
|
f.write('.' + it.name + '(')
|
||||||
|
|
|
@ -158,3 +158,27 @@ fn (f Foo) method_with_or() int {
|
||||||
}
|
}
|
||||||
return 20
|
return 20
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn fn_with_match_expr() {
|
||||||
|
a := 10
|
||||||
|
b := match a {
|
||||||
|
10 {
|
||||||
|
10
|
||||||
|
}
|
||||||
|
5 {
|
||||||
|
5
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match b {
|
||||||
|
10 {
|
||||||
|
println('10')
|
||||||
|
}
|
||||||
|
20 {
|
||||||
|
println('20')
|
||||||
|
}
|
||||||
|
else {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -158,3 +158,27 @@ fn (f Foo) method_with_or() int {
|
||||||
}
|
}
|
||||||
return 20
|
return 20
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn fn_with_match_expr() {
|
||||||
|
a := 10
|
||||||
|
b := match a {
|
||||||
|
10 {
|
||||||
|
10
|
||||||
|
}
|
||||||
|
5 {
|
||||||
|
5
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match b {
|
||||||
|
10 {
|
||||||
|
println('10')
|
||||||
|
}
|
||||||
|
20 {
|
||||||
|
println('20')
|
||||||
|
}
|
||||||
|
else {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue