fixed return precedence and operator parsing

This commit is contained in:
Matthieu Jolimaitre 2024-10-25 13:58:45 +02:00
parent 3868298f00
commit 7febf91d3c
2 changed files with 10 additions and 3 deletions

View file

@ -220,8 +220,8 @@ impl ShortDef {
pub fn parser(expr: impl Parse<Expr>) -> impl Parse<Self> {
(lx("break").map(|_| Self::Break))
.or(lx("continue").map(|_| Self::Continue))
.or(lx("return").map(|_| Self::Return(Expr::Litteral(Litteral::None))))
.or(lx("return").ignore_then(expr).map(Self::Return))
.or(lx("return").map(|_| Self::Return(Expr::Litteral(Litteral::None))))
}
pub fn eval(&self, context: &mut Context) -> Result<Short, EvalError> {
@ -345,10 +345,10 @@ impl Op {
.or(lx("*").map(|_| Self::Prod))
.or(lx("==").map(|_| Self::Eq))
.or(lx("!=").map(|_| Self::Neq))
.or(lx("<").map(|_| Self::Lt))
.or(lx(">").map(|_| Self::Gt))
.or(lx("<=").map(|_| Self::Leq))
.or(lx(">=").map(|_| Self::Geq))
.or(lx("<").map(|_| Self::Lt))
.or(lx(">").map(|_| Self::Gt))
}
pub fn apply(&self, l: &Value, r: &Value) -> Result<Value, EvalError> {