- Move .mrs files into misses-compiler/examples/ alongside .rs runners - Add lib.rs exposing parse/codegen for use by example binaries and main.rs - Fix parser: #[attr] vs #[a => b] disambiguation (look for => before ]) - Fix parser: `for` keyword in `impl Foo for Bar` no longer triggers spread (is_spread_for lookahead: must match `for <ident> in $<ident> =>`) - Add derive_getters.mrs: getter methods via spread iteration - Add make_id_type.mrs: newtype u64 wrapper with From impls, derive attrs Run with: cargo run --example hello|derive_builder|declare_table|derive_getters|make_id_type https://claude.ai/code/session_01Tppkab4eLsL21asHGjQJoF
25 lines
851 B
Plaintext
25 lines
851 B
Plaintext
// derive_builder.mrs — builder pattern generator
|
|
// Demonstrates: struct pattern, variadic field binding, escape block,
|
|
// expression injection, spread iteration in struct and impl bodies
|
|
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(),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|