From f9a63efb8214a36b13545b158bf27c1b6540b650 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Wed, 8 Feb 2012 17:45:02 -0700 Subject: [PATCH] Correctly handle the character position at the EOF. Fixes issue #1785. --- src/comp/syntax/parse/lexer.rs | 8 +++++++- src/test/run-pass/qquote.rs | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/comp/syntax/parse/lexer.rs b/src/comp/syntax/parse/lexer.rs index 42cc5400b0c3a..2902ad513a19f 100644 --- a/src/comp/syntax/parse/lexer.rs +++ b/src/comp/syntax/parse/lexer.rs @@ -43,7 +43,13 @@ impl reader for reader { let next = str::char_range_at(*self.src, self.pos); self.pos = next.next; self.curr = next.ch; - } else { self.curr = -1 as char; } + } else { + if (self.curr != -1 as char) { + self.col += 1u; + self.chpos += 1u; + self.curr = -1 as char; + } + } } fn fatal(m: str) -> ! { self.span_diagnostic.span_fatal( diff --git a/src/test/run-pass/qquote.rs b/src/test/run-pass/qquote.rs index 50751a6608165..ef10f03129b21 100644 --- a/src/test/run-pass/qquote.rs +++ b/src/test/run-pass/qquote.rs @@ -76,6 +76,11 @@ fn main() { let pat = #ast(pat){some(_)}; check_pp(pat, pprust::print_pat, "some(_)"); + + // issue #1785 + let x = #ast{1}; + let test1 = #ast{1+$(x)}; + check_pp(test1, pprust::print_expr, "1 + 1"); } fn check_pp(expr: T, f: fn(pprust::ps, T), expect: str) {