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