diff --git a/Cargo.toml b/Cargo.toml index 7581a3c..8943f29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ trace = ["tracing/max_level_trace", "tracing/release_max_level_trace", "tracing" features = ["explanations"] [dependencies] +slotted-egraphs-derive = { path = "slotted-egraphs-derive" } fnv = "1.0.7" tracing = { version = "0.1", features = ["attributes"], optional = true } diff --git a/slotted-egraphs-derive/Cargo.toml b/slotted-egraphs-derive/Cargo.toml new file mode 100644 index 0000000..b4b9d96 --- /dev/null +++ b/slotted-egraphs-derive/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "slotted-egraphs-derive" +version = "0.1.0" +edition = "2021" + +[dependencies] +syn = { version = "2.0", features = ["full"] } +quote = "1.0" +proc-macro2 = "1.0" + +[lib] +proc-macro = true diff --git a/slotted-egraphs-derive/src/lib.rs b/slotted-egraphs-derive/src/lib.rs new file mode 100644 index 0000000..1136de9 --- /dev/null +++ b/slotted-egraphs-derive/src/lib.rs @@ -0,0 +1,14 @@ +use proc_macro::TokenStream as TokenStream1; +use proc_macro2::TokenStream as TokenStream2; +use quote::{format_ident, quote, ToTokens}; +use syn::*; + +#[proc_macro] +pub fn define_language(input: TokenStream1) -> TokenStream1 { + let mut xx: ItemEnum = parse(input).unwrap(); + xx.variants.iter_mut().for_each(|x| { + x.attrs.clear(); + x.discriminant = None; + }); + quote! { #xx }.to_token_stream().into() +} diff --git a/src/lang.rs b/src/lang.rs index 6160973..9759a2b 100644 --- a/src/lang.rs +++ b/src/lang.rs @@ -1,5 +1,19 @@ use crate::*; +pub struct Bind { + pub slot: Slot, + pub elem: T, +} + +define_language! { + enum ExampleLanguage { + Lambda(Bind) = "lambda", + App(AppliedId, AppliedId) = "app", + Var(Slot) = "var", + #[substitution_op] Let(AppliedId, Bind) = "let", + } +} + #[derive(Debug, Clone)] /// A child node of some term ("child" in the sense of an AST). /// diff --git a/src/lib.rs b/src/lib.rs index 896645e..3b79c80 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,8 @@ const CHECKS: bool = true; #[cfg(not(feature = "checks"))] const CHECKS: bool = false; +pub use slotted_egraphs_derive::define_language; + mod slot; pub use slot::*;