diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 86202835d0..9ac38a7f0d 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -330,24 +330,9 @@ fn (f mut Fmt) expr(node ast.Expr) { } ast.CallExpr { f.write('${it.name}(') - for i, arg in it.args { - if it.muts[i] { - f.write('mut ') - } - if i > 0 { - f.wrap_long_line() - } - f.expr(arg) - if i < it.args.len - 1 { - f.write(', ') - } - } + f.call_args(it.args, it.muts) f.write(')') - if it.or_block.stmts.len > 0 { - f.writeln(' or {') - f.stmts(it.or_block.stmts) - f.write('}') - } + f.or_expr(it.or_block) } ast.CharLiteral { f.write('`$it.val`') @@ -464,24 +449,9 @@ fn (f mut Fmt) expr(node ast.Expr) { ast.MethodCallExpr { f.expr(it.expr) f.write('.' + it.name + '(') - for i, arg in it.args { - if it.muts[i] { - f.write('mut ') - } - if i > 0 { - f.wrap_long_line() - } - f.expr(arg) - if i < it.args.len - 1 { - f.write(', ') - } - } + f.call_args(it.args, it.muts) f.write(')') - if it.or_block.stmts.len > 0 { - f.writeln(' or {') - f.stmts(it.or_block.stmts) - f.write('}') - } + f.or_expr(it.or_block) } ast.None { f.write('none') @@ -549,3 +519,26 @@ fn (f mut Fmt) wrap_long_line() { f.line_len = 0 } } + +fn (f mut Fmt) call_args(args []ast.Expr, muts []bool) { + for i, arg in args { + if muts[i] { + f.write('mut ') + } + if i > 0 { + f.wrap_long_line() + } + f.expr(arg) + if i < args.len - 1 { + f.write(', ') + } + } +} + +fn (f mut Fmt) or_expr(or_block ast.OrExpr) { + if or_block.stmts.len > 0 { + f.writeln(' or {') + f.stmts(or_block.stmts) + f.write('}') + } +}