Skip to content

Commit 7b12924

Browse files
committed
Fix pretty-printing of istr literals. Issue #855
1 parent c274d16 commit 7b12924

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/comp/syntax/parse/parser.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,10 +886,11 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr {
886886
p.bump();
887887
alt p.peek() {
888888
token::LIT_STR(s) {
889+
let sp = p.get_span();
889890
p.bump();
890891
let lit =
891892
@{node: ast::lit_str(p.get_str(s), ast::sk_unique),
892-
span: p.get_span()};
893+
span: sp};
893894
ex = ast::expr_lit(lit);
894895
}
895896
_ { ex = ast::expr_uniq(parse_expr(p)); }

src/comp/syntax/print/pprust.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,17 @@ fn print_literal(s: &ps, lit: &@ast::lit) {
14681468
maybe_print_comment(s, lit.span.lo);
14691469
alt next_lit(s) {
14701470
some(lt) {
1471-
if lt.pos == lit.span.lo { word(s.s, lt.lit); s.cur_lit += 1u; ret; }
1471+
if lt.pos == lit.span.lo {
1472+
// FIXME: This is a hack until istrs replace strings, since
1473+
// istrs are prefixed with a token that is not part of the literal
1474+
alt lit.node {
1475+
ast::lit_str(_, ast::sk_unique.) { word(s.s, "~"); }
1476+
_ { }
1477+
}
1478+
word(s.s, lt.lit);
1479+
s.cur_lit += 1u;
1480+
ret;
1481+
}
14721482
}
14731483
_ { }
14741484
}

0 commit comments

Comments
 (0)