1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fmt: process MatchExpr

This commit is contained in:
Alexey 2020-02-29 22:43:15 +03:00 committed by GitHub
parent 4e88c2286e
commit c1e095e587
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 71 additions and 0 deletions

View File

@ -438,6 +438,29 @@ fn (f mut Fmt) expr(node ast.Expr) {
f.indent--
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 {
f.expr(it.expr)
f.write('.' + it.name + '(')

View File

@ -158,3 +158,27 @@ fn (f Foo) method_with_or() int {
}
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 {}
}
}

View File

@ -158,3 +158,27 @@ fn (f Foo) method_with_or() int {
}
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 {}
}
}