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 = () -> {
result = sum_equals(1, 2, 3);
main = || {
let result = sum_equals(1, 2, 3);
print(result)
}
sum_equals = (x, y, expected) -> {
sum = add(x, y);
sum_equals = |x, y, expected| {
let sum = add(x, y);
equals(sum, expected)
}

View File

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