about summary refs log tree commit diff
path: root/src/libsyntax/parse/common.rs
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-09-09 17:35:56 -0700
committerBrian Anderson <banderson@mozilla.com>2012-09-09 17:35:56 -0700
commite7a01b7383df092c9b5fc9367541cd9f90a07c40 (patch)
treec3b1afef2fd960bff295773084a85317acd772e9 /src/libsyntax/parse/common.rs
parente0c232025c2a175069de3dd30b52b0ac2dbc2f65 (diff)
downloadrust-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.rs21
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();