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