Skip to content

Commit 4c1d3ee

Browse files
committed
---
yaml --- r: 2879 b: refs/heads/master c: e5dc138 h: refs/heads/master i: 2877: 01d2367 2875: ca38ac9 2871: e38a1cb 2863: 63f7c32 2847: e06fb18 2815: 73ae07d v: v3
1 parent e417fe9 commit 4c1d3ee

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 681f0c7a2b2f83b34f9c0f22ca8e109b047df13a
2+
refs/heads/master: e5dc138dfa53d0351031b4955f697b6ac808afae

trunk/src/comp/pretty/pp.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ fn mk_printer(io::writer out, uint linewidth) -> printer {
131131
true, // scan_stack_empty
132132
0u, // top
133133
0u, // bottom
134-
print_stack);
134+
print_stack,
135+
0);
135136
}
136137

137138
/*
@@ -236,7 +237,10 @@ obj printer(io::writer out,
236237
mutable uint bottom, // index of bottom of scan_stack
237238

238239
// stack of blocks-in-progress being flushed by print
239-
mutable vec[print_stack_elt] print_stack
240+
mutable vec[print_stack_elt] print_stack,
241+
242+
// buffered indentation to avoid writing trailing whitespace
243+
mutable int pending_indentation
240244
) {
241245

242246

@@ -430,16 +434,13 @@ obj printer(io::writer out,
430434
fn print_newline(int amount) {
431435
log #fmt("NEWLINE %d", amount);
432436
out.write_str("\n");
437+
pending_indentation = 0;
433438
self.indent(amount);
434439
}
435440

436441
fn indent(int amount) {
437442
log #fmt("INDENT %d", amount);
438-
auto u = 0;
439-
while (u < amount) {
440-
out.write_str(" ");
441-
u += 1;
442-
}
443+
pending_indentation += amount;
443444
}
444445

445446
fn top() -> print_stack_elt {
@@ -452,6 +453,14 @@ obj printer(io::writer out,
452453
ret top;
453454
}
454455

456+
fn write_str(str s) {
457+
while (pending_indentation > 0) {
458+
out.write_str(" ");
459+
pending_indentation -= 1;
460+
}
461+
out.write_str(s);
462+
}
463+
455464
fn print(token x, int L) {
456465
log #fmt("print %s %d (remaining line space=%d)",
457466
tok_str(x), L, space);
@@ -515,7 +524,7 @@ obj printer(io::writer out,
515524
assert L == len;
516525
// assert L <= space;
517526
space -= len;
518-
out.write_str(s);
527+
self.write_str(s);
519528
}
520529

521530
case (EOF) {

0 commit comments

Comments
 (0)