chore(vendor): add anyhow crate
This commit was merged in pull request #68.
This commit is contained in:
109
third_party/crates/syn-3.0.6/src/ident.rs
vendored
Normal file
109
third_party/crates/syn-3.0.6/src/ident.rs
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
#[cfg(feature = "parsing")]
|
||||
use crate::lookahead;
|
||||
|
||||
pub use proc_macro2::Ident;
|
||||
|
||||
#[cfg(feature = "parsing")]
|
||||
pub_if_not_doc! {
|
||||
#[doc(hidden)]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn Ident(marker: lookahead::TokenMarker) -> Ident {
|
||||
match marker {}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! ident_from_token {
|
||||
($token:ident) => {
|
||||
impl From<Token![$token]> for Ident {
|
||||
fn from(token: Token![$token]) -> Ident {
|
||||
Ident::new(stringify!($token), token.span)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
ident_from_token!(self);
|
||||
ident_from_token!(Self);
|
||||
ident_from_token!(super);
|
||||
ident_from_token!(crate);
|
||||
ident_from_token!(extern);
|
||||
|
||||
impl From<Token![_]> for Ident {
|
||||
fn from(token: Token![_]) -> Ident {
|
||||
Ident::new("_", token.span)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn xid_ok(symbol: &str) -> bool {
|
||||
let mut chars = symbol.chars();
|
||||
let first = chars.next().unwrap();
|
||||
if !(first == '_' || unicode_ident::is_xid_start(first)) {
|
||||
return false;
|
||||
}
|
||||
for ch in chars {
|
||||
if !unicode_ident::is_xid_continue(ch) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(feature = "parsing")]
|
||||
pub(crate) mod parsing {
|
||||
use crate::buffer::Cursor;
|
||||
use crate::error::Result;
|
||||
use crate::parse::{Parse, ParseStream};
|
||||
use crate::token::Token;
|
||||
use alloc::string::ToString;
|
||||
use proc_macro2::Ident;
|
||||
|
||||
pub(crate) fn accept_as_ident(repr: &str) -> bool {
|
||||
match repr {
|
||||
"_" |
|
||||
// Based on https://doc.rust-lang.org/1.65.0/reference/keywords.html
|
||||
"abstract" | "as" | "async" | "await" | "become" | "box" | "break" |
|
||||
"const" | "continue" | "crate" | "do" | "dyn" | "else" | "enum" |
|
||||
"extern" | "false" | "final" | "fn" | "for" | "if" | "impl" | "in" |
|
||||
"let" | "loop" | "macro" | "match" | "mod" | "move" | "mut" |
|
||||
"override" | "priv" | "pub" | "ref" | "return" | "Self" | "self" |
|
||||
"static" | "struct" | "super" | "trait" | "true" | "try" | "type" |
|
||||
"typeof" | "unsafe" | "unsized" | "use" | "virtual" | "where" |
|
||||
"while" | "yield" => false,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
|
||||
impl Parse for Ident {
|
||||
fn parse(input: ParseStream) -> Result<Self> {
|
||||
input.step(|cursor| {
|
||||
if let Some((ident, rest)) = cursor.ident() {
|
||||
if accept_as_ident(&ident.to_string()) {
|
||||
Ok((ident, rest))
|
||||
} else {
|
||||
Err(cursor.error(format_args!(
|
||||
"expected identifier, found keyword `{}`",
|
||||
ident,
|
||||
)))
|
||||
}
|
||||
} else {
|
||||
Err(cursor.error("expected identifier"))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Token for Ident {
|
||||
fn peek(cursor: Cursor) -> bool {
|
||||
if let Some((ident, _rest)) = cursor.ident() {
|
||||
accept_as_ident(&ident.to_string())
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn display() -> &'static str {
|
||||
"identifier"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user