1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5pub struct PowerShellRoot {
6 pub items: Vec<PowerShellItem>,
7}
8
9#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11pub enum PowerShellItem {
12 Statement(PowerShellStatement),
13 Function(PowerShellFunction),
14 Class(PowerShellClass),
15 Workflow(PowerShellWorkflow),
16}
17
18#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
20pub enum PowerShellStatement {
21 Expression(Box<PowerShellExpression>),
22 Assignment(PowerShellAssignment),
23 If(PowerShellIf),
24 While(PowerShellWhile),
25 For(PowerShellFor),
26 ForEach(PowerShellForEach),
27 Switch(PowerShellSwitch),
28 Try(PowerShellTry),
29 Return(PowerShellReturn),
30 Break(PowerShellBreak),
31 Continue(PowerShellContinue),
32 Exit(PowerShellExit),
33 Throw(PowerShellThrow),
34 Block(PowerShellBlock),
35}
36
37#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
39pub enum PowerShellExpression {
40 Literal(PowerShellLiteral),
41 Variable(PowerShellVariable),
42 Command(PowerShellCommand),
43 Pipeline(PowerShellPipeline),
44 Binary(PowerShellBinaryOp),
45 Unary(PowerShellUnaryOp),
46 Member(PowerShellMemberAccess),
47 Index(PowerShellIndexAccess),
48 Subexpression(Box<PowerShellExpression>),
49 Array(PowerShellArray),
50 Hashtable(PowerShellHashtable),
51 ScriptBlock(PowerShellScriptBlock),
52}
53
54#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
56pub enum PowerShellLiteral {
57 String(String),
58 Number(String),
59 Boolean(bool),
60 Null,
61}
62
63#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
65pub struct PowerShellVariable {
66 pub name: String,
67 pub scope: Option<String>,
68}
69
70#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
72pub struct PowerShellCommand {
73 pub name: String,
74 pub arguments: Vec<PowerShellArgument>,
75}
76
77#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
79pub enum PowerShellArgument {
80 Positional(Box<PowerShellExpression>),
81 Named(String, Box<PowerShellExpression>),
82 Switch(String),
83}
84
85#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
87pub struct PowerShellPipeline {
88 pub commands: Vec<PowerShellCommand>,
89}
90
91#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
93pub struct PowerShellBinaryOp {
94 pub left: Box<PowerShellExpression>,
95 pub operator: PowerShellBinaryOperator,
96 pub right: Box<PowerShellExpression>,
97}
98
99#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
101pub enum PowerShellBinaryOperator {
102 Add,
103 Subtract,
104 Multiply,
105 Divide,
106 Modulo,
107 Equal,
108 NotEqual,
109 Less,
110 LessEqual,
111 Greater,
112 GreaterEqual,
113 Like,
114 NotLike,
115 Match,
116 NotMatch,
117 Contains,
118 NotContains,
119 In,
120 NotIn,
121 And,
122 Or,
123 Xor,
124 BitwiseAnd,
125 BitwiseOr,
126 BitwiseXor,
127}
128
129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
131pub struct PowerShellUnaryOp {
132 pub operator: PowerShellUnaryOperator,
133 pub operand: Box<PowerShellExpression>,
134}
135
136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
138pub enum PowerShellUnaryOperator {
139 Plus,
140 Minus,
141 Not,
142 BitwiseNot,
143 Increment,
144 Decrement,
145}
146
147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
149pub struct PowerShellMemberAccess {
150 pub object: Box<PowerShellExpression>,
151 pub member: String,
152}
153
154#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
156pub struct PowerShellIndexAccess {
157 pub object: Box<PowerShellExpression>,
158 pub index: Box<PowerShellExpression>,
159}
160
161#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
163pub struct PowerShellArray {
164 pub elements: Vec<PowerShellExpression>,
165}
166
167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
169pub struct PowerShellHashtable {
170 pub entries: Vec<PowerShellHashtableEntry>,
171}
172
173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
175pub struct PowerShellHashtableEntry {
176 pub key: Box<PowerShellExpression>,
177 pub value: Box<PowerShellExpression>,
178}
179
180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
182pub struct PowerShellScriptBlock {
183 pub statements: Vec<PowerShellStatement>,
184}
185
186#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
188pub struct PowerShellAssignment {
189 pub target: Box<PowerShellExpression>,
190 pub operator: PowerShellAssignmentOperator,
191 pub value: Box<PowerShellExpression>,
192}
193
194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
196pub enum PowerShellAssignmentOperator {
197 Assign,
198 PlusAssign,
199 MinusAssign,
200 MultiplyAssign,
201 DivideAssign,
202 ModuloAssign,
203}
204
205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
207pub struct PowerShellIf {
208 pub condition: Box<PowerShellExpression>,
209 pub then_block: PowerShellScriptBlock,
210 pub elseif_blocks: Vec<PowerShellElseIf>,
211 pub else_block: Option<PowerShellScriptBlock>,
212}
213
214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
216pub struct PowerShellElseIf {
217 pub condition: Box<PowerShellExpression>,
218 pub block: PowerShellScriptBlock,
219}
220
221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
223pub struct PowerShellWhile {
224 pub condition: Box<PowerShellExpression>,
225 pub block: PowerShellScriptBlock,
226}
227
228#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
230pub struct PowerShellFor {
231 pub init: Option<Box<PowerShellExpression>>,
232 pub condition: Option<Box<PowerShellExpression>>,
233 pub update: Option<Box<PowerShellExpression>>,
234 pub block: PowerShellScriptBlock,
235}
236
237#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
239pub struct PowerShellForEach {
240 pub variable: PowerShellVariable,
241 pub collection: Box<PowerShellExpression>,
242 pub block: PowerShellScriptBlock,
243}
244
245#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
247pub struct PowerShellSwitch {
248 pub expression: Box<PowerShellExpression>,
249 pub cases: Vec<PowerShellSwitchCase>,
250 pub default: Option<PowerShellScriptBlock>,
251}
252
253#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
255pub struct PowerShellSwitchCase {
256 pub pattern: Box<PowerShellExpression>,
257 pub block: PowerShellScriptBlock,
258}
259
260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
262pub struct PowerShellTry {
263 pub block: PowerShellScriptBlock,
264 pub catch_blocks: Vec<PowerShellCatch>,
265 pub finally_block: Option<PowerShellScriptBlock>,
266}
267
268#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
270pub struct PowerShellCatch {
271 pub exception_type: Option<String>,
272 pub block: PowerShellScriptBlock,
273}
274
275#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
277pub struct PowerShellReturn {
278 pub value: Option<Box<PowerShellExpression>>,
279}
280
281#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
283pub struct PowerShellBreak {
284 pub label: Option<String>,
285}
286
287#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
289pub struct PowerShellContinue {
290 pub label: Option<String>,
291}
292
293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
295pub struct PowerShellExit {
296 pub code: Option<Box<PowerShellExpression>>,
297}
298
299#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
301pub struct PowerShellThrow {
302 pub exception: Option<Box<PowerShellExpression>>,
303}
304
305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
307pub struct PowerShellBlock {
308 pub statements: Vec<PowerShellStatement>,
309}
310
311#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
313pub struct PowerShellFunction {
314 pub name: String,
315 pub parameters: Vec<PowerShellParameter>,
316 pub body: PowerShellScriptBlock,
317 pub attributes: Vec<PowerShellAttribute>,
318}
319
320#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
322pub struct PowerShellParameter {
323 pub name: String,
324 pub param_type: Option<String>,
325 pub default_value: Option<Box<PowerShellExpression>>,
326 pub attributes: Vec<PowerShellAttribute>,
327}
328
329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
331pub struct PowerShellAttribute {
332 pub name: String,
333 pub arguments: Vec<PowerShellExpression>,
334}
335
336#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
338pub struct PowerShellClass {
339 pub name: String,
340 pub base_class: Option<String>,
341 pub members: Vec<PowerShellClassMember>,
342}
343
344#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
346pub enum PowerShellClassMember {
347 Property(PowerShellProperty),
348 Method(PowerShellMethod),
349 Constructor(PowerShellConstructor),
350}
351
352#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
354pub struct PowerShellProperty {
355 pub name: String,
356 pub property_type: Option<String>,
357 pub default_value: Option<Box<PowerShellExpression>>,
358 pub attributes: Vec<PowerShellAttribute>,
359}
360
361#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
363pub struct PowerShellMethod {
364 pub name: String,
365 pub parameters: Vec<PowerShellParameter>,
366 pub return_type: Option<String>,
367 pub body: PowerShellScriptBlock,
368 pub attributes: Vec<PowerShellAttribute>,
369}
370
371#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
373pub struct PowerShellConstructor {
374 pub parameters: Vec<PowerShellParameter>,
375 pub body: PowerShellScriptBlock,
376}
377
378#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
380pub struct PowerShellWorkflow {
381 pub name: String,
382 pub parameters: Vec<PowerShellParameter>,
383 pub body: PowerShellScriptBlock,
384}