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

fmt: extract common code to methods

This commit is contained in:
Alexey 2020-03-02 19:09:45 +03:00 committed by GitHub
parent 8497d637d9
commit cca5c5537f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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('}')
}
}