about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2018-05-14 00:01:56 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2018-05-15 23:54:08 +0300
commitc1061254317ac747d2bf5901329545f4cec5ebcb (patch)
tree4abe39c1bf4c5db072c168ce019c195763e0920b /src/libsyntax
parent5b820a694c0fd8392092c3f0301537aafe92cce2 (diff)
downloadrust-c1061254317ac747d2bf5901329545f4cec5ebcb.tar.gz
rust-c1061254317ac747d2bf5901329545f4cec5ebcb.zip
Represent lifetimes as two joint tokens in proc macros
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/quote.rs1
-rw-r--r--src/libsyntax/parse/lexer/mod.rs5
-rw-r--r--src/libsyntax/parse/token.rs6
-rw-r--r--src/libsyntax/print/pprust.rs1
4 files changed, 9 insertions, 4 deletions
diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs
index eeed291c0ca..a6e6ccde72c 100644
--- a/src/libsyntax/ext/quote.rs
+++ b/src/libsyntax/ext/quote.rs
@@ -711,6 +711,7 @@ fn expr_mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P<ast::Expr> {
         token::Pound        => "Pound",
         token::Dollar       => "Dollar",
         token::Question     => "Question",
+        token::SingleQuote  => "SingleQuote",
         token::Eof          => "Eof",
 
         token::Whitespace | token::Comment | token::Shebang(_) => {
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs
index 4da7b8e93d9..3e22598043a 100644
--- a/src/libsyntax/parse/lexer/mod.rs
+++ b/src/libsyntax/parse/lexer/mod.rs
@@ -1773,10 +1773,7 @@ fn ident_continue(c: Option<char>) -> bool {
 // The string is a valid identifier or a lifetime identifier.
 pub fn is_valid_ident(s: &str) -> bool {
     let mut chars = s.chars();
-    match chars.next() {
-        Some('\'') => ident_start(chars.next()) && chars.all(|ch| ident_continue(Some(ch))),
-        ch => ident_start(ch) && chars.all(|ch| ident_continue(Some(ch)))
-    }
+    ident_start(chars.next()) && chars.all(|ch| ident_continue(Some(ch)))
 }
 
 #[cfg(test)]
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index 6bcc1b0f026..a1c056cbb2c 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -210,6 +210,8 @@ pub enum Token {
     Pound,
     Dollar,
     Question,
+    /// Used by proc macros for representing lifetimes, not generated by lexer right now.
+    SingleQuote,
     /// An opening delimiter, eg. `{`
     OpenDelim(DelimToken),
     /// A closing delimiter, eg. `}`
@@ -513,6 +515,10 @@ impl Token {
                 Colon => ModSep,
                 _ => return None,
             },
+            SingleQuote => match joint {
+                Ident(ident, false) => Lifetime(ident),
+                _ => return None,
+            },
 
             Le | EqEq | Ne | Ge | AndAnd | OrOr | Tilde | BinOpEq(..) | At | DotDotDot | DotEq |
             DotDotEq | Comma | Semi | ModSep | RArrow | LArrow | FatArrow | Pound | Dollar |
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 99a6fcf170d..8e33fa08083 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -224,6 +224,7 @@ pub fn token_to_string(tok: &Token) -> String {
         token::Pound                => "#".to_string(),
         token::Dollar               => "$".to_string(),
         token::Question             => "?".to_string(),
+        token::SingleQuote          => "'".to_string(),
 
         /* Literals */
         token::Literal(lit, suf) => {