Skip to content
Snippets Groups Projects
Verified Commit b07278c5 authored by Louis's avatar Louis :fire:
Browse files

Implement conditional blocks

parent f8b051c1
No related branches found
No related tags found
No related merge requests found
Pipeline #498 passed with stages
in 55 seconds
...@@ -149,7 +149,7 @@ impl Visitor for SimpleExecutor { ...@@ -149,7 +149,7 @@ impl Visitor for SimpleExecutor {
} }
} }
ValueExpression::Grouped(group) => self.evaluate_value_expression(group.inner.as_ref()), ValueExpression::Grouped(group) => self.evaluate_value_expression(group.inner.as_ref()),
ValueExpression::Block(_) => Err(RuntimeError::Unsupported("Block")), ValueExpression::Block(block) => self.evaluate_expression_list(block),
ValueExpression::Literal(lit) => Ok(ForgeValue::from(lit.clone())), ValueExpression::Literal(lit) => Ok(ForgeValue::from(lit.clone())),
ValueExpression::DeclareIdentifier(decl) => match decl { ValueExpression::DeclareIdentifier(decl) => match decl {
DeclareIdent::WithValue(assignment) => { DeclareIdent::WithValue(assignment) => {
...@@ -161,9 +161,27 @@ impl Visitor for SimpleExecutor { ...@@ -161,9 +161,27 @@ impl Visitor for SimpleExecutor {
Ok(ForgeValue::Null) Ok(ForgeValue::Null)
} }
}, },
ValueExpression::Assignment(_) => Err(RuntimeError::Unsupported("Assignment")), ValueExpression::Assignment(assign) => self.process_assignment(assign),
ValueExpression::ConditionalBlock(_) => { ValueExpression::ConditionalBlock(condition) => {
Err(RuntimeError::Unsupported("ConditionalBlock")) let mut has_found = false;
let mut last_value = ForgeValue::Null;
for block in condition.blocks.iter() {
let guard_val = self.evaluate_value_expression(block.guard.as_ref())?;
if guard_val.as_bool() {
has_found = true;
last_value = self.evaluate_expression_list(&block.block)?;
break;
}
}
if !has_found {
if let Some(value) = &condition.fallback {
last_value = self.evaluate_expression_list(value)?;
}
}
Ok(last_value)
} }
ValueExpression::Identifier(ident) => self ValueExpression::Identifier(ident) => self
.get_variable(ident) .get_variable(ident)
......
...@@ -359,13 +359,7 @@ impl Not for ForgeValue { ...@@ -359,13 +359,7 @@ impl Not for ForgeValue {
type Output = ForgeValue; type Output = ForgeValue;
fn not(self) -> Self::Output { fn not(self) -> Self::Output {
match self { ForgeValue::Boolean(!self.as_bool())
ForgeValue::Number(num) => (num != Number::Integer(0)).into(),
ForgeValue::Boolean(b) => (!b).into(),
ForgeValue::String(st) => (!st.is_empty()).into(),
ForgeValue::List(ls) => (!ls.is_empty()).into(),
ForgeValue::Null => ForgeValue::Null,
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment