summaryrefslogtreecommitdiff
path: root/src/chomp/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/chomp/mod.rs')
-rw-r--r--src/chomp/mod.rs36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/chomp/mod.rs b/src/chomp/mod.rs
index 1e30738..79b4fac 100644
--- a/src/chomp/mod.rs
+++ b/src/chomp/mod.rs
@@ -1,12 +1,10 @@
use std::{fmt, hash};
+use heck::{CamelCase, SnakeCase};
use proc_macro2::{Ident, Span};
use syn::ext::IdentExt;
pub mod ast;
-pub mod check;
-pub mod context;
-pub mod error;
pub mod set;
pub mod typed;
pub mod visit;
@@ -25,7 +23,7 @@ impl Name {
}
}
- pub fn as_ident(self, span: Span) -> Ident {
+ pub fn into_ident(self, span: Span) -> Ident {
match self {
Self::Spanned(i) => i,
Self::Spanless(s) => Ident::new(&s, span),
@@ -33,6 +31,36 @@ impl Name {
}
}
+impl CamelCase for Name {
+ fn to_camel_case(&self) -> Self::Owned {
+ match self {
+ Self::Spanned(ident) => {
+ let span = ident.span();
+ let name = ident.unraw().to_string();
+ Ident::new(&name.to_camel_case(), span).into()
+ }
+ Name::Spanless(name) => {
+ name.to_camel_case().into()
+ }
+ }
+ }
+}
+
+impl SnakeCase for Name {
+ fn to_snake_case(&self) -> Self::Owned {
+ match self {
+ Self::Spanned(ident) => {
+ let span = ident.span();
+ let name = ident.unraw().to_string();
+ Ident::new(&name.to_snake_case(), span).into()
+ }
+ Name::Spanless(name) => {
+ name.to_snake_case().into()
+ }
+ }
+ }
+}
+
impl PartialEq for Name {
fn eq(&self, other: &Self) -> bool {
match (self, other) {