Skip to content

Commit 331333f

Browse files
committed
---
yaml --- r: 11017 b: refs/heads/master c: 099290b h: refs/heads/master i: 11015: 9f8428a v: v3
1 parent 55d84d6 commit 331333f

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: c0f9073557b5daed86aea411fb4c56e554583af2
2+
refs/heads/master: 099290bc7385477ab6c9908abb3b540e8cb6956a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/comp/syntax/ext/qquote.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ fn visit_expr_aq(expr: @ast::expr, &&cx: aq_ctxt, v: vt<aq_ctxt>)
3838
}
3939
}
4040

41+
fn is_space(c: char) -> bool {
42+
syntax::parse::lexer::is_whitespace(c)
43+
}
44+
4145
fn expand_qquote(ecx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
4246
let str = codemap::span_to_snippet(sp, ecx.session().parse_sess.cm);
4347
let qcx = gather_anti_quotes(sp.lo, e);
@@ -48,20 +52,28 @@ fn expand_qquote(ecx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
4852
prev = lo;
4953
}
5054
let str2 = "";
51-
let active = true;
55+
enum state {active, skip(uint), blank};
56+
let state = active;
5257
let i = 0u, j = 0u;
5358
let g_len = vec::len(cx.gather);
5459
str::chars_iter(str) {|ch|
55-
if (active && j < g_len && i == cx.gather[j].lo) {
60+
if (j < g_len && i == cx.gather[j].lo) {
5661
assert ch == '$';
57-
active = false;
58-
str2 += #fmt(" $%u ", j);
62+
let repl = #fmt("$%u ", j);
63+
state = skip(str::char_len(repl));
64+
str2 += repl;
65+
}
66+
alt state {
67+
active {str::push_char(str2, ch);}
68+
skip(1u) {state = blank;}
69+
skip(sk) {state = skip (sk-1u);}
70+
blank if is_space(ch) {str::push_char(str2, ch);}
71+
blank {str::push_char(str2, ' ');}
5972
}
60-
if (active) {str::push_char(str2, ch);}
6173
i += 1u;
62-
if (!active && j < g_len && i == cx.gather[j].hi) {
74+
if (j < g_len && i == cx.gather[j].hi) {
6375
assert ch == ')';
64-
active = true;
76+
state = active;
6577
j += 1u;
6678
}
6779
}

0 commit comments

Comments
 (0)