adapt Abstraction variant of LTExpr to allow multiple parameters

This avoids unneccesary recursive chaining and also allows abstractions with zero parameters.
This commit is contained in:
Michael Sippel 2024-05-12 04:22:32 +02:00
parent a6282c00eb
commit f54f630b38
Signed by: senvas
GPG key ID: F96CF119C34B64A6
4 changed files with 39 additions and 27 deletions

View file

@ -175,13 +175,16 @@ where It: Iterator<Item = char>
Ok(LTIRToken::Lambda) => {
if children.len() == 0 {
tokens.next();
let name = parse_symbol(tokens)?;
let mut args = Vec::new();
while let Some(Ok(LTIRToken::Symbol(_))) = tokens.peek() {
args.push((parse_symbol(tokens)?, None));
}
let body = parse_expr(tokens)?;
return Ok(LTExpr::Abstraction{
arg_id: name,
arg_type: None,
val_expr: Box::new(body)
args,
body: Box::new(body)
});
} else {
return Err(ParseError::UnexpectedToken);