Skip to content

Commit

Permalink
Bug fix to accept $ in 0th pos, (ie #ast{$(x) + ...}).
Browse files Browse the repository at this point in the history
Note: part from Niko Matsakis commit: rewrite assert to accept a $ in
0th pos.
  • Loading branch information
kevina committed Feb 11, 2012
1 parent f9a63ef commit 48eda22
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/comp/syntax/ext/qquote.rs
Expand Up @@ -184,11 +184,12 @@ fn finish<T: qq_helper>
let sp = node.span();
let qcx = gather_anti_quotes(sp.lo, node);
let cx = qcx;
let prev = 0u;
for {lo: lo, _} in cx.gather {
assert lo > prev;
prev = lo;

// assert that the vector is sorted by position:
uint::range(1u, vec::len(cx.gather)) {|i|
assert cx.gather[i-1u].lo < cx.gather[i].lo;
}

let str2 = "";
enum state {active, skip(uint), blank};
let state = active;
Expand Down
7 changes: 7 additions & 0 deletions src/test/run-pass/qquote.rs
Expand Up @@ -81,6 +81,13 @@ fn main() {
let x = #ast{1};
let test1 = #ast{1+$(x)};
check_pp(test1, pprust::print_expr, "1 + 1");

let test2 = #ast{$(x)+1};
check_pp(test2, pprust::print_expr, "1 + 1");

let y = #ast{2};
let test3 = #ast{$(x) + $(y)};
check_pp(test3, pprust::print_expr, "1 + 2");
}

fn check_pp<T>(expr: T, f: fn(pprust::ps, T), expect: str) {
Expand Down

0 comments on commit 48eda22

Please sign in to comment.