Move Ident parser to ident.rs
diff --git a/src/ident.rs b/src/ident.rs
index df4386b..368b0c3 100644
--- a/src/ident.rs
+++ b/src/ident.rs
@@ -1,5 +1,7 @@
#[cfg(feature = "parsing")]
use lookahead;
+#[cfg(feature = "parsing")]
+use parse::{Parse, ParseStream, Result};
pub use proc_macro2::Ident;
@@ -9,3 +11,27 @@
pub fn Ident(marker: lookahead::TokenMarker) -> Ident {
match marker {}
}
+
+#[cfg(feature = "parsing")]
+impl Parse for Ident {
+ fn parse(input: ParseStream) -> Result<Self> {
+ input.step(|cursor| {
+ if let Some((ident, rest)) = cursor.ident() {
+ match ident.to_string().as_str() {
+ "_"
+ // Based on https://doc.rust-lang.org/grammar.html#keywords
+ // and https://github.com/rust-lang/rfcs/blob/master/text/2421-unreservations-2018.md
+ | "abstract" | "as" | "become" | "box" | "break" | "const"
+ | "continue" | "crate" | "do" | "else" | "enum" | "extern" | "false" | "final"
+ | "fn" | "for" | "if" | "impl" | "in" | "let" | "loop" | "macro" | "match"
+ | "mod" | "move" | "mut" | "override" | "priv" | "proc" | "pub"
+ | "ref" | "return" | "Self" | "self" | "static" | "struct"
+ | "super" | "trait" | "true" | "type" | "typeof" | "unsafe" | "unsized" | "use"
+ | "virtual" | "where" | "while" | "yield" => {}
+ _ => return Ok((ident, rest)),
+ }
+ }
+ Err(cursor.error("expected identifier"))
+ })
+ }
+}
diff --git a/src/parse.rs b/src/parse.rs
index 05d9261..ced7f25 100644
--- a/src/parse.rs
+++ b/src/parse.rs
@@ -128,7 +128,7 @@
feature = "proc-macro"
))]
use proc_macro;
-use proc_macro2::{self, Delimiter, Group, Ident, Literal, Punct, Span, TokenStream, TokenTree};
+use proc_macro2::{self, Delimiter, Group, Literal, Punct, Span, TokenStream, TokenTree};
use buffer::{Cursor, TokenBuffer};
use error;
@@ -307,29 +307,6 @@
}
}
-impl Parse for Ident {
- fn parse(input: ParseStream) -> Result<Self> {
- input.step(|cursor| {
- if let Some((ident, rest)) = cursor.ident() {
- match ident.to_string().as_str() {
- "_"
- // Based on https://doc.rust-lang.org/grammar.html#keywords
- // and https://github.com/rust-lang/rfcs/blob/master/text/2421-unreservations-2018.md
- | "abstract" | "as" | "become" | "box" | "break" | "const"
- | "continue" | "crate" | "do" | "else" | "enum" | "extern" | "false" | "final"
- | "fn" | "for" | "if" | "impl" | "in" | "let" | "loop" | "macro" | "match"
- | "mod" | "move" | "mut" | "override" | "priv" | "proc" | "pub"
- | "ref" | "return" | "Self" | "self" | "static" | "struct"
- | "super" | "trait" | "true" | "type" | "typeof" | "unsafe" | "unsized" | "use"
- | "virtual" | "where" | "while" | "yield" => {}
- _ => return Ok((ident, rest)),
- }
- }
- Err(cursor.error("expected identifier"))
- })
- }
-}
-
impl<T: Parse> Parse for Box<T> {
fn parse(input: ParseStream) -> Result<Self> {
input.parse().map(Box::new)