提交 7185ea35 编写于 作者: M Marijn Haverbeke

Use quotes around tokens in parser error messages to make them more readable

Closes #1328
上级 6637340c
...@@ -162,8 +162,8 @@ fn bad_expr_word_table() -> hashmap<str, ()> { ...@@ -162,8 +162,8 @@ fn bad_expr_word_table() -> hashmap<str, ()> {
} }
fn unexpected(p: parser, t: token::token) -> ! { fn unexpected(p: parser, t: token::token) -> ! {
let s: str = "unexpected token: "; let s: str = "unexpected token: '" + token::to_str(p.get_reader(), t) +
s += token::to_str(p.get_reader(), t); "'";
p.fatal(s); p.fatal(s);
} }
...@@ -171,11 +171,11 @@ fn expect(p: parser, t: token::token) { ...@@ -171,11 +171,11 @@ fn expect(p: parser, t: token::token) {
if p.peek() == t { if p.peek() == t {
p.bump(); p.bump();
} else { } else {
let s: str = "expecting "; let s: str = "expecting '";
s += token::to_str(p.get_reader(), t); s += token::to_str(p.get_reader(), t);
s += ", found "; s += "' but found '";
s += token::to_str(p.get_reader(), p.peek()); s += token::to_str(p.get_reader(), p.peek());
p.fatal(s); p.fatal(s + "'");
} }
} }
...@@ -1703,9 +1703,9 @@ fn parse_block_tail(p: parser, lo: uint, s: ast::blk_check_mode) -> ast::blk { ...@@ -1703,9 +1703,9 @@ fn parse_block_tail(p: parser, lo: uint, s: ast::blk_check_mode) -> ast::blk {
token::RBRACE. { expr = some(e); } token::RBRACE. { expr = some(e); }
t { t {
if stmt_ends_with_semi(*stmt) { if stmt_ends_with_semi(*stmt) {
p.fatal("expected ';' or '}' after " + p.fatal("expected ';' or '}' after expression but \
"expression but found " + found '" + token::to_str(p.get_reader(), t) +
token::to_str(p.get_reader(), t)); "'");
} }
stmts += [stmt]; stmts += [stmt];
} }
...@@ -1908,8 +1908,8 @@ fn parse_mod_items(p: parser, term: token::token, ...@@ -1908,8 +1908,8 @@ fn parse_mod_items(p: parser, term: token::token,
alt parse_item(p, attrs) { alt parse_item(p, attrs) {
some(i) { items += [i]; } some(i) { items += [i]; }
_ { _ {
p.fatal("expected item but found " + p.fatal("expected item but found '" +
token::to_str(p.get_reader(), p.peek())); token::to_str(p.get_reader(), p.peek()) + "'");
} }
} }
} }
...@@ -2079,8 +2079,8 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item { ...@@ -2079,8 +2079,8 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
} }
token::RBRACE. {/* empty */ } token::RBRACE. {/* empty */ }
_ { _ {
p.fatal("expected name of variant or '}' but found " + p.fatal("expected name of variant or '}' but found '" +
token::to_str(p.get_reader(), tok)); token::to_str(p.get_reader(), tok) + "'");
} }
} }
} }
......
// error-pattern:expecting ] // error-pattern:expecting ']'
// asterisk is bogus // asterisk is bogus
#[attr*] #[attr*]
......
// error-pattern:expecting [, found fmt // error-pattern:expecting '[' but found 'fmt'
// Don't know how to deal with a syntax extension appearing after an // Don't know how to deal with a syntax extension appearing after an
// item attribute. Probably could use a better error message. // item attribute. Probably could use a better error message.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册