fmt: extract common code to methods
							parent
							
								
									8497d637d9
								
							
						
					
					
						commit
						cca5c5537f
					
				|  | @ -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('}') | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue