1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
use crate::lua_generator::{LuaGenerator, ToLua}; use crate::nodes::{ Block, Expression, }; #[derive(Clone, Debug, PartialEq, Eq)] pub struct RepeatStatement { block: Block, condition: Expression, } impl RepeatStatement { pub fn new(block: Block, condition: Expression) -> Self { Self { block, condition, } } pub fn get_block(&self) -> &Block { &self.block } pub fn mutate_block(&mut self) -> &mut Block { &mut self.block } pub fn mutate_condition(&mut self) -> &mut Expression { &mut self.condition } } impl ToLua for RepeatStatement { fn to_lua(&self, generator: &mut LuaGenerator) { generator.push_str("repeat"); self.block.to_lua(generator); generator.push_str("until"); self.condition.to_lua(generator); } } #[cfg(test)] mod test { use super::*; #[test] fn generate_empty_repeat_statement() { let output = RepeatStatement::new( Block::default(), Expression::False ).to_lua_string(); assert_eq!(output, "repeat until false"); } }