Fix pretty-printing of consecutive idents.
This commit is contained in:
parent
3819b6b3d1
commit
e6af5eeaa2
2 changed files with 12 additions and 6 deletions
|
@ -118,7 +118,8 @@ fn mk_printer(out: io::writer, linewidth: uint) -> printer {
|
|||
mut top: 0u,
|
||||
mut bottom: 0u,
|
||||
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
|
||||
print_stack: dvec<print_stack_elt>,
|
||||
// buffered indentation to avoid writing trailing whitespace
|
||||
mut pending_indentation: int
|
||||
mut pending_indentation: int,
|
||||
mut token_tree_last_was_ident: bool
|
||||
};
|
||||
|
||||
enum printer {
|
||||
|
|
|
@ -622,12 +622,14 @@ fn print_tt(s: ps, tt: ast::token_tree) {
|
|||
for tts.each() |tt_elt| { print_tt(s, tt_elt); }
|
||||
}
|
||||
ast::tt_tok(_, tk) {
|
||||
word(s.s, parse::token::to_str(*s.intr, tk));
|
||||
alt tk {
|
||||
// gotta keep them separated
|
||||
parse::token::IDENT(*) { word(s.s, ~" ") }
|
||||
_ {}
|
||||
parse::token::IDENT(*) { // don't let idents run together
|
||||
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) {
|
||||
word(s.s, ~"$(");
|
||||
|
@ -638,9 +640,11 @@ fn print_tt(s: ps, tt: ast::token_tree) {
|
|||
none {}
|
||||
}
|
||||
word(s.s, if zerok { ~"*" } else { ~"+" });
|
||||
s.s.token_tree_last_was_ident = false;
|
||||
}
|
||||
ast::tt_nonterminal(_, name) {
|
||||
word(s.s, ~"$" + *name);
|
||||
s.s.token_tree_last_was_ident = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue