diff options
Diffstat (limited to 'src/libsyntax/parse/token.rs')
| -rw-r--r-- | src/libsyntax/parse/token.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 663eace6b62..f089fc024fe 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -77,7 +77,21 @@ pub enum Lit { static_assert_size!(Lit, 8); impl Lit { - crate fn literal_name(&self) -> &'static str { + crate fn symbol(&self) -> Symbol { + match *self { + Bool(s) | Byte(s) | Char(s) | Integer(s) | Float(s) | Err(s) | + Str_(s) | StrRaw(s, _) | ByteStr(s) | ByteStrRaw(s, _) => s + } + } + + crate fn article(&self) -> &'static str { + match *self { + Integer(_) | Err(_) => "an", + _ => "a", + } + } + + crate fn descr(&self) -> &'static str { match *self { Bool(_) => panic!("literal token contains `Lit::Bool`"), Byte(_) => "byte literal", @@ -92,7 +106,7 @@ impl Lit { crate fn may_have_suffix(&self) -> bool { match *self { - Integer(..) | Float(..) => true, + Integer(..) | Float(..) | Err(..) => true, _ => false, } } @@ -318,6 +332,13 @@ impl Token { } } + crate fn expect_lit(&self) -> (Lit, Option<Symbol>) { + match *self { + Literal(lit, suf) => (lit, suf), + _=> panic!("`expect_lit` called on non-literal"), + } + } + /// Returns `true` if the token is any literal, a minus (which can prefix a literal, /// for example a '-42', or one of the boolean idents). crate fn can_begin_literal_or_bool(&self) -> bool { |
