libsyntax: Remove the restricted keyword concept
This commit is contained in:
parent
76f8cfb26c
commit
0c82c00dc4
3 changed files with 4 additions and 58 deletions
|
@ -37,9 +37,6 @@ trait parser_common {
|
||||||
fn is_any_keyword(tok: token::token) -> bool;
|
fn is_any_keyword(tok: token::token) -> bool;
|
||||||
fn eat_keyword(word: ~str) -> bool;
|
fn eat_keyword(word: ~str) -> bool;
|
||||||
fn expect_keyword(word: ~str);
|
fn expect_keyword(word: ~str);
|
||||||
fn is_restricted_keyword(word: ~str) -> bool;
|
|
||||||
fn check_restricted_keywords();
|
|
||||||
fn check_restricted_keywords_(w: ~str);
|
|
||||||
fn expect_gt();
|
fn expect_gt();
|
||||||
fn parse_seq_to_before_gt<T: Copy>(sep: Option<token::token>,
|
fn parse_seq_to_before_gt<T: Copy>(sep: Option<token::token>,
|
||||||
f: fn(parser) -> T) -> ~[T];
|
f: fn(parser) -> T) -> ~[T];
|
||||||
|
@ -104,7 +101,6 @@ impl parser: parser_common {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_value_ident() -> ast::ident {
|
fn parse_value_ident() -> ast::ident {
|
||||||
self.check_restricted_keywords();
|
|
||||||
return self.parse_ident();
|
return self.parse_ident();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,26 +161,6 @@ impl parser: parser_common {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_restricted_keyword(word: ~str) -> bool {
|
|
||||||
self.restricted_keywords.contains_key_ref(&word)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_restricted_keywords() {
|
|
||||||
match self.token {
|
|
||||||
token::IDENT(_, false) => {
|
|
||||||
let w = token_to_str(self.reader, self.token);
|
|
||||||
self.check_restricted_keywords_(w);
|
|
||||||
}
|
|
||||||
_ => ()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_restricted_keywords_(w: ~str) {
|
|
||||||
if self.is_restricted_keyword(w) {
|
|
||||||
self.fatal(~"found `" + w + ~"` in restricted position");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_strict_keyword(word: ~str) -> bool {
|
fn is_strict_keyword(word: ~str) -> bool {
|
||||||
self.strict_keywords.contains_key_ref(&word)
|
self.strict_keywords.contains_key_ref(&word)
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,7 +217,6 @@ fn parser(sess: parse_sess, cfg: ast::crate_cfg,
|
||||||
restriction: UNRESTRICTED,
|
restriction: UNRESTRICTED,
|
||||||
quote_depth: 0u,
|
quote_depth: 0u,
|
||||||
keywords: token::keyword_table(),
|
keywords: token::keyword_table(),
|
||||||
restricted_keywords: token::restricted_keyword_table(),
|
|
||||||
strict_keywords: token::strict_keyword_table(),
|
strict_keywords: token::strict_keyword_table(),
|
||||||
reserved_keywords: token::reserved_keyword_table(),
|
reserved_keywords: token::reserved_keyword_table(),
|
||||||
obsolete_set: std::map::HashMap(),
|
obsolete_set: std::map::HashMap(),
|
||||||
|
@ -239,7 +238,6 @@ struct parser {
|
||||||
reader: reader,
|
reader: reader,
|
||||||
interner: interner<@~str>,
|
interner: interner<@~str>,
|
||||||
keywords: HashMap<~str, ()>,
|
keywords: HashMap<~str, ()>,
|
||||||
restricted_keywords: HashMap<~str, ()>,
|
|
||||||
strict_keywords: HashMap<~str, ()>,
|
strict_keywords: HashMap<~str, ()>,
|
||||||
reserved_keywords: HashMap<~str, ()>,
|
reserved_keywords: HashMap<~str, ()>,
|
||||||
/// The set of seen errors about obsolete syntax. Used to suppress
|
/// The set of seen errors about obsolete syntax. Used to suppress
|
||||||
|
@ -3200,7 +3198,6 @@ impl parser {
|
||||||
let ty_params = self.parse_ty_params();
|
let ty_params = self.parse_ty_params();
|
||||||
// Newtype syntax
|
// Newtype syntax
|
||||||
if self.token == token::EQ {
|
if self.token == token::EQ {
|
||||||
self.check_restricted_keywords_(*self.id_to_str(id));
|
|
||||||
self.bump();
|
self.bump();
|
||||||
let ty = self.parse_ty(false);
|
let ty = self.parse_ty(false);
|
||||||
self.expect(token::SEMI);
|
self.expect(token::SEMI);
|
||||||
|
|
|
@ -362,20 +362,17 @@ fn mk_fake_ident_interner() -> ident_interner {
|
||||||
/**
|
/**
|
||||||
* All the valid words that have meaning in the Rust language.
|
* All the valid words that have meaning in the Rust language.
|
||||||
*
|
*
|
||||||
* Rust keywords are either 'temporary', 'restricted', or 'strict'. Temporary
|
* Rust keywords are either 'temporary', 'strict' or 'reserved'. Temporary
|
||||||
* keywords are contextual and may be used as identifiers anywhere. They are
|
* keywords are contextual and may be used as identifiers anywhere. They are
|
||||||
* expected to disappear from the grammar soon. Restricted keywords may not
|
* expected to disappear from the grammar soon. Strict keywords may not
|
||||||
* appear in positions that might otherwise contain _value identifiers_.
|
* appear as identifiers at all. Reserved keywords are not used anywhere in
|
||||||
* Strict keywords may not appear as identifiers at all.
|
* the language and may not appear as identifiers.
|
||||||
*/
|
*/
|
||||||
fn keyword_table() -> HashMap<~str, ()> {
|
fn keyword_table() -> HashMap<~str, ()> {
|
||||||
let keywords = str_hash();
|
let keywords = str_hash();
|
||||||
for temporary_keyword_table().each_key |word| {
|
for temporary_keyword_table().each_key |word| {
|
||||||
keywords.insert(word, ());
|
keywords.insert(word, ());
|
||||||
}
|
}
|
||||||
for restricted_keyword_table().each_key |word| {
|
|
||||||
keywords.insert(word, ());
|
|
||||||
}
|
|
||||||
for strict_keyword_table().each_key |word| {
|
for strict_keyword_table().each_key |word| {
|
||||||
keywords.insert(word, ());
|
keywords.insert(word, ());
|
||||||
}
|
}
|
||||||
|
@ -397,30 +394,6 @@ fn temporary_keyword_table() -> HashMap<~str, ()> {
|
||||||
words
|
words
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Keywords that may not appear in any position that might otherwise contain a
|
|
||||||
* _value identifier_. Restricted keywords may still be used as other types of
|
|
||||||
* identifiers.
|
|
||||||
*
|
|
||||||
* Reasons:
|
|
||||||
*
|
|
||||||
* * For some (most?), if used at the start of a line, they will cause the
|
|
||||||
* line to be interpreted as a specific kind of statement, which would be
|
|
||||||
* confusing.
|
|
||||||
*
|
|
||||||
* * `true` or `false` as identifiers would always be shadowed by
|
|
||||||
* the boolean constants
|
|
||||||
*/
|
|
||||||
fn restricted_keyword_table() -> HashMap<~str, ()> {
|
|
||||||
let words = str_hash();
|
|
||||||
let keys = ~[
|
|
||||||
];
|
|
||||||
for keys.each |word| {
|
|
||||||
words.insert(word, ());
|
|
||||||
}
|
|
||||||
words
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Full keywords. May not appear anywhere else.
|
/// Full keywords. May not appear anywhere else.
|
||||||
fn strict_keyword_table() -> HashMap<~str, ()> {
|
fn strict_keyword_table() -> HashMap<~str, ()> {
|
||||||
let words = str_hash();
|
let words = str_hash();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue