From da2a7e5bd25055de1573a7f862986522213ed1ca Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Tue, 19 Jul 2011 18:17:49 -0700 Subject: [PATCH] Simple refactoring in the pretty printer. Introduce a proto_to_str function to find the string representation of a given proto instead of casing on the proto in multiple places. --- src/comp/syntax/print/pprust.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index facf0152430..caeba63ffd5 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -848,7 +848,7 @@ fn print_expr(&ps s, &@ast::expr expr) { bclose(s, expr.span); } case (ast::expr_fn(?f)) { - head(s, "fn"); + head(s, proto_to_str(f.proto)); print_fn_args_and_ret(s, f.decl); space(s.s); print_block(s, f.body); @@ -1147,9 +1147,7 @@ fn print_fn(&ps s, ast::fn_decl decl, ast::proto proto, str name, &ast::ty_param[] typarams) { alt (decl.purity) { case (ast::impure_fn) { - if (proto == ast::proto_iter) { - head(s, "iter"); - } else { head(s, "fn"); } + head(s, proto_to_str(proto)); } case (_) { head(s, "pred"); } } @@ -1308,9 +1306,7 @@ fn print_ty_fn(&ps s, &ast::proto proto, &option::t[str] id, &ast::ty_arg[] inputs, &@ast::ty output, &ast::controlflow cf, &(@ast::constr)[] constrs) { ibox(s, indent_unit); - if (proto == ast::proto_fn) { - word(s.s, "fn"); - } else { word(s.s, "iter"); } + word(s.s, proto_to_str(proto)); alt (id) { case (some(?id)) { word(s.s, " "); word(s.s, id); } case (_) { } @@ -1565,6 +1561,13 @@ fn ast_constrs_str(&(@ast::constr)[] constrs) -> str { ret s; } +fn proto_to_str(&ast::proto p) -> str { + ret alt (p) { + ast::proto_fn { "fn" } + ast::proto_iter { "iter" } + }; +} + // // Local Variables: // mode: rust