feat: Implement AST macros and templates
This commit introduces support for AST macros and templates, enabling users to define and use custom, reusable components within the visual DSL. Key changes include: - A new `MacroRegistry` to manage macro definitions. - A `MacroExpander` to process macro calls and expand templates. - A `MacroEvaluator` trait for evaluating expressions during expansion. - The `Expansion` node in `BoundKind` to preserve the original macro call and its expanded form for debugging. - Updates to the `Binder`, `Dumper`, and `UpvalueAnalyzer` to handle the new macro constructs. - New examples demonstrating various macro functionalities like `unless`, splicing, and nested macros.
This commit is contained in:
@@ -300,6 +300,19 @@ impl Binder {
|
||||
|
||||
Ok(self.make_node(node.identity.clone(), BoundKind::Map { entries: bound_entries }, ty))
|
||||
},
|
||||
|
||||
UntypedKind::Expansion { call, expanded } => {
|
||||
let bound_expanded = self.bind(expanded)?;
|
||||
let ty = bound_expanded.ty.clone();
|
||||
Ok(self.make_node(node.identity.clone(), BoundKind::Expansion {
|
||||
original_call: Rc::from(call.as_ref().clone()),
|
||||
bound_expanded: Box::new(bound_expanded),
|
||||
}, ty))
|
||||
},
|
||||
|
||||
UntypedKind::Template(_) | UntypedKind::Placeholder(_) | UntypedKind::Splice(_) | UntypedKind::MacroDecl { .. } => {
|
||||
Err(format!("Macro construct {:?} found in Binder. Macros must be expanded before binding.", node.kind))
|
||||
}
|
||||
|
||||
UntypedKind::Extension(_) => {
|
||||
Err("Custom extensions not supported in Binder yet".to_string())
|
||||
|
||||
Reference in New Issue
Block a user