Skip to content

Commit d12e73b

Browse files
committed
---
yaml --- r: 30483 b: refs/heads/incoming c: 3d2a74a h: refs/heads/master i: 30481: 7112661 30479: 8ede134 v: v3
1 parent f10d8f3 commit d12e73b

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: ea01ee2e9e161a7028b98848c071e5fe9c30c7f7
9+
refs/heads/incoming: 3d2a74a160c5772efccda711e60c173077099ef2
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libsyntax/parse/common.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ impl parser: parser_common {
8585

8686
fn parse_ident() -> ast::ident {
8787
self.check_strict_keywords();
88+
self.check_reserved_keywords();
8889
match copy self.token {
8990
token::IDENT(i, _) => { self.bump(); return i; }
9091
token::INTERPOLATED(token::nt_ident(*)) => { self.bug(
@@ -204,6 +205,26 @@ impl parser: parser_common {
204205
}
205206
}
206207

208+
fn is_reserved_keyword(word: ~str) -> bool {
209+
self.reserved_keywords.contains_key_ref(&word)
210+
}
211+
212+
fn check_reserved_keywords() {
213+
match self.token {
214+
token::IDENT(_, false) => {
215+
let w = token_to_str(self.reader, self.token);
216+
self.check_reserved_keywords_(w);
217+
}
218+
_ => ()
219+
}
220+
}
221+
222+
fn check_reserved_keywords_(w: ~str) {
223+
if self.is_reserved_keyword(w) {
224+
self.fatal(~"`" + w + ~"` is a reserved keyword");
225+
}
226+
}
227+
207228
fn expect_gt() {
208229
if self.token == token::GT {
209230
self.bump();

branches/incoming/src/libsyntax/parse/parser.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ fn parser(sess: parse_sess, cfg: ast::crate_cfg,
216216
keywords: token::keyword_table(),
217217
restricted_keywords: token::restricted_keyword_table(),
218218
strict_keywords: token::strict_keyword_table(),
219+
reserved_keywords: token::reserved_keyword_table(),
219220
obsolete_set: std::map::HashMap(),
220221
}
221222
}
@@ -237,6 +238,7 @@ struct parser {
237238
keywords: HashMap<~str, ()>,
238239
restricted_keywords: HashMap<~str, ()>,
239240
strict_keywords: HashMap<~str, ()>,
241+
reserved_keywords: HashMap<~str, ()>,
240242
/// The set of seen errors about obsolete syntax. Used to suppress
241243
/// extra detail when the same error is seen twice
242244
obsolete_set: HashMap<ObsoleteSyntax, ()>,

branches/incoming/src/libsyntax/parse/token.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ fn keyword_table() -> HashMap<~str, ()> {
379379
for strict_keyword_table().each_key |word| {
380380
keywords.insert(word, ());
381381
}
382+
for reserved_keyword_table().each_key |word| {
383+
keywords.insert(word, ());
384+
}
382385
keywords
383386
}
384387

@@ -447,6 +450,17 @@ fn strict_keyword_table() -> HashMap<~str, ()> {
447450
words
448451
}
449452
453+
fn reserved_keyword_table() -> HashMap<~str, ()> {
454+
let words = str_hash();
455+
let keys = ~[
456+
~"be"
457+
];
458+
for keys.each |word| {
459+
words.insert(word, ());
460+
}
461+
words
462+
}
463+
450464
impl binop : cmp::Eq {
451465
pure fn eq(&&other: binop) -> bool {
452466
(self as uint) == (other as uint)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let be = 0;
3+
//~^ ERROR `be` is a reserved keyword
4+
}

0 commit comments

Comments
 (0)