darklua_core/nodes/statements/
repeat_statement.rs1use crate::nodes::{Block, Expression, Token};
2
3#[derive(Clone, Debug, PartialEq, Eq)]
4pub struct RepeatTokens {
5 pub repeat: Token,
6 pub until: Token,
7}
8
9impl RepeatTokens {
10 super::impl_token_fns!(target = [repeat, until]);
11}
12
13#[derive(Clone, Debug, PartialEq, Eq)]
14pub struct RepeatStatement {
15 block: Block,
16 condition: Expression,
17 tokens: Option<RepeatTokens>,
18}
19
20impl RepeatStatement {
21 pub fn new<B: Into<Block>, E: Into<Expression>>(block: B, condition: E) -> Self {
22 Self {
23 block: block.into(),
24 condition: condition.into(),
25 tokens: None,
26 }
27 }
28
29 #[inline]
30 pub fn get_block(&self) -> &Block {
31 &self.block
32 }
33
34 #[inline]
35 pub fn get_condition(&self) -> &Expression {
36 &self.condition
37 }
38
39 #[inline]
40 pub fn mutate_block(&mut self) -> &mut Block {
41 &mut self.block
42 }
43
44 #[inline]
45 pub fn mutate_condition(&mut self) -> &mut Expression {
46 &mut self.condition
47 }
48
49 #[inline]
50 pub(crate) fn mutate_block_and_condition(&mut self) -> (&mut Block, &mut Expression) {
51 (&mut self.block, &mut self.condition)
52 }
53
54 pub fn with_tokens(mut self, tokens: RepeatTokens) -> Self {
55 self.tokens = Some(tokens);
56 self
57 }
58
59 #[inline]
60 pub fn set_tokens(&mut self, tokens: RepeatTokens) {
61 self.tokens = Some(tokens);
62 }
63
64 #[inline]
65 pub fn get_tokens(&self) -> Option<&RepeatTokens> {
66 self.tokens.as_ref()
67 }
68
69 #[inline]
70 pub fn mutate_tokens(&mut self) -> Option<&mut RepeatTokens> {
71 self.tokens.as_mut()
72 }
73
74 super::impl_token_fns!(iter = [tokens]);
75}