diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-09-09 17:35:56 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-09-09 17:35:56 -0700 |
| commit | e7a01b7383df092c9b5fc9367541cd9f90a07c40 (patch) | |
| tree | c3b1afef2fd960bff295773084a85317acd772e9 /src/libsyntax/parse/common.rs | |
| parent | e0c232025c2a175069de3dd30b52b0ac2dbc2f65 (diff) | |
| download | rust-e7a01b7383df092c9b5fc9367541cd9f90a07c40.tar.gz rust-e7a01b7383df092c9b5fc9367541cd9f90a07c40.zip | |
Introduce 'strict' keywords, that may not be used as idents anywhere
Diffstat (limited to 'src/libsyntax/parse/common.rs')
| -rw-r--r-- | src/libsyntax/parse/common.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libsyntax/parse/common.rs b/src/libsyntax/parse/common.rs index 478288ba4cd..c2ed8a7d9d6 100644 --- a/src/libsyntax/parse/common.rs +++ b/src/libsyntax/parse/common.rs @@ -84,6 +84,7 @@ impl parser: parser_common { } fn parse_ident() -> ast::ident { + self.check_strict_keywords(); match copy self.token { token::IDENT(i, _) => { self.bump(); return i; } token::INTERPOLATED(token::nt_ident(*)) => { self.bug( @@ -183,6 +184,26 @@ impl parser: parser_common { } } + fn is_strict_keyword(word: ~str) -> bool { + self.strict_keywords.contains_key_ref(&word) + } + + fn check_strict_keywords() { + match self.token { + token::IDENT(_, false) => { + let w = token_to_str(self.reader, self.token); + self.check_strict_keywords_(w); + } + _ => () + } + } + + fn check_strict_keywords_(w: ~str) { + if self.is_strict_keyword(w) { + self.fatal(~"found `" + w + ~"` in ident position"); + } + } + fn expect_gt() { if self.token == token::GT { self.bump(); |
