Implement Misses DSL compiler (parser + codegen)

- ast.rs: Full AST for .mrs files (MacroDef, Pattern, OutputBody, TemplateItem)
- parser.rs: Hand-written recursive descent parser with line/col error reporting
- codegen.rs: Transforms AST to Rust proc macro code using syn/quote/proc_macro2
- main.rs: CLI reads .mrs file, runs parse→codegen, writes to stdout or file
- Cargo.toml: Workspace with syn, quote, proc-macro2, prettyplease deps
- examples/: hello.mrs, derive_builder.mrs, declare_table.mrs reference examples

All three reference examples parse and produce prettyplease-formatted Rust output.
Generated code uses syn::parse::Parser closures for structural patterns, quote!
for token templates, spread iteration via .iter().map().collect(), and
format_ident! for identifier construction.

https://claude.ai/code/session_01Tppkab4eLsL21asHGjQJoF
This commit is contained in:
Claude
2026-03-07 11:37:58 +00:00
commit ed62264870
11 changed files with 1152 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
macro declare_table! {
$name:ident { $body:tt } => {
@{
let table_str = misses_rt::to_table_name(&name);
}
T~{
pub struct $name {
pub id: u64,
}
impl $name {
pub const TABLE: &'static str = ${ table_str.as_str() };
}
}
}
}
+21
View File
@@ -0,0 +1,21 @@
macro derive_builder! {
struct $name:ident { $($field:ident : $ty:ty),* } => {
@{
let builder_name = format_ident!("{}_Builder", name.to_string());
}
T~{
pub struct ${ builder_name } {
for field in $fields =>
pub $field.name: Option<$field.ty>,
}
impl ${ builder_name } {
pub fn build(self) -> $name {
$name {
for field in $fields =>
$field.name: self.$field.name.unwrap(),
}
}
}
}
}
}
+9
View File
@@ -0,0 +1,9 @@
macro hello! {
$name:ident => {
T~{
pub fn #[say => hello]() -> &'static str {
${ format!("hello, {}!", stringify!(name)) }
}
}
}
}