From aac3549a72663c523a456b2f5d7c3b77f509cdd6 Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Thu, 14 Jan 2021 11:42:55 +0000 Subject: Add labelled expressions. Restructure project (again). Convert `Cat` and `Alt` from binary to n+2-ary. --- src/chomp/mod.rs | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'src/chomp/mod.rs') 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) { -- cgit v1.2.3