diff --git a/forge-script-lang/src/runtime/executor/simple.rs b/forge-script-lang/src/runtime/executor/simple.rs index f4f99aceca8c8dc64982f71ae712c049a51adf2d..12a04b3dbfe43ec3d1e30acb88e57d249d40d6df 100644 --- a/forge-script-lang/src/runtime/executor/simple.rs +++ b/forge-script-lang/src/runtime/executor/simple.rs @@ -149,7 +149,7 @@ impl Visitor for SimpleExecutor { } } 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::DeclareIdentifier(decl) => match decl { DeclareIdent::WithValue(assignment) => { @@ -161,9 +161,27 @@ impl Visitor for SimpleExecutor { Ok(ForgeValue::Null) } }, - ValueExpression::Assignment(_) => Err(RuntimeError::Unsupported("Assignment")), - ValueExpression::ConditionalBlock(_) => { - Err(RuntimeError::Unsupported("ConditionalBlock")) + ValueExpression::Assignment(assign) => self.process_assignment(assign), + ValueExpression::ConditionalBlock(condition) => { + 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 .get_variable(ident) diff --git a/forge-script-lang/src/runtime/value.rs b/forge-script-lang/src/runtime/value.rs index ad6e04fcc91be51c2ea4e61dcc2ddddd9b00d0ce..697567fa18eb04de9fc8ca08ae5f1e02ec0500bf 100644 --- a/forge-script-lang/src/runtime/value.rs +++ b/forge-script-lang/src/runtime/value.rs @@ -359,13 +359,7 @@ impl Not for ForgeValue { type Output = ForgeValue; fn not(self) -> Self::Output { - match self { - 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, - } + ForgeValue::Boolean(!self.as_bool()) } }