Add else if control flow.

This commit is contained in:
Stephen Chung
2020-03-02 17:04:56 +08:00
parent cc87214750
commit ed8d2ac20f
4 changed files with 48 additions and 37 deletions

View File

@@ -818,18 +818,6 @@ impl Engine {
last_result
}
Stmt::If(guard, body) => self
.eval_expr(scope, guard)?
.downcast::<bool>()
.map_err(|_| EvalAltResult::ErrorIfGuard)
.and_then(|guard_val| {
if *guard_val {
self.eval_stmt(scope, body)
} else {
Ok(Box::new(()))
}
}),
Stmt::IfElse(guard, body, else_body) => self
.eval_expr(scope, guard)?
.downcast::<bool>()
@@ -837,8 +825,10 @@ impl Engine {
.and_then(|guard_val| {
if *guard_val {
self.eval_stmt(scope, body)
} else if else_body.is_some() {
self.eval_stmt(scope, else_body.as_ref().unwrap())
} else {
self.eval_stmt(scope, else_body)
Ok(Box::new(()))
}
}),