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:
parent
a6282c00eb
commit
f54f630b38
4 changed files with 39 additions and 27 deletions
src
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue