Skip to main content

oak_powershell/parser/
element_type.rs

1use oak_core::{ElementType, UniversalElementRole};
2
3/// Element types for the PowerShell language.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6#[repr(u8)]
7pub enum PowerShellElementType {
8    /// Whitespace.
9    Whitespace,
10    /// A newline.
11    Newline,
12    /// A comment.
13    Comment,
14
15    /// `begin` keyword.
16    Begin,
17    /// `break` keyword.
18    Break,
19    /// `catch` keyword.
20    Catch,
21    /// `class` keyword.
22    Class,
23    /// `continue` keyword.
24    Continue,
25    /// `data` keyword.
26    Data,
27    /// `define` keyword.
28    Define,
29    /// `do` keyword.
30    Do,
31    /// `dynamicparam` keyword.
32    DynamicParam,
33    /// `else` keyword.
34    Else,
35    /// `elseif` keyword.
36    ElseIf,
37    /// `end` keyword.
38    End,
39    /// `exit` keyword.
40    Exit,
41    /// `filter` keyword.
42    Filter,
43    /// `finally` keyword.
44    Finally,
45    /// `for` keyword.
46    For,
47    /// `foreach` keyword.
48    ForEach,
49    /// `from` keyword.
50    From,
51    /// `function` keyword.
52    Function,
53    /// `if` keyword.
54    If,
55    /// `in` keyword.
56    In,
57    /// `param` keyword.
58    Param,
59    /// `process` keyword.
60    Process,
61    /// `return` keyword.
62    Return,
63    /// `switch` keyword.
64    Switch,
65    /// `throw` keyword.
66    Throw,
67    /// `trap` keyword.
68    Trap,
69    /// `try` keyword.
70    Try,
71    /// `until` keyword.
72    Until,
73    /// `using` keyword.
74    Using,
75    /// `var` keyword.
76    Var,
77    /// `while` keyword.
78    While,
79    /// `workflow` keyword.
80    Workflow,
81
82    /// `+`.
83    Plus,
84    /// `-`.
85    Minus,
86    /// `*`.
87    Multiply,
88    /// `/`.
89    Divide,
90    /// `%`.
91    Modulo,
92    /// `=`.
93    Equal,
94    /// `!=`.
95    NotEqual,
96    /// `>`.
97    GreaterThan,
98    /// `<`.
99    LessThan,
100    /// `>=`.
101    GreaterEqual,
102    /// `<=`.
103    LessEqual,
104    /// `-like`.
105    Like,
106    /// `-notlike`.
107    NotLike,
108    /// `-match`.
109    Match,
110    /// `-notmatch`.
111    NotMatch,
112    /// `-contains`.
113    Contains,
114    /// `-notcontains`.
115    NotContains,
116    /// `-notin`.
117    NotIn,
118    /// `-replace`.
119    Replace,
120    /// `-split`.
121    Split,
122    /// `-join`.
123    Join,
124    /// `-is`.
125    Is,
126    /// `-isnot`.
127    IsNot,
128    /// `-as`.
129    As,
130    /// `-and`.
131    And,
132    /// `-or`.
133    Or,
134    /// `-xor`.
135    Xor,
136    /// `-not`.
137    Not,
138    /// `-band`.
139    Band,
140    /// `-bor`.
141    Bor,
142    /// `-bxor`.
143    Bxor,
144    /// `-bnot`.
145    Bnot,
146    /// `-shl`.
147    Shl,
148    /// `-shr`.
149    Shr,
150
151    /// `(`.
152    LeftParen,
153    /// `)`.
154    RightParen,
155    /// `{`.
156    LeftBrace,
157    /// `}`.
158    RightBrace,
159    /// `[`.
160    LeftBracket,
161    /// `]`.
162    RightBracket,
163    /// `;`.
164    Semicolon,
165    /// `,`.
166    Comma,
167    /// `.`.
168    Dot,
169    /// `..`.
170    DotDot,
171    /// `:`.
172    Colon,
173    /// `::`.
174    DoubleColon,
175    /// `|`.
176    Pipe,
177    /// `&`.
178    Ampersand,
179    /// `@`.
180    At,
181    /// `$`.
182    Dollar,
183    /// `?`.
184    Question,
185    /// `!`.
186    Exclamation,
187    /// `` ` ``.
188    Backtick,
189    /// `'`.
190    SingleQuote,
191    /// `"`.
192    DoubleQuote,
193
194    /// A string literal.
195    StringLiteral,
196    /// A number literal.
197    NumberLiteral,
198    /// A boolean literal.
199    BooleanLiteral,
200    /// A null literal.
201    NullLiteral,
202    /// An array literal.
203    ArrayLiteral,
204    /// A hash literal.
205    HashLiteral,
206
207    /// An identifier.
208    Identifier,
209    /// A variable.
210    Variable,
211    /// An automatic variable.
212    AutomaticVariable,
213    /// A preference variable.
214    PreferenceVariable,
215
216    /// Root node of the AST.
217    Root,
218    /// A function definition.
219    FunctionDef,
220    /// A class definition.
221    ClassDef,
222    /// An `if` statement.
223    IfStatement,
224    /// A `for` statement.
225    ForStatement,
226    /// A `foreach` statement.
227    ForEachStatement,
228    /// A `while` statement.
229    WhileStatement,
230    /// A `do-while` statement.
231    DoWhileStatement,
232    /// A `switch` statement.
233    SwitchStatement,
234    /// A `try` statement.
235    TryStatement,
236    /// A `catch` block.
237    CatchBlock,
238    /// A `finally` block.
239    FinallyBlock,
240    /// A `param` block.
241    ParamBlock,
242    /// A `process` block.
243    ProcessBlock,
244    /// A `begin` block.
245    BeginBlock,
246    /// An `end` block.
247    EndBlock,
248    /// An expression statement.
249    ExpressionStatement,
250    /// A pipeline.
251    Pipeline,
252    /// A command.
253    Command,
254    /// A command parameter.
255    CommandParameter,
256    /// A command argument.
257    CommandArgument,
258    /// An error token.
259    Error,
260    /// End of stream.
261    Eof,
262}
263
264impl ElementType for PowerShellElementType {
265    type Role = UniversalElementRole;
266
267    fn role(&self) -> Self::Role {
268        match self {
269            Self::Root => UniversalElementRole::Root,
270            Self::Error => UniversalElementRole::Error,
271            _ => UniversalElementRole::None,
272        }
273    }
274}
275
276impl From<crate::lexer::token_type::PowerShellTokenType> for PowerShellElementType {
277    fn from(token: crate::lexer::token_type::PowerShellTokenType) -> Self {
278        unsafe { std::mem::transmute(token) }
279    }
280}