blob: 368b0c3e6a8b3bcbb91f6d03ccec2041e8f8d263 [file] [log] [blame]
David Tolnay4fb71232018-08-25 23:14:50 -04001#[cfg(feature = "parsing")]
2use lookahead;
David Tolnayf07b3342018-09-01 11:58:11 -07003#[cfg(feature = "parsing")]
4use parse::{Parse, ParseStream, Result};
David Tolnay4fb71232018-08-25 23:14:50 -04005
6pub use proc_macro2::Ident;
7
8#[cfg(feature = "parsing")]
9#[doc(hidden)]
10#[allow(non_snake_case)]
11pub fn Ident(marker: lookahead::TokenMarker) -> Ident {
12 match marker {}
13}
David Tolnayf07b3342018-09-01 11:58:11 -070014
15#[cfg(feature = "parsing")]
16impl Parse for Ident {
17 fn parse(input: ParseStream) -> Result<Self> {
18 input.step(|cursor| {
19 if let Some((ident, rest)) = cursor.ident() {
20 match ident.to_string().as_str() {
21 "_"
22 // Based on https://doc.rust-lang.org/grammar.html#keywords
23 // and https://github.com/rust-lang/rfcs/blob/master/text/2421-unreservations-2018.md
24 | "abstract" | "as" | "become" | "box" | "break" | "const"
25 | "continue" | "crate" | "do" | "else" | "enum" | "extern" | "false" | "final"
26 | "fn" | "for" | "if" | "impl" | "in" | "let" | "loop" | "macro" | "match"
27 | "mod" | "move" | "mut" | "override" | "priv" | "proc" | "pub"
28 | "ref" | "return" | "Self" | "self" | "static" | "struct"
29 | "super" | "trait" | "true" | "type" | "typeof" | "unsafe" | "unsized" | "use"
30 | "virtual" | "where" | "while" | "yield" => {}
31 _ => return Ok((ident, rest)),
32 }
33 }
34 Err(cursor.error("expected identifier"))
35 })
36 }
37}