summary refs log tree commit diff
path: root/src/libsyntax/parse/token.rs
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2016-04-16 04:10:59 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2016-04-24 20:59:44 +0300
commit8dbf8f5f0a26a8f80f895294532ad567c156beb3 (patch)
tree5b0fcc8d207f3a59dbdca97c5d71f2fd2db511e0 /src/libsyntax/parse/token.rs
parent8d0dd7876e733555b0284e9b6cbf0f33ed792b67 (diff)
downloadrust-8dbf8f5f0a26a8f80f895294532ad567c156beb3.tar.gz
rust-8dbf8f5f0a26a8f80f895294532ad567c156beb3.zip
syntax: Don't rely on token::IdentStyle in the parser
Diffstat (limited to 'src/libsyntax/parse/token.rs')
-rw-r--r--src/libsyntax/parse/token.rs88
1 files changed, 26 insertions, 62 deletions
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index 16417ac0044..46cf79ba336 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -26,7 +26,6 @@ use std::fmt;
 use std::ops::Deref;
 use std::rc::Rc;
 
-#[allow(non_camel_case_types)]
 #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)]
 pub enum BinOpToken {
     Plus,
@@ -99,7 +98,6 @@ impl Lit {
     }
 }
 
-#[allow(non_camel_case_types)]
 #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug)]
 pub enum Token {
     /* Expression-operator symbols. */
@@ -185,7 +183,7 @@ impl Token {
     pub fn can_begin_expr(&self) -> bool {
         match *self {
             OpenDelim(_)                => true,
-            Ident(_, _)                 => true,
+            Ident(..)                   => true,
             Underscore                  => true,
             Tilde                       => true,
             Literal(_, _)               => true,
@@ -218,7 +216,7 @@ impl Token {
     /// Returns `true` if the token is an identifier.
     pub fn is_ident(&self) -> bool {
         match *self {
-            Ident(_, _) => true,
+            Ident(..)   => true,
             _           => false,
         }
     }
@@ -239,16 +237,6 @@ impl Token {
         }
     }
 
-    /// Returns `true` if the token is a path that is not followed by a `::`
-    /// token.
-    #[allow(non_upper_case_globals)]
-    pub fn is_plain_ident(&self) -> bool {
-        match *self {
-            Ident(_, Plain) => true,
-            _               => false,
-        }
-    }
-
     /// Returns `true` if the token is a lifetime.
     pub fn is_lifetime(&self) -> bool {
         match *self {
@@ -289,77 +277,53 @@ impl Token {
     }
 
     /// Returns `true` if the token is a given keyword, `kw`.
-    #[allow(non_upper_case_globals)]
     pub fn is_keyword(&self, kw: keywords::Keyword) -> bool {
         match *self {
-            Ident(sid, Plain) => kw.to_name() == sid.name,
-            _                      => false,
+            Ident(id, _) => id.name == kw.to_name(),
+            _ => false,
         }
     }
 
-    pub fn is_keyword_allow_following_colon(&self, kw: keywords::Keyword) -> bool {
+    pub fn is_path_segment_keyword(&self) -> bool {
         match *self {
-            Ident(sid, _) => { kw.to_name() == sid.name }
-            _ => { false }
+            Ident(id, _) => id.name == SUPER_KEYWORD_NAME ||
+                            id.name == SELF_KEYWORD_NAME ||
+                            id.name == SELF_TYPE_KEYWORD_NAME,
+            _ => false,
         }
     }
 
-    /// Returns `true` if the token is either a special identifier, or a strict
-    /// or reserved keyword.
-    #[allow(non_upper_case_globals)]
+    /// Returns `true` if the token is either a strict or reserved keyword.
     pub fn is_any_keyword(&self) -> bool {
         match *self {
-            Ident(sid, Plain) => {
-                let n = sid.name;
-
-                   n == SELF_KEYWORD_NAME
-                || n == STATIC_KEYWORD_NAME
-                || n == SUPER_KEYWORD_NAME
-                || n == SELF_TYPE_KEYWORD_NAME
-                || STRICT_KEYWORD_START <= n
-                && n <= RESERVED_KEYWORD_FINAL
-            },
+            Ident(id, _) => id.name == SELF_KEYWORD_NAME ||
+                            id.name == STATIC_KEYWORD_NAME ||
+                            id.name == SUPER_KEYWORD_NAME ||
+                            id.name == SELF_TYPE_KEYWORD_NAME ||
+                            id.name >= STRICT_KEYWORD_START &&
+                            id.name <= RESERVED_KEYWORD_FINAL,
             _ => false
         }
     }
 
-    /// Returns `true` if the token may not appear as an identifier.
-    #[allow(non_upper_case_globals)]
+    /// Returns `true` if the token is either a strict keyword.
     pub fn is_strict_keyword(&self) -> bool {
         match *self {
-            Ident(sid, Plain) => {
-                let n = sid.name;
-
-                   n == SELF_KEYWORD_NAME
-                || n == STATIC_KEYWORD_NAME
-                || n == SUPER_KEYWORD_NAME
-                || n == SELF_TYPE_KEYWORD_NAME
-                || STRICT_KEYWORD_START <= n
-                && n <= STRICT_KEYWORD_FINAL
-            },
-            Ident(sid, ModName) => {
-                let n = sid.name;
-
-                   n != SELF_KEYWORD_NAME
-                && n != SUPER_KEYWORD_NAME
-                && STRICT_KEYWORD_START <= n
-                && n <= STRICT_KEYWORD_FINAL
-            }
+            Ident(id, _) => id.name == SELF_KEYWORD_NAME ||
+                            id.name == STATIC_KEYWORD_NAME ||
+                            id.name == SUPER_KEYWORD_NAME ||
+                            id.name == SELF_TYPE_KEYWORD_NAME ||
+                            id.name >= STRICT_KEYWORD_START &&
+                            id.name <= STRICT_KEYWORD_FINAL,
             _ => false,
         }
     }
 
-    /// Returns `true` if the token is a keyword that has been reserved for
-    /// possible future use.
-    #[allow(non_upper_case_globals)]
+    /// Returns `true` if the token is either a keyword reserved for possible future use.
     pub fn is_reserved_keyword(&self) -> bool {
         match *self {
-            Ident(sid, Plain) => {
-                let n = sid.name;
-
-                   RESERVED_KEYWORD_START <= n
-                && n <= RESERVED_KEYWORD_FINAL
-            },
+            Ident(id, _) => id.name >= RESERVED_KEYWORD_START &&
+                            id.name <= RESERVED_KEYWORD_FINAL,
             _ => false,
         }
     }