Introduce 'strict' keywords, that may not be used as idents anywhere

This commit is contained in:
Brian Anderson
2012-09-09 17:35:56 -07:00
parent e0c232025c
commit e7a01b7383
3 changed files with 42 additions and 4 deletions

View File

@@ -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();