diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-09-11 19:26:48 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-09-11 19:26:48 -0700 |
| commit | 3d2a74a160c5772efccda711e60c173077099ef2 (patch) | |
| tree | 232a101ea013a8ead9633bd9a83c8a6e9c62798a /src/libsyntax/parse | |
| parent | ea01ee2e9e161a7028b98848c071e5fe9c30c7f7 (diff) | |
| download | rust-3d2a74a160c5772efccda711e60c173077099ef2.tar.gz rust-3d2a74a160c5772efccda711e60c173077099ef2.zip | |
Reserve 'be' as a keyword
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/common.rs | 21 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 14 |
3 files changed, 37 insertions, 0 deletions
diff --git a/src/libsyntax/parse/common.rs b/src/libsyntax/parse/common.rs index d71d95fd63f..a498b69527a 100644 --- a/src/libsyntax/parse/common.rs +++ b/src/libsyntax/parse/common.rs @@ -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(); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 676610c66be..ea824ea2fb6 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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, ()>, diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index aac36040cf0..3e5abe557e2 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -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) |
