Make syntax a little Rustier

main
mat ess 2023-05-01 23:56:01 -04:00
parent c2c0dacb67
commit dc557c19de
2 changed files with 9 additions and 8 deletions

View File

@ -1,9 +1,9 @@
main = () -> { main = || {
result = sum_equals(1, 2, 3); let result = sum_equals(1, 2, 3);
print(result) print(result)
} }
sum_equals = (x, y, expected) -> { sum_equals = |x, y, expected| {
sum = add(x, y); let sum = add(x, y);
equals(sum, expected) equals(sum, expected)
} }

View File

@ -3,13 +3,13 @@ use crate::syntax::{Expression, Name, Statement};
grammar; grammar;
pub Statement: Statement = { pub Statement: Statement = {
<name:Name> "=" <body:Expression> ";" => Statement::Binding(name, body), "let" <Name> "=" <Expression> ";" => Statement::Binding(<>),
<body:Expression> ";" => Statement::Expression(body), <Expression> ";" => Statement::Expression(<>),
}; };
pub Expression: Expression = { pub Expression: Expression = {
"(" <params:Comma<Name>> ")" "->" <body:Expression> => Expression::Lambda(params, Box::new(body)), "|" <params:Comma<Name>> "|" <body:Expression> => Expression::Lambda(params, Box::new(body)),
Atom => <>, Atom,
}; };
Atom: Expression = { Atom: Expression = {
@ -18,6 +18,7 @@ Atom: Expression = {
<callee:Atom> "(" <args:Comma<Expression>> ")" => Expression::Call(Box::new(callee), args), <callee:Atom> "(" <args:Comma<Expression>> ")" => Expression::Call(Box::new(callee), args),
Integer => Expression::Integer(<>), Integer => Expression::Integer(<>),
Boolean => Expression::Boolean(<>), Boolean => Expression::Boolean(<>),
"(" <Expression> ")",
}; };
// TODO: decide on identifier syntax // TODO: decide on identifier syntax