darklua_core/nodes/statements/
repeat_statement.rs1use crate::nodes::{Block, Expression, Token};
2
3#[derive(Clone, Debug, PartialEq, Eq)]
5pub struct RepeatTokens {
6 pub repeat: Token,
7 pub until: Token,
8}
9
10impl RepeatTokens {
11 super::impl_token_fns!(target = [repeat, until]);
12}
13
14#[derive(Clone, Debug, PartialEq, Eq)]
16pub struct RepeatStatement {
17 block: Block,
18 condition: Expression,
19 tokens: Option<RepeatTokens>,
20}
21
22impl RepeatStatement {
23 pub fn new<B: Into<Block>, E: Into<Expression>>(block: B, condition: E) -> Self {
25 Self {
26 block: block.into(),
27 condition: condition.into(),
28 tokens: None,
29 }
30 }
31
32 #[inline]
34 pub fn get_block(&self) -> &Block {
35 &self.block
36 }
37
38 #[inline]
40 pub fn get_condition(&self) -> &Expression {
41 &self.condition
42 }
43
44 #[inline]
46 pub fn mutate_block(&mut self) -> &mut Block {
47 &mut self.block
48 }
49
50 #[inline]
52 pub fn mutate_condition(&mut self) -> &mut Expression {
53 &mut self.condition
54 }
55
56 #[inline]
58 pub(crate) fn mutate_block_and_condition(&mut self) -> (&mut Block, &mut Expression) {
59 (&mut self.block, &mut self.condition)
60 }
61
62 pub fn with_tokens(mut self, tokens: RepeatTokens) -> Self {
64 self.tokens = Some(tokens);
65 self
66 }
67
68 #[inline]
70 pub fn set_tokens(&mut self, tokens: RepeatTokens) {
71 self.tokens = Some(tokens);
72 }
73
74 #[inline]
76 pub fn get_tokens(&self) -> Option<&RepeatTokens> {
77 self.tokens.as_ref()
78 }
79
80 #[inline]
82 pub fn mutate_tokens(&mut self) -> Option<&mut RepeatTokens> {
83 self.tokens.as_mut()
84 }
85
86 pub fn mutate_first_token(&mut self) -> &mut Token {
88 if self.tokens.is_none() {
89 self.tokens = Some(RepeatTokens {
90 repeat: Token::from_content("repeat"),
91 until: Token::from_content("until"),
92 });
93 }
94 &mut self.tokens.as_mut().unwrap().repeat
95 }
96
97 pub fn mutate_last_token(&mut self) -> &mut Token {
100 self.condition.mutate_last_token()
101 }
102
103 super::impl_token_fns!(iter = [tokens]);
104}