Reserve 'be' as a keyword

This commit is contained in:
Brian Anderson 2012-09-11 19:26:48 -07:00
parent ea01ee2e9e
commit 3d2a74a160
4 changed files with 41 additions and 0 deletions

View File

@ -85,6 +85,7 @@ impl parser: parser_common {
fn parse_ident() -> ast::ident {
self.check_strict_keywords();
self.check_reserved_keywords();
match copy self.token {
token::IDENT(i, _) => { self.bump(); return i; }
token::INTERPOLATED(token::nt_ident(*)) => { self.bug(
@ -204,6 +205,26 @@ impl parser: parser_common {
}
}
fn is_reserved_keyword(word: ~str) -> bool {
self.reserved_keywords.contains_key_ref(&word)
}
fn check_reserved_keywords() {
match self.token {
token::IDENT(_, false) => {
let w = token_to_str(self.reader, self.token);
self.check_reserved_keywords_(w);
}
_ => ()
}
}
fn check_reserved_keywords_(w: ~str) {
if self.is_reserved_keyword(w) {
self.fatal(~"`" + w + ~"` is a reserved keyword");
}
}
fn expect_gt() {
if self.token == token::GT {
self.bump();

View File

@ -216,6 +216,7 @@ fn parser(sess: parse_sess, cfg: ast::crate_cfg,
keywords: token::keyword_table(),
restricted_keywords: token::restricted_keyword_table(),
strict_keywords: token::strict_keyword_table(),
reserved_keywords: token::reserved_keyword_table(),
obsolete_set: std::map::HashMap(),
}
}
@ -237,6 +238,7 @@ struct parser {
keywords: HashMap<~str, ()>,
restricted_keywords: HashMap<~str, ()>,
strict_keywords: HashMap<~str, ()>,
reserved_keywords: HashMap<~str, ()>,
/// The set of seen errors about obsolete syntax. Used to suppress
/// extra detail when the same error is seen twice
obsolete_set: HashMap<ObsoleteSyntax, ()>,

View File

@ -379,6 +379,9 @@ fn keyword_table() -> HashMap<~str, ()> {
for strict_keyword_table().each_key |word| {
keywords.insert(word, ());
}
for reserved_keyword_table().each_key |word| {
keywords.insert(word, ());
}
keywords
}
@ -447,6 +450,17 @@ fn strict_keyword_table() -> HashMap<~str, ()> {
words
}
fn reserved_keyword_table() -> HashMap<~str, ()> {
let words = str_hash();
let keys = ~[
~"be"
];
for keys.each |word| {
words.insert(word, ());
}
words
}
impl binop : cmp::Eq {
pure fn eq(&&other: binop) -> bool {
(self as uint) == (other as uint)

View File

@ -0,0 +1,4 @@
fn main() {
let be = 0;
//~^ ERROR `be` is a reserved keyword
}