Add while loops
This commit is contained in:
parent
346d9ba878
commit
4be32d0a5d
@ -40,7 +40,8 @@ impl AbstractTree for Block {
|
||||
let action = statement.run(_context)?;
|
||||
previous = match action {
|
||||
Action::Return(value) => Action::Return(value),
|
||||
r#break => return Ok(r#break),
|
||||
Action::None => Action::None,
|
||||
Action::Break => return Ok(action),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -19,14 +19,27 @@ impl While {
|
||||
|
||||
impl AbstractTree for While {
|
||||
fn expected_type(&self, _context: &Context) -> Result<Type, ValidationError> {
|
||||
todo!()
|
||||
Ok(Type::None)
|
||||
}
|
||||
|
||||
fn validate(&self, _context: &Context) -> Result<(), ValidationError> {
|
||||
todo!()
|
||||
self.expression.validate(_context)?;
|
||||
self.block.validate(_context)
|
||||
}
|
||||
|
||||
fn run(self, _context: &Context) -> Result<Action, RuntimeError> {
|
||||
todo!()
|
||||
while self
|
||||
.expression
|
||||
.clone()
|
||||
.run(_context)?
|
||||
.as_return_value()?
|
||||
.as_boolean()?
|
||||
{
|
||||
if let Action::Break = self.block.clone().run(_context)? {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Action::None)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user