Skip to content

Commit e6af5ee

Browse files
committed
Fix pretty-printing of consecutive idents.
1 parent 3819b6b commit e6af5ee

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/libsyntax/print/pp.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ fn mk_printer(out: io::writer, linewidth: uint) -> printer {
118118
mut top: 0u,
119119
mut bottom: 0u,
120120
print_stack: dvec(),
121-
mut pending_indentation: 0})
121+
mut pending_indentation: 0,
122+
mut token_tree_last_was_ident: false})
122123
}
123124

124125

@@ -223,7 +224,8 @@ type printer_ = {
223224
// stack of blocks-in-progress being flushed by print
224225
print_stack: dvec<print_stack_elt>,
225226
// buffered indentation to avoid writing trailing whitespace
226-
mut pending_indentation: int
227+
mut pending_indentation: int,
228+
mut token_tree_last_was_ident: bool
227229
};
228230

229231
enum printer {

src/libsyntax/print/pprust.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -622,12 +622,14 @@ fn print_tt(s: ps, tt: ast::token_tree) {
622622
for tts.each() |tt_elt| { print_tt(s, tt_elt); }
623623
}
624624
ast::tt_tok(_, tk) {
625-
word(s.s, parse::token::to_str(*s.intr, tk));
626625
alt tk {
627-
// gotta keep them separated
628-
parse::token::IDENT(*) { word(s.s, ~" ") }
629-
_ {}
626+
parse::token::IDENT(*) { // don't let idents run together
627+
if s.s.token_tree_last_was_ident { word(s.s, ~" ") }
628+
s.s.token_tree_last_was_ident = true;
629+
}
630+
_ { s.s.token_tree_last_was_ident = false; }
630631
}
632+
word(s.s, parse::token::to_str(*s.intr, tk));
631633
}
632634
ast::tt_seq(_, tts, sep, zerok) {
633635
word(s.s, ~"$(");
@@ -638,9 +640,11 @@ fn print_tt(s: ps, tt: ast::token_tree) {
638640
none {}
639641
}
640642
word(s.s, if zerok { ~"*" } else { ~"+" });
643+
s.s.token_tree_last_was_ident = false;
641644
}
642645
ast::tt_nonterminal(_, name) {
643646
word(s.s, ~"$" + *name);
647+
s.s.token_tree_last_was_ident = true;
644648
}
645649
}
646650
}

0 commit comments

Comments
 (0)