Skip to content

Commit

Permalink
Use quotes around tokens in parser error messages to make them more r…
Browse files Browse the repository at this point in the history
…eadable

Closes #1328
  • Loading branch information
marijnh committed Dec 19, 2011
1 parent 6637340 commit 7185ea3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions src/comp/syntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,20 @@ fn bad_expr_word_table() -> hashmap<str, ()> {
}

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

fn expect(p: parser, t: token::token) {
if p.peek() == t {
p.bump();
} else {
let s: str = "expecting ";
let s: str = "expecting '";
s += token::to_str(p.get_reader(), t);
s += ", found ";
s += "' but found '";
s += token::to_str(p.get_reader(), p.peek());
p.fatal(s);
p.fatal(s + "'");
}
}

Expand Down Expand Up @@ -1703,9 +1703,9 @@ fn parse_block_tail(p: parser, lo: uint, s: ast::blk_check_mode) -> ast::blk {
token::RBRACE. { expr = some(e); }
t {
if stmt_ends_with_semi(*stmt) {
p.fatal("expected ';' or '}' after " +
"expression but found " +
token::to_str(p.get_reader(), t));
p.fatal("expected ';' or '}' after expression but \
found '" + token::to_str(p.get_reader(), t) +
"'");
}
stmts += [stmt];
}
Expand Down Expand Up @@ -1908,8 +1908,8 @@ fn parse_mod_items(p: parser, term: token::token,
alt parse_item(p, attrs) {
some(i) { items += [i]; }
_ {
p.fatal("expected item but found " +
token::to_str(p.get_reader(), p.peek()));
p.fatal("expected item but found '" +
token::to_str(p.get_reader(), p.peek()) + "'");
}
}
}
Expand Down Expand Up @@ -2079,8 +2079,8 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
}
token::RBRACE. {/* empty */ }
_ {
p.fatal("expected name of variant or '}' but found " +
token::to_str(p.get_reader(), tok));
p.fatal("expected name of variant or '}' but found '" +
token::to_str(p.get_reader(), tok) + "'");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/attr-bad-meta.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// error-pattern:expecting ]
// error-pattern:expecting ']'

// asterisk is bogus
#[attr*]
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/ext-after-attrib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// error-pattern:expecting [, found fmt
// error-pattern:expecting '[' but found 'fmt'

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

0 comments on commit 7185ea3

Please sign in to comment.