Make syntax a little Rustier
parent
c2c0dacb67
commit
dc557c19de
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue