Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/syn-2.0.119/src/ident.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / syn-2.0.119 / src / ident.rs` 109 lines ยท 3176 bytes Raw Blame History 1 #[cfg(feature = "parsing")] 2 use crate::lookahead; 3 4 pub use proc_macro2::Ident; 5 6 #[cfg(feature = "parsing")] 7 pub_if_not_doc! { 8 #[doc(hidden)] 9 #[allow(non_snake_case)] 10 pub fn Ident(marker: lookahead::TokenMarker) -> Ident { 11 match marker {} 12 } 13 } 14 15 macro_rules! ident_from_token { 16 ($token:ident) => { 17 impl From for Ident { 18 fn from(token: Token![$token]) -> Ident { 19 Ident::new(stringify!($token), token.span) 20 } 21 } 22 }; 23 } 24 25 ident_from_token!(self); 26 ident_from_token!(Self); 27 ident_from_token!(super); 28 ident_from_token!(crate); 29 ident_from_token!(extern); 30 31 impl From for Ident { 32 fn from(token: Token![_]) -> Ident { 33 Ident::new("_", token.span) 34 } 35 } 36 37 pub(crate) fn xid_ok(symbol: &str) -> bool { 38 let mut chars = symbol.chars(); 39 let first = chars.next().unwrap(); 40 if !(first == '_' || unicode_ident::is_xid_start(first)) { 41 return false; 42 } 43 for ch in chars { 44 if !unicode_ident::is_xid_continue(ch) { 45 return false; 46 } 47 } 48 true 49 } 50 51 #[cfg(feature = "parsing")] 52 mod parsing { 53 use crate::buffer::Cursor; 54 use crate::error::Result; 55 use crate::parse::{Parse, ParseStream}; 56 use crate::token::Token; 57 use alloc::string::ToString; 58 use proc_macro2::Ident; 59 60 fn accept_as_ident(ident: &Ident) -> bool { 61 match ident.to_string().as_str() { 62 "_" | 63 // Based on https://doc.rust-lang.org/1.65.0/reference/keywords.html 64 "abstract" | "as" | "async" | "await" | "become" | "box" | "break" | 65 "const" | "continue" | "crate" | "do" | "dyn" | "else" | "enum" | 66 "extern" | "false" | "final" | "fn" | "for" | "if" | "impl" | "in" | 67 "let" | "loop" | "macro" | "match" | "mod" | "move" | "mut" | 68 "override" | "priv" | "pub" | "ref" | "return" | "Self" | "self" | 69 "static" | "struct" | "super" | "trait" | "true" | "try" | "type" | 70 "typeof" | "unsafe" | "unsized" | "use" | "virtual" | "where" | 71 "while" | "yield" => false, 72 _ => true, 73 } 74 } 75 76 #[cfg_attr(docsrs, doc(cfg(feature = "parsing")))] 77 impl Parse for Ident { 78 fn parse(input: ParseStream) -> Result { 79 input.step(|cursor| { 80 if let Some((ident, rest)) = cursor.ident() { 81 if accept_as_ident(&ident) { 82 Ok((ident, rest)) 83 } else { 84 Err(cursor.error(format_args!( 85 "expected identifier, found keyword `{}`", 86 ident, 87 ))) 88 } 89 } else { 90 Err(cursor.error("expected identifier")) 91 } 92 }) 93 } 94 } 95 96 impl Token for Ident { 97 fn peek(cursor: Cursor) -> bool { 98 if let Some((ident, _rest)) = cursor.ident() { 99 accept_as_ident(&ident) 100 } else { 101 false 102 } 103 } 104 105 fn display() -> &'static str { 106 "identifier" 107 } 108 } 109 }