Add prelude and while macro

This commit introduces a new prelude file that defines the `while` macro
and registers it during environment bootstrapping. The `again` macro has
been updated to accept multiple arguments for its recursive call, and
several examples have been adjusted to reflect this change.
Additionally, the `MacroRegistry` in the compiler is now cloneable and
can be moved out of the `MacroExpander`.
This commit is contained in:
Michael Schimmel
2026-02-28 12:41:19 +01:00
parent 83324a1892
commit 7126668934
8 changed files with 56 additions and 26 deletions
+15 -2
View File
@@ -153,10 +153,23 @@ impl<'a> Parser<'a> {
}
fn parse_again(&mut self, identity: Identity) -> Result<Node<UntypedKind>, String> {
let args = Box::new(self.parse_expression()?);
let mut elements = Vec::new();
while *self.peek() != TokenKind::RightParen && *self.peek() != TokenKind::EOF {
elements.push(self.parse_expression()?);
}
let args_node = Node {
identity: identity.clone(),
kind: UntypedKind::Tuple { elements },
ty: (),
};
Ok(Node {
identity,
kind: UntypedKind::Again { args },
kind: UntypedKind::Again {
args: Box::new(args_node),
},
ty: (),
})
}