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.
This commit is contained in:
parent
9bd945639b
commit
da2a7e5bd2
@ -848,7 +848,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
|
|||||||
bclose(s, expr.span);
|
bclose(s, expr.span);
|
||||||
}
|
}
|
||||||
case (ast::expr_fn(?f)) {
|
case (ast::expr_fn(?f)) {
|
||||||
head(s, "fn");
|
head(s, proto_to_str(f.proto));
|
||||||
print_fn_args_and_ret(s, f.decl);
|
print_fn_args_and_ret(s, f.decl);
|
||||||
space(s.s);
|
space(s.s);
|
||||||
print_block(s, f.body);
|
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) {
|
&ast::ty_param[] typarams) {
|
||||||
alt (decl.purity) {
|
alt (decl.purity) {
|
||||||
case (ast::impure_fn) {
|
case (ast::impure_fn) {
|
||||||
if (proto == ast::proto_iter) {
|
head(s, proto_to_str(proto));
|
||||||
head(s, "iter");
|
|
||||||
} else { head(s, "fn"); }
|
|
||||||
}
|
}
|
||||||
case (_) { head(s, "pred"); }
|
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::ty_arg[] inputs, &@ast::ty output,
|
||||||
&ast::controlflow cf, &(@ast::constr)[] constrs) {
|
&ast::controlflow cf, &(@ast::constr)[] constrs) {
|
||||||
ibox(s, indent_unit);
|
ibox(s, indent_unit);
|
||||||
if (proto == ast::proto_fn) {
|
word(s.s, proto_to_str(proto));
|
||||||
word(s.s, "fn");
|
|
||||||
} else { word(s.s, "iter"); }
|
|
||||||
alt (id) {
|
alt (id) {
|
||||||
case (some(?id)) { word(s.s, " "); word(s.s, id); }
|
case (some(?id)) { word(s.s, " "); word(s.s, id); }
|
||||||
case (_) { }
|
case (_) { }
|
||||||
@ -1565,6 +1561,13 @@ fn ast_constrs_str(&(@ast::constr)[] constrs) -> str {
|
|||||||
ret s;
|
ret s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn proto_to_str(&ast::proto p) -> str {
|
||||||
|
ret alt (p) {
|
||||||
|
ast::proto_fn { "fn" }
|
||||||
|
ast::proto_iter { "iter" }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Local Variables:
|
// Local Variables:
|
||||||
// mode: rust
|
// mode: rust
|
||||||
|
Loading…
x
Reference in New Issue
Block a user