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