1
Fork 0

get rid of keyword idents, replace with names

should prevent future bugs
This commit is contained in:
John Clements 2014-07-06 15:19:29 -07:00
parent 06b64345d6
commit c1b8b3c35c
2 changed files with 8 additions and 8 deletions

View file

@ -542,7 +542,7 @@ impl<'a> Parser<'a> {
// true. Otherwise, return false. // true. Otherwise, return false.
pub fn eat_keyword(&mut self, kw: keywords::Keyword) -> bool { pub fn eat_keyword(&mut self, kw: keywords::Keyword) -> bool {
match self.token { match self.token {
token::IDENT(sid, false) if kw.to_ident().name == sid.name => { token::IDENT(sid, false) if kw.to_name() == sid.name => {
self.bump(); self.bump();
true true
} }
@ -555,7 +555,7 @@ impl<'a> Parser<'a> {
// otherwise, eat it. // otherwise, eat it.
pub fn expect_keyword(&mut self, kw: keywords::Keyword) { pub fn expect_keyword(&mut self, kw: keywords::Keyword) {
if !self.eat_keyword(kw) { if !self.eat_keyword(kw) {
let id_interned_str = token::get_ident(kw.to_ident()); let id_interned_str = token::get_name(kw.to_name());
let token_str = self.this_token_to_string(); let token_str = self.this_token_to_string();
self.fatal(format!("expected `{}`, found `{}`", self.fatal(format!("expected `{}`, found `{}`",
id_interned_str, token_str).as_slice()) id_interned_str, token_str).as_slice())

View file

@ -413,7 +413,7 @@ macro_rules! declare_special_idents_and_keywords {(
* the language and may not appear as identifiers. * the language and may not appear as identifiers.
*/ */
pub mod keywords { pub mod keywords {
use ast::Ident; use ast::Name;
pub enum Keyword { pub enum Keyword {
$( $sk_variant, )* $( $sk_variant, )*
@ -421,10 +421,10 @@ macro_rules! declare_special_idents_and_keywords {(
} }
impl Keyword { impl Keyword {
pub fn to_ident(&self) -> Ident { pub fn to_name(&self) -> Name {
match *self { match *self {
$( $sk_variant => Ident { name: $sk_name, ctxt: 0 }, )* $( $sk_variant => $sk_name, )*
$( $rk_variant => Ident { name: $rk_name, ctxt: 0 }, )* $( $rk_variant => $rk_name, )*
} }
} }
} }
@ -432,7 +432,7 @@ macro_rules! declare_special_idents_and_keywords {(
fn mk_fresh_ident_interner() -> IdentInterner { fn mk_fresh_ident_interner() -> IdentInterner {
// The indices here must correspond to the numbers in // The indices here must correspond to the numbers in
// special_idents, in Keyword to_ident(), and in static // special_idents, in Keyword to_name(), and in static
// constants below. // constants below.
let mut init_vec = Vec::new(); let mut init_vec = Vec::new();
$(init_vec.push($si_str);)* $(init_vec.push($si_str);)*
@ -710,7 +710,7 @@ pub fn fresh_mark() -> Mrk {
pub fn is_keyword(kw: keywords::Keyword, tok: &Token) -> bool { pub fn is_keyword(kw: keywords::Keyword, tok: &Token) -> bool {
match *tok { match *tok {
token::IDENT(sid, false) => { kw.to_ident().name == sid.name } token::IDENT(sid, false) => { kw.to_name() == sid.name }
_ => { false } _ => { false }
} }
} }