From cca5c5537ff54e37b1526509d0170f26e40e6010 Mon Sep 17 00:00:00 2001 From: Alexey Date: Mon, 2 Mar 2020 19:09:45 +0300 Subject: [PATCH] fmt: extract common code to methods --- vlib/v/fmt/fmt.v | 61 +++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 34 deletions(-) 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('}') + } +}