1use oak_core::{ElementType, Token, TokenType, UniversalElementRole, UniversalTokenRole};
2use serde::{Deserialize, Serialize};
3
4pub type PowerShellToken = Token<PowerShellSyntaxKind>;
5
6#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Hash)]
7pub enum PowerShellSyntaxKind {
8 Whitespace,
10 Newline,
11 Comment,
12
13 Begin,
15 Break,
16 Catch,
17 Class,
18 Continue,
19 Data,
20 Define,
21 Do,
22 DynamicParam,
23 Else,
24 ElseIf,
25 End,
26 Exit,
27 Filter,
28 Finally,
29 For,
30 ForEach,
31 From,
32 Function,
33 If,
34 In,
35 Param,
36 Process,
37 Return,
38 Switch,
39 Throw,
40 Trap,
41 Try,
42 Until,
43 Using,
44 Var,
45 While,
46 Workflow,
47
48 Plus,
50 Minus,
51 Multiply,
52 Divide,
53 Modulo,
54 Equal,
55 NotEqual,
56 GreaterThan,
57 LessThan,
58 GreaterEqual,
59 LessEqual,
60 Like,
61 NotLike,
62 Match,
63 NotMatch,
64 Contains,
65 NotContains,
66 NotIn,
67 Replace,
68 Split,
69 Join,
70 Is,
71 IsNot,
72 As,
73 And,
74 Or,
75 Xor,
76 Not,
77 Band,
78 Bor,
79 Bxor,
80 Bnot,
81 Shl,
82 Shr,
83
84 LeftParen,
86 RightParen,
87 LeftBrace,
88 RightBrace,
89 LeftBracket,
90 RightBracket,
91 Semicolon,
92 Comma,
93 Dot,
94 DotDot,
95 Colon,
96 DoubleColon,
97 Pipe,
98 Ampersand,
99 At,
100 Dollar,
101 Question,
102 Exclamation,
103 Backtick,
104 SingleQuote,
105 DoubleQuote,
106
107 StringLiteral,
109 NumberLiteral,
110 BooleanLiteral,
111 NullLiteral,
112 ArrayLiteral,
113 HashLiteral,
114
115 Identifier,
117 Variable,
118 AutomaticVariable,
119 PreferenceVariable,
120
121 Root,
123 FunctionDef,
124 ClassDef,
125 IfStatement,
126 ForStatement,
127 ForEachStatement,
128 WhileStatement,
129 DoWhileStatement,
130 SwitchStatement,
131 TryStatement,
132 CatchBlock,
133 FinallyBlock,
134 ParamBlock,
135 ProcessBlock,
136 BeginBlock,
137 EndBlock,
138 ExpressionStatement,
139 Pipeline,
140 Command,
141 CommandParameter,
142 CommandArgument,
143 Error,
144 Eof,
145}
146
147impl TokenType for PowerShellSyntaxKind {
148 const END_OF_STREAM: Self = Self::Eof;
149 type Role = UniversalTokenRole;
150
151 fn role(&self) -> Self::Role {
152 match self {
153 Self::Whitespace | Self::Newline => UniversalTokenRole::Whitespace,
154 Self::Comment => UniversalTokenRole::Comment,
155 Self::Eof => UniversalTokenRole::Eof,
156 _ => UniversalTokenRole::None,
157 }
158 }
159
160 fn is_comment(&self) -> bool {
161 matches!(self, Self::Comment)
162 }
163
164 fn is_whitespace(&self) -> bool {
165 matches!(self, Self::Whitespace | Self::Newline)
166 }
167}
168
169impl ElementType for PowerShellSyntaxKind {
170 type Role = UniversalElementRole;
171
172 fn role(&self) -> Self::Role {
173 match self {
174 Self::Error => UniversalElementRole::Error,
175 Self::Root => UniversalElementRole::Root,
176 Self::FunctionDef | Self::ClassDef | Self::IfStatement => UniversalElementRole::Detail,
177 _ => UniversalElementRole::None,
178 }
179 }
180}