darklua_core/nodes/statements/
numeric_for.rs

1use crate::nodes::{Block, Expression, Token, TypedIdentifier};
2
3#[derive(Clone, Debug, PartialEq, Eq)]
4pub struct NumericForTokens {
5    pub r#for: Token,
6    pub equal: Token,
7    pub r#do: Token,
8    pub end: Token,
9    pub end_comma: Token,
10    pub step_comma: Option<Token>,
11}
12
13impl NumericForTokens {
14    super::impl_token_fns!(
15        target = [r#for, equal, r#do, end, end_comma]
16        iter = [step_comma]
17    );
18}
19
20#[derive(Clone, Debug, PartialEq, Eq)]
21pub struct NumericForStatement {
22    identifier: TypedIdentifier,
23    start: Expression,
24    end: Expression,
25    step: Option<Expression>,
26    block: Block,
27    tokens: Option<NumericForTokens>,
28}
29
30impl NumericForStatement {
31    pub fn new<
32        S: Into<TypedIdentifier>,
33        E1: Into<Expression>,
34        E2: Into<Expression>,
35        B: Into<Block>,
36    >(
37        identifier: S,
38        start: E1,
39        end: E2,
40        step: Option<Expression>,
41        block: B,
42    ) -> Self {
43        Self {
44            identifier: identifier.into(),
45            start: start.into(),
46            end: end.into(),
47            step,
48            block: block.into(),
49            tokens: None,
50        }
51    }
52
53    pub fn with_tokens(mut self, tokens: NumericForTokens) -> Self {
54        self.tokens = Some(tokens);
55        self
56    }
57
58    #[inline]
59    pub fn set_tokens(&mut self, tokens: NumericForTokens) {
60        self.tokens = Some(tokens);
61    }
62
63    #[inline]
64    pub fn get_tokens(&self) -> Option<&NumericForTokens> {
65        self.tokens.as_ref()
66    }
67
68    #[inline]
69    pub fn mutate_tokens(&mut self) -> Option<&mut NumericForTokens> {
70        self.tokens.as_mut()
71    }
72
73    #[inline]
74    pub fn get_block(&self) -> &Block {
75        &self.block
76    }
77
78    #[inline]
79    pub fn mutate_block(&mut self) -> &mut Block {
80        &mut self.block
81    }
82
83    #[inline]
84    pub fn get_start(&self) -> &Expression {
85        &self.start
86    }
87
88    #[inline]
89    pub fn mutate_start(&mut self) -> &mut Expression {
90        &mut self.start
91    }
92
93    #[inline]
94    pub fn get_end(&self) -> &Expression {
95        &self.end
96    }
97
98    #[inline]
99    pub fn mutate_end(&mut self) -> &mut Expression {
100        &mut self.end
101    }
102
103    #[inline]
104    pub fn get_step(&self) -> Option<&Expression> {
105        self.step.as_ref()
106    }
107
108    #[inline]
109    pub fn mutate_step(&mut self) -> &mut Option<Expression> {
110        &mut self.step
111    }
112
113    #[inline]
114    pub fn get_identifier(&self) -> &TypedIdentifier {
115        &self.identifier
116    }
117
118    #[inline]
119    pub fn mutate_identifier(&mut self) -> &mut TypedIdentifier {
120        &mut self.identifier
121    }
122
123    #[inline]
124    pub fn set_identifier<S: Into<TypedIdentifier>>(&mut self, identifier: S) {
125        self.identifier = identifier.into();
126    }
127
128    pub fn clear_types(&mut self) {
129        self.identifier.remove_type();
130    }
131
132    super::impl_token_fns!(target = [identifier] iter = [tokens]);
133}