Do not parse reserved words as ident
diff --git a/src/ident.rs b/src/ident.rs
index 8b65e5b..e61a11c 100644
--- a/src/ident.rs
+++ b/src/ident.rs
@@ -54,7 +54,26 @@
use space::skip_whitespace;
use unicode_xid::UnicodeXID;
- pub fn ident(mut input: &str) -> IResult<&str, Ident> {
+ pub fn ident(input: &str) -> IResult<&str, Ident> {
+ let (rest, id) = match word(input) {
+ IResult::Done(rest, id) => (rest, id),
+ IResult::Error => return IResult::Error,
+ };
+
+ match id.as_ref() {
+ // From https://doc.rust-lang.org/grammar.html#keywords
+ "abstract" | "alignof" | "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" | "offsetof" | "override" | "priv" | "proc" | "pub" | "pure" | "ref" |
+ "return" | "Self" | "self" | "sizeof" | "static" | "struct" | "super" | "trait" |
+ "true" | "type" | "typeof" | "unsafe" | "unsized" | "use" | "virtual" | "where" |
+ "while" | "yield" => IResult::Error,
+ _ => IResult::Done(rest, id),
+ }
+ }
+
+ pub fn word(mut input: &str) -> IResult<&str, Ident> {
input = skip_whitespace(input);
let mut chars = input.char_indices();
diff --git a/src/mac.rs b/src/mac.rs
index e96bdcf..7e6e05c 100644
--- a/src/mac.rs
+++ b/src/mac.rs
@@ -114,7 +114,7 @@
use super::*;
use Lifetime;
use generics::parsing::lifetime;
- use ident::parsing::ident;
+ use ident::parsing::{ident, word};
use lit::parsing::lit;
use space::{block_comment, whitespace};
@@ -181,7 +181,7 @@
|
map!(lit, Token::Literal)
|
- map!(ident, Token::Ident)
+ map!(word, Token::Ident)
|
map!(lifetime, |lt: Lifetime| Token::Lifetime(lt.ident))
|