Add misses-rt crate, component example, README, and fix codegen for non-keyword literal tokens
- misses-rt: add Buffer/Markup HTML helpers, name/type helpers, parse_sections/parse_kv, and template AST - codegen: add is_syn_keyword() — non-keyword idents in patterns now generate parse+compare instead of syn::Token![…] - parser: split punct vs ident chars in literal pattern tokens so `props:` becomes two tokens - examples: add component.mrs/.rs demonstrating named literal tokens and tt capture - README: comprehensive guide covering .mrs syntax, running the compiler, misses-rt helpers, and examples https://claude.ai/code/session_01Tppkab4eLsL21asHGjQJoF
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
// component.mrs — Vue-like component macro generator
|
||||
// Demonstrates: named literal tokens, variadic binding, $body:tt capture,
|
||||
// escape block using misses_rt, expression injection
|
||||
macro component! {
|
||||
$name:ident { $($prop_name:ident : $prop_type:ty),* } $body:tt => {
|
||||
@{
|
||||
let struct_name = format_ident!("{}", name.to_string());
|
||||
}
|
||||
T~{
|
||||
pub struct $name {
|
||||
for prop in $prop_names =>
|
||||
pub $prop_name.name: $prop_name.ty,
|
||||
}
|
||||
|
||||
impl $name {
|
||||
pub fn new(${ struct_name }(
|
||||
for prop in $prop_names =>
|
||||
$prop_name.name: $prop_name.ty,
|
||||
)) -> Self {
|
||||
Self {
|
||||
for prop in $prop_names =>
|
||||
$prop_name.name,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(&self) -> misses_rt::Markup {
|
||||
misses_rt::parse_template($body)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fn main() {
|
||||
let source = include_str!("component.mrs");
|
||||
println!("=== SOURCE ===\n{source}");
|
||||
|
||||
let file = misses::parse(source).expect("parse error");
|
||||
let generated = misses::codegen(&file);
|
||||
println!("=== GENERATED ===\n{generated}");
|
||||
}
|
||||
Reference in New Issue
Block a user