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