summaryrefslogtreecommitdiff
path: root/src/chomp/mod.rs
diff options
context:
space:
mode:
authorGreg Brown <gmb60@cam.ac.uk>2021-01-14 11:42:55 +0000
committerGreg Brown <gmb60@cam.ac.uk>2021-01-14 11:42:55 +0000
commitaac3549a72663c523a456b2f5d7c3b77f509cdd6 (patch)
tree562824f3cfa5feca791715c733f7749197bb7e7a /src/chomp/mod.rs
parent0d01692c97ea8ca6fc4b229e5b9678cb252bceda (diff)
Add labelled expressions.
Restructure project (again). Convert `Cat` and `Alt` from binary to n+2-ary.
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) {