Fix pretty-printing of consecutive idents.

This commit is contained in:
Paul Stansifer
2012-07-30 17:56:53 -07:00
parent 3819b6b3d1
commit e6af5eeaa2
2 changed files with 12 additions and 6 deletions

View File

@@ -118,7 +118,8 @@ fn mk_printer(out: io::writer, linewidth: uint) -> printer {
mut top: 0u, mut top: 0u,
mut bottom: 0u, mut bottom: 0u,
print_stack: dvec(), print_stack: dvec(),
mut pending_indentation: 0}) mut pending_indentation: 0,
mut token_tree_last_was_ident: false})
} }
@@ -223,7 +224,8 @@ type printer_ = {
// stack of blocks-in-progress being flushed by print // stack of blocks-in-progress being flushed by print
print_stack: dvec<print_stack_elt>, print_stack: dvec<print_stack_elt>,
// buffered indentation to avoid writing trailing whitespace // buffered indentation to avoid writing trailing whitespace
mut pending_indentation: int mut pending_indentation: int,
mut token_tree_last_was_ident: bool
}; };
enum printer { enum printer {

View File

@@ -622,12 +622,14 @@ fn print_tt(s: ps, tt: ast::token_tree) {
for tts.each() |tt_elt| { print_tt(s, tt_elt); } for tts.each() |tt_elt| { print_tt(s, tt_elt); }
} }
ast::tt_tok(_, tk) { ast::tt_tok(_, tk) {
word(s.s, parse::token::to_str(*s.intr, tk));
alt tk { alt tk {
// gotta keep them separated parse::token::IDENT(*) { // don't let idents run together
parse::token::IDENT(*) { word(s.s, ~" ") } if s.s.token_tree_last_was_ident { word(s.s, ~" ") }
_ {} s.s.token_tree_last_was_ident = true;
}
_ { s.s.token_tree_last_was_ident = false; }
} }
word(s.s, parse::token::to_str(*s.intr, tk));
} }
ast::tt_seq(_, tts, sep, zerok) { ast::tt_seq(_, tts, sep, zerok) {
word(s.s, ~"$("); word(s.s, ~"$(");
@@ -638,9 +640,11 @@ fn print_tt(s: ps, tt: ast::token_tree) {
none {} none {}
} }
word(s.s, if zerok { ~"*" } else { ~"+" }); word(s.s, if zerok { ~"*" } else { ~"+" });
s.s.token_tree_last_was_ident = false;
} }
ast::tt_nonterminal(_, name) { ast::tt_nonterminal(_, name) {
word(s.s, ~"$" + *name); word(s.s, ~"$" + *name);
s.s.token_tree_last_was_ident = true;
} }
} }
} }