darklua_core/nodes/statements/
mod.rs1mod assign;
2mod compound_assign;
3mod do_statement;
4mod function;
5mod generic_for;
6mod if_statement;
7mod last_statement;
8mod local_assign;
9mod local_function;
10mod numeric_for;
11mod repeat_statement;
12mod type_declaration;
13mod type_function;
14mod while_statement;
15
16pub use assign::*;
17pub use compound_assign::*;
18pub use do_statement::*;
19pub use function::*;
20pub use generic_for::*;
21pub use if_statement::*;
22pub use last_statement::*;
23pub use local_assign::*;
24pub use local_function::*;
25pub use numeric_for::*;
26pub use repeat_statement::*;
27pub use type_declaration::*;
28pub use type_function::*;
29pub use while_statement::*;
30
31use crate::nodes::FunctionCall;
32
33use super::impl_token_fns;
34
35#[derive(Clone, Debug, PartialEq, Eq)]
37pub enum Statement {
38 Assign(AssignStatement),
40 Do(DoStatement),
42 Call(FunctionCall),
44 CompoundAssign(CompoundAssignStatement),
46 Function(Box<FunctionStatement>),
48 GenericFor(GenericForStatement),
50 If(IfStatement),
52 LocalAssign(LocalAssignStatement),
54 LocalFunction(Box<LocalFunctionStatement>),
56 NumericFor(Box<NumericForStatement>),
58 Repeat(RepeatStatement),
60 While(WhileStatement),
62 TypeDeclaration(TypeDeclarationStatement),
64 TypeFunction(Box<TypeFunctionStatement>),
66}
67
68impl Statement {
69 pub fn mutate_first_token(&mut self) -> &mut crate::nodes::Token {
71 match self {
72 Self::Assign(assign) => assign.mutate_first_token(),
73 Self::Do(do_stmt) => do_stmt.mutate_first_token(),
74 Self::Call(call) => call.mutate_first_token(),
75 Self::CompoundAssign(compound) => compound.mutate_first_token(),
76 Self::Function(function) => function.mutate_first_token(),
77 Self::GenericFor(generic_for) => generic_for.mutate_first_token(),
78 Self::If(if_stmt) => if_stmt.mutate_first_token(),
79 Self::LocalAssign(local_assign) => local_assign.mutate_first_token(),
80 Self::LocalFunction(local_function) => local_function.mutate_first_token(),
81 Self::NumericFor(numeric_for) => numeric_for.mutate_first_token(),
82 Self::Repeat(repeat_stmt) => repeat_stmt.mutate_first_token(),
83 Self::While(while_stmt) => while_stmt.mutate_first_token(),
84 Self::TypeDeclaration(type_decl) => type_decl.mutate_first_token(),
85 Self::TypeFunction(type_function) => type_function.mutate_first_token(),
86 }
87 }
88
89 pub fn mutate_last_token(&mut self) -> &mut crate::nodes::Token {
92 match self {
93 Self::Assign(assign) => assign.mutate_last_token(),
94 Self::Do(do_stmt) => do_stmt.mutate_last_token(),
95 Self::Call(call) => call.mutate_last_token(),
96 Self::CompoundAssign(compound) => compound.mutate_last_token(),
97 Self::Function(function) => function.mutate_last_token(),
98 Self::GenericFor(generic_for) => generic_for.mutate_last_token(),
99 Self::If(if_stmt) => if_stmt.mutate_last_token(),
100 Self::LocalAssign(local_assign) => local_assign.mutate_last_token(),
101 Self::LocalFunction(local_function) => local_function.mutate_last_token(),
102 Self::NumericFor(numeric_for) => numeric_for.mutate_last_token(),
103 Self::Repeat(repeat_stmt) => repeat_stmt.mutate_last_token(),
104 Self::While(while_stmt) => while_stmt.mutate_last_token(),
105 Self::TypeDeclaration(type_decl) => type_decl.mutate_last_token(),
106 Self::TypeFunction(type_function) => type_function.mutate_last_token(),
107 }
108 }
109}
110
111impl From<AssignStatement> for Statement {
112 fn from(assign: AssignStatement) -> Statement {
113 Statement::Assign(assign)
114 }
115}
116
117impl From<DoStatement> for Statement {
118 fn from(do_statement: DoStatement) -> Statement {
119 Statement::Do(do_statement)
120 }
121}
122
123impl From<CompoundAssignStatement> for Statement {
124 fn from(statement: CompoundAssignStatement) -> Statement {
125 Statement::CompoundAssign(statement)
126 }
127}
128
129impl From<FunctionCall> for Statement {
130 fn from(call: FunctionCall) -> Statement {
131 Statement::Call(call)
132 }
133}
134
135impl From<FunctionStatement> for Statement {
136 fn from(function: FunctionStatement) -> Statement {
137 Statement::Function(Box::new(function))
138 }
139}
140
141impl From<GenericForStatement> for Statement {
142 fn from(generic_for: GenericForStatement) -> Statement {
143 Statement::GenericFor(generic_for)
144 }
145}
146
147impl From<IfStatement> for Statement {
148 fn from(if_statement: IfStatement) -> Statement {
149 Statement::If(if_statement)
150 }
151}
152
153impl From<LocalAssignStatement> for Statement {
154 fn from(assign: LocalAssignStatement) -> Statement {
155 Statement::LocalAssign(assign)
156 }
157}
158
159impl From<LocalFunctionStatement> for Statement {
160 fn from(function: LocalFunctionStatement) -> Statement {
161 Statement::LocalFunction(Box::new(function))
162 }
163}
164
165impl From<NumericForStatement> for Statement {
166 fn from(numeric_for: NumericForStatement) -> Statement {
167 Statement::NumericFor(numeric_for.into())
168 }
169}
170
171impl From<RepeatStatement> for Statement {
172 fn from(repeat_statement: RepeatStatement) -> Statement {
173 Statement::Repeat(repeat_statement)
174 }
175}
176
177impl From<WhileStatement> for Statement {
178 fn from(while_statement: WhileStatement) -> Statement {
179 Statement::While(while_statement)
180 }
181}
182
183impl From<TypeDeclarationStatement> for Statement {
184 fn from(type_declaration: TypeDeclarationStatement) -> Statement {
185 Statement::TypeDeclaration(type_declaration)
186 }
187}
188
189impl From<TypeFunctionStatement> for Statement {
190 fn from(type_function: TypeFunctionStatement) -> Statement {
191 Statement::TypeFunction(Box::new(type_function))
192 }
193}