about summary refs log tree commit diff
path: root/src/libsyntax/parse/token.rs
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-05-18 17:36:30 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-05-23 12:44:05 +0300
commitfcc2f92f454d9ce1e66713e28edb136d6948dd5a (patch)
tree1a5893ca61d737492851dfba7d3831949333071e /src/libsyntax/parse/token.rs
parent85334c50921a1c90707c9d0fb344c63bd373e1b8 (diff)
downloadrust-fcc2f92f454d9ce1e66713e28edb136d6948dd5a.tar.gz
rust-fcc2f92f454d9ce1e66713e28edb136d6948dd5a.zip
syntax: Return named errors from literal parsing functions
Diffstat (limited to 'src/libsyntax/parse/token.rs')
-rw-r--r--src/libsyntax/parse/token.rs25
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 {