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

v2: update MatchExpr in vfmt

This commit is contained in:
Joe Conigliaro 2020-03-04 22:14:37 +11:00
parent e71948461e
commit 5872961124

View File

@ -434,20 +434,29 @@ fn (f mut Fmt) expr(node ast.Expr) {
f.expr(it.cond) f.expr(it.cond)
f.writeln(' {') f.writeln(' {')
f.indent++ f.indent++
for i, expr in it.match_exprs { for i, branch in it.branches {
f.expr(expr) // normal branch
f.writeln(' {') if i < it.branches.len - 1 {
f.stmts(it.blocks[i].stmts) for j,expr in branch.exprs {
f.writeln('}') f.expr(expr)
} if j < branch.exprs.len - 1 {
f.write(', ')
else_stmts := it.blocks[it.blocks.len - 1].stmts }
if (else_stmts.len == 0) { }
f.writeln('else {}') f.writeln(' {')
} else { f.stmts(branch.stmts)
f.writeln('else {') f.writeln('}')
f.stmts(else_stmts) }
f.writeln('}') // else branch
else {
if (branch.stmts.len == 0) {
f.writeln('else {}')
} else {
f.writeln('else {')
f.stmts(branch.stmts)
f.writeln('}')
}
}
} }
f.indent-- f.indent--
f.write('}') f.write('}')