Handle raw identifiers in proc macro server

This commit is contained in:
Ryo Yoshida 2022-12-03 22:57:08 +09:00
parent 04a2ac2de2
commit de591f08d6
No known key found for this signature in database
GPG key ID: E25698A930586171
5 changed files with 27 additions and 12 deletions

View file

@ -86,10 +86,20 @@ pub enum Spacing {
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Ident {
/// Identifier or keyword. Unlike rustc, we keep "r#" prefix when it represents a raw identifier.
pub text: SmolStr,
pub id: TokenId,
}
impl Ident {
/// Constructor intended to be used only by proc macro server. `text` should not contain raw
/// identifier prefix.
pub fn new_with_is_raw(text: SmolStr, id: TokenId, is_raw: bool) -> Self {
let text = if is_raw { SmolStr::from_iter(["r#", &text]) } else { text };
Ident { text, id }
}
}
impl Leaf {
pub fn id(&self) -> TokenId {
match self {