Skip to content

Commit 7185ea3

Browse files
committed
Use quotes around tokens in parser error messages to make them more readable
Closes #1328
1 parent 6637340 commit 7185ea3

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/comp/syntax/parse/parser.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -162,20 +162,20 @@ fn bad_expr_word_table() -> hashmap<str, ()> {
162162
}
163163

164164
fn unexpected(p: parser, t: token::token) -> ! {
165-
let s: str = "unexpected token: ";
166-
s += token::to_str(p.get_reader(), t);
165+
let s: str = "unexpected token: '" + token::to_str(p.get_reader(), t) +
166+
"'";
167167
p.fatal(s);
168168
}
169169

170170
fn expect(p: parser, t: token::token) {
171171
if p.peek() == t {
172172
p.bump();
173173
} else {
174-
let s: str = "expecting ";
174+
let s: str = "expecting '";
175175
s += token::to_str(p.get_reader(), t);
176-
s += ", found ";
176+
s += "' but found '";
177177
s += token::to_str(p.get_reader(), p.peek());
178-
p.fatal(s);
178+
p.fatal(s + "'");
179179
}
180180
}
181181

@@ -1703,9 +1703,9 @@ fn parse_block_tail(p: parser, lo: uint, s: ast::blk_check_mode) -> ast::blk {
17031703
token::RBRACE. { expr = some(e); }
17041704
t {
17051705
if stmt_ends_with_semi(*stmt) {
1706-
p.fatal("expected ';' or '}' after " +
1707-
"expression but found " +
1708-
token::to_str(p.get_reader(), t));
1706+
p.fatal("expected ';' or '}' after expression but \
1707+
found '" + token::to_str(p.get_reader(), t) +
1708+
"'");
17091709
}
17101710
stmts += [stmt];
17111711
}
@@ -1908,8 +1908,8 @@ fn parse_mod_items(p: parser, term: token::token,
19081908
alt parse_item(p, attrs) {
19091909
some(i) { items += [i]; }
19101910
_ {
1911-
p.fatal("expected item but found " +
1912-
token::to_str(p.get_reader(), p.peek()));
1911+
p.fatal("expected item but found '" +
1912+
token::to_str(p.get_reader(), p.peek()) + "'");
19131913
}
19141914
}
19151915
}
@@ -2079,8 +2079,8 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
20792079
}
20802080
token::RBRACE. {/* empty */ }
20812081
_ {
2082-
p.fatal("expected name of variant or '}' but found " +
2083-
token::to_str(p.get_reader(), tok));
2082+
p.fatal("expected name of variant or '}' but found '" +
2083+
token::to_str(p.get_reader(), tok) + "'");
20842084
}
20852085
}
20862086
}

src/test/compile-fail/attr-bad-meta.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// error-pattern:expecting ]
1+
// error-pattern:expecting ']'
22

33
// asterisk is bogus
44
#[attr*]

src/test/compile-fail/ext-after-attrib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// error-pattern:expecting [, found fmt
1+
// error-pattern:expecting '[' but found 'fmt'
22

33
// Don't know how to deal with a syntax extension appearing after an
44
// item attribute. Probably could use a better error message.

0 commit comments

Comments
 (0)