Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ident #68

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions pilota-build/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,33 +203,33 @@ pub trait IdentName {
fn as_syn_ident(&self) -> syn::Ident;
}

fn str2ident(s: &str) -> smol_str::SmolStr {
fn str2ident(s: &str) -> syn::Ident {
if s == "Self" {
return smol_str::SmolStr::new_inline("Self_");
return format_ident!("Self_");
}
if KEYWORDS_SET.contains(s) {
smol_str::SmolStr::new(format!("r#{}", s))
format_ident!("r#{}", s)
} else {
smol_str::SmolStr::new(s)
format_ident!("{}", s)
}
}

impl IdentName for &str {
fn upper_camel_ident(&self) -> smol_str::SmolStr {
let s = self.to_upper_camel_case();
str2ident(&s)
s.into()
}

fn snake_ident(&self) -> smol_str::SmolStr {
str2ident(&self.to_snake_case())
self.to_snake_case().into()
}

fn shouty_snake_case(&self) -> smol_str::SmolStr {
str2ident(&self.to_shouty_snake_case())
self.to_shouty_snake_case().into()
}

fn as_syn_ident(&self) -> syn::Ident {
format_ident!("{}", self)
str2ident(self)
}
}

Expand All @@ -247,6 +247,6 @@ impl IdentName for smol_str::SmolStr {
}

fn as_syn_ident(&self) -> syn::Ident {
format_ident!("{}", &**self)
str2ident(self)
}
}