Add 'again' keyword for recursive calls
The `again` keyword is introduced to facilitate explicit recursive function calls. It is restricted to tail-call positions to prevent dead code and ensure TCO optimization. Type checking is enhanced to validate argument types against function parameters.
This commit is contained in:
@@ -140,6 +140,7 @@ impl<'a> Parser<'a> {
|
||||
match sym.name.as_ref() {
|
||||
"if" => self.parse_if(identity),
|
||||
"fn" => self.parse_fn(identity),
|
||||
"again" => self.parse_again(identity),
|
||||
"def" => self.parse_def(identity),
|
||||
"assign" => self.parse_assign(identity),
|
||||
"do" => self.parse_do(identity),
|
||||
@@ -154,6 +155,15 @@ impl<'a> Parser<'a> {
|
||||
result
|
||||
}
|
||||
|
||||
fn parse_again(&mut self, identity: Identity) -> Result<Node<UntypedKind>, String> {
|
||||
let args = Box::new(self.parse_expression()?);
|
||||
Ok(Node {
|
||||
identity,
|
||||
kind: UntypedKind::Again { args },
|
||||
ty: (),
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_if(&mut self, identity: Identity) -> Result<Node<UntypedKind>, String> {
|
||||
let cond = Box::new(self.parse_expression()?);
|
||||
let then_br = Box::new(self.parse_expression()?);
|
||||
|
||||
Reference in New Issue
Block a user