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
+45
View File
@@ -0,0 +1,45 @@
mod ast;
mod parser;
mod codegen;
use std::path::PathBuf;
fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() < 2 {
eprintln!("Usage: misses <input.mrs> [output.rs]");
std::process::exit(1);
}
let input_path = PathBuf::from(&args[1]);
let src = match std::fs::read_to_string(&input_path) {
Ok(s) => s,
Err(e) => {
eprintln!("Error reading {:?}: {}", input_path, e);
std::process::exit(1);
}
};
let ast = match parser::parse(&src) {
Ok(a) => a,
Err(e) => {
eprintln!("Parse error: {}", e);
std::process::exit(1);
}
};
let generated = codegen::codegen(&ast);
if args.len() >= 3 {
let output_path = PathBuf::from(&args[2]);
match std::fs::write(&output_path, &generated) {
Ok(_) => {}
Err(e) => {
eprintln!("Error writing {:?}: {}", output_path, e);
std::process::exit(1);
}
}
} else {
print!("{}", generated);
}
}