diff options
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 6 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 22a0261d8c6..3e22598043a 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1770,6 +1770,12 @@ fn ident_continue(c: Option<char>) -> bool { (c > '\x7f' && c.is_xid_continue()) } +// The string is a valid identifier or a lifetime identifier. +pub fn is_valid_ident(s: &str) -> bool { + let mut chars = s.chars(); + ident_start(chars.next()) && chars.all(|ch| ident_continue(Some(ch))) +} + #[cfg(test)] mod tests { use super::*; 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 | |
