diff options
Diffstat (limited to 'src/libsyntax/parse/token.rs')
| -rw-r--r-- | src/libsyntax/parse/token.rs | 66 |
1 files changed, 21 insertions, 45 deletions
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index b4300feced4..7ea047d332b 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -80,7 +80,7 @@ pub enum Lit { } impl Lit { - pub fn short_name(&self) -> &'static str { + crate fn short_name(&self) -> &'static str { match *self { Byte(_) => "byte", Char(_) => "char", @@ -217,15 +217,7 @@ impl Token { Ident(ident, ident.is_raw_guess()) } - /// Returns `true` if the token starts with '>'. - pub fn is_like_gt(&self) -> bool { - match *self { - BinOp(Shr) | BinOpEq(Shr) | Gt | Ge => true, - _ => false, - } - } - - pub fn is_like_plus(&self) -> bool { + crate fn is_like_plus(&self) -> bool { match *self { BinOp(Plus) | BinOpEq(Plus) => true, _ => false, @@ -233,7 +225,7 @@ impl Token { } /// Returns `true` if the token can appear at the start of an expression. - pub fn can_begin_expr(&self) -> bool { + crate fn can_begin_expr(&self) -> bool { match *self { Ident(ident, is_raw) => ident_can_begin_expr(ident, is_raw), // value name or keyword @@ -265,7 +257,7 @@ impl Token { } /// Returns `true` if the token can appear at the start of a type. - pub fn can_begin_type(&self) -> bool { + crate fn can_begin_type(&self) -> bool { match *self { Ident(ident, is_raw) => ident_can_begin_type(ident, is_raw), // type name or keyword @@ -288,13 +280,13 @@ impl Token { } /// Returns `true` if the token can appear at the start of a generic bound. - pub fn can_begin_bound(&self) -> bool { + crate fn can_begin_bound(&self) -> bool { self.is_path_start() || self.is_lifetime() || self.is_keyword(keywords::For) || self == &Question || self == &OpenDelim(Paren) } /// Returns `true` if the token is any literal - pub fn is_lit(&self) -> bool { + crate fn is_lit(&self) -> bool { match *self { Literal(..) => true, _ => false, @@ -303,7 +295,7 @@ impl Token { /// Returns `true` if the token is any literal, a minus (which can follow a literal, /// for example a '-42', or one of the boolean idents). - pub fn can_begin_literal_or_bool(&self) -> bool { + crate fn can_begin_literal_or_bool(&self) -> bool { match *self { Literal(..) => true, BinOp(Minus) => true, @@ -340,37 +332,21 @@ impl Token { self.ident().is_some() } /// Returns `true` if the token is a lifetime. - pub fn is_lifetime(&self) -> bool { + crate fn is_lifetime(&self) -> bool { self.lifetime().is_some() } /// Returns `true` if the token is a identifier whose name is the given /// string slice. - pub fn is_ident_named(&self, name: &str) -> bool { + crate fn is_ident_named(&self, name: &str) -> bool { match self.ident() { Some((ident, _)) => ident.as_str() == name, None => false } } - /// Returns `true` if the token is a documentation comment. - pub fn is_doc_comment(&self) -> bool { - match *self { - DocComment(..) => true, - _ => false, - } - } - - /// Returns `true` if the token is interpolated. - pub fn is_interpolated(&self) -> bool { - match *self { - Interpolated(..) => true, - _ => false, - } - } - /// Returns `true` if the token is an interpolated path. - pub fn is_path(&self) -> bool { + fn is_path(&self) -> bool { if let Interpolated(ref nt) = *self { if let NtPath(..) = nt.0 { return true; @@ -380,16 +356,16 @@ impl Token { } /// Returns `true` if the token is either the `mut` or `const` keyword. - pub fn is_mutability(&self) -> bool { + crate fn is_mutability(&self) -> bool { self.is_keyword(keywords::Mut) || self.is_keyword(keywords::Const) } - pub fn is_qpath_start(&self) -> bool { + crate fn is_qpath_start(&self) -> bool { self == &Lt || self == &BinOp(Shl) } - pub fn is_path_start(&self) -> bool { + crate fn is_path_start(&self) -> bool { self == &ModSep || self.is_qpath_start() || self.is_path() || self.is_path_segment_keyword() || self.is_ident() && !self.is_reserved_ident() } @@ -416,7 +392,7 @@ impl Token { } /// Returns `true` if the token is a keyword used in the language. - pub fn is_used_keyword(&self) -> bool { + crate fn is_used_keyword(&self) -> bool { match self.ident() { Some((id, false)) => id.is_used_keyword(), _ => false, @@ -424,7 +400,7 @@ impl Token { } /// Returns `true` if the token is a keyword reserved for possible future use. - pub fn is_unused_keyword(&self) -> bool { + crate fn is_unused_keyword(&self) -> bool { match self.ident() { Some((id, false)) => id.is_unused_keyword(), _ => false, @@ -439,7 +415,7 @@ impl Token { } } - pub fn glue(self, joint: Token) -> Option<Token> { + crate fn glue(self, joint: Token) -> Option<Token> { Some(match self { Eq => match joint { Eq => EqEq, @@ -507,7 +483,7 @@ impl Token { /// Returns tokens that are likely to be typed accidentally instead of the current token. /// Enables better error recovery when the wrong token is found. - pub fn similar_tokens(&self) -> Option<Vec<Token>> { + crate fn similar_tokens(&self) -> Option<Vec<Token>> { match *self { Comma => Some(vec![Dot, Lt]), Semi => Some(vec![Colon]), @@ -603,7 +579,7 @@ impl Token { // See comments in `interpolated_to_tokenstream` for why we care about // *probably* equal here rather than actual equality - pub fn probably_equal_for_proc_macro(&self, other: &Token) -> bool { + crate fn probably_equal_for_proc_macro(&self, other: &Token) -> bool { if mem::discriminant(self) != mem::discriminant(other) { return false } @@ -732,7 +708,7 @@ impl fmt::Debug for Nonterminal { } } -pub fn is_op(tok: &Token) -> bool { +crate fn is_op(tok: &Token) -> bool { match *tok { OpenDelim(..) | CloseDelim(..) | Literal(..) | DocComment(..) | Ident(..) | Lifetime(..) | Interpolated(..) | @@ -758,11 +734,11 @@ impl fmt::Debug for LazyTokenStream { } impl LazyTokenStream { - pub fn new() -> Self { + fn new() -> Self { LazyTokenStream(Lock::new(None)) } - pub fn force<F: FnOnce() -> TokenStream>(&self, f: F) -> TokenStream { + fn force<F: FnOnce() -> TokenStream>(&self, f: F) -> TokenStream { let mut opt_stream = self.0.lock(); if opt_stream.is_none() { *opt_stream = Some(f()); |
