1#[repr(u8)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
16pub enum SyntaxKind {
17 Tombstone,
19 SourceFile,
20 Error,
21 Attr,
22 Visibility,
23 Name,
24 TokenTree,
25 Abi,
26
27 Fn,
29 ParamList,
30 Param,
31 SelfParam,
32 RetType,
33 WhereClause,
34 WherePred,
35 GenericParamList,
36 LifetimeParam,
37 TypeParam,
38 ConstParam,
39 Impl,
40 Trait,
41 Struct,
42 Enum,
43 Union,
44 TypeAlias,
45 Const,
46 Static,
47 Module,
48 Use,
49 ExternCrate,
50 ExternBlock,
51 MacroRules,
52 MacroCall,
53 ItemList,
54
55 PathType,
57 RefType,
58 PtrType,
59 TupleType,
60 ArrayType,
61 SliceType,
62 FnPtrType,
63 ImplTraitType,
64 DynTraitType,
65 NeverType,
66 InferType,
67 ParenType,
68 TypeBoundList,
69 TypeBound,
70 ForBinder,
71 Path,
72 PathSegment,
73 GenericArgList,
74 TypeArg,
75 LifetimeArg,
76 ConstArg,
77 AssocTypeArg,
78 Lifetime,
79
80 IdentPat,
82 WildcardPat,
83 RefPat,
84 TuplePat,
85 TupleStructPat,
86 RecordPat,
87 RecordPatField,
88 PathPat,
89 LiteralPat,
90 RangePat,
91 OrPat,
92 SlicePat,
93 RestPat,
94 BoxPat,
95 MacroPat,
96 ParenPat,
97 ConstBlockPat,
98
99 Literal,
101 PathExpr,
102 CallExpr,
103 ArgList,
104 MethodCallExpr,
105 FieldExpr,
106 IndexExpr,
107 TryExpr,
108 AwaitExpr,
109 PrefixExpr,
110 RefExpr,
111 BinExpr,
112 CastExpr,
113 RangeExpr,
114 ParenExpr,
115 TupleExpr,
116 ArrayExpr,
117 BlockExpr,
118 IfExpr,
119 MatchExpr,
120 MatchArmList,
121 MatchArm,
122 MatchGuard,
123 LoopExpr,
124 WhileExpr,
125 ForExpr,
126 ReturnExpr,
127 BreakExpr,
128 ContinueExpr,
129 ClosureExpr,
130 RecordExpr,
131 RecordExprFieldList,
132 RecordExprField,
133 LetExpr,
134 Label,
135 UnderscoreExpr,
136 YieldExpr,
137 BecomeExpr,
138
139 LetStmt,
141 LetElse,
142 ExprStmt,
143}
144
145const F_EXPR: u8 = 1 << 0;
146const F_PAT: u8 = 1 << 1;
147const F_TYPE: u8 = 1 << 2;
148const F_ITEM: u8 = 1 << 3;
149const F_BLOCK_LIKE: u8 = 1 << 4;
150const F_CF_CUT: u8 = 1 << 5;
151const F_SEMA_SKIP: u8 = 1 << 6;
152
153const KIND_FLAGS: [u8; 256] = {
154 use SyntaxKind as K;
155 let mut t = [0u8; 256];
156
157 let mut i = K::Literal as usize;
159 while i <= K::BecomeExpr as usize {
160 t[i] |= F_EXPR;
161 i += 1;
162 }
163 t[K::ArgList as usize] &= !F_EXPR;
164 t[K::MatchArmList as usize] &= !F_EXPR;
165 t[K::MatchArm as usize] &= !F_EXPR;
166 t[K::MatchGuard as usize] &= !F_EXPR;
167 t[K::RecordExprFieldList as usize] &= !F_EXPR;
168 t[K::RecordExprField as usize] &= !F_EXPR;
169 t[K::Label as usize] &= !F_EXPR;
170
171 let mut p = K::IdentPat as usize;
173 while p <= K::ConstBlockPat as usize {
174 t[p] |= F_PAT;
175 p += 1;
176 }
177 t[K::RecordPatField as usize] &= !F_PAT;
178
179 let mut ty = K::PathType as usize;
181 while ty <= K::ParenType as usize {
182 t[ty] |= F_TYPE | F_CF_CUT | F_SEMA_SKIP;
183 ty += 1;
184 }
185
186 t[K::Fn as usize] |= F_ITEM | F_CF_CUT | F_SEMA_SKIP;
188 let mut it = K::Impl as usize;
189 while it <= K::MacroRules as usize {
190 t[it] |= F_ITEM | F_CF_CUT | F_SEMA_SKIP;
191 it += 1;
192 }
193
194 t[K::BlockExpr as usize] |= F_BLOCK_LIKE;
196 t[K::IfExpr as usize] |= F_BLOCK_LIKE;
197 t[K::MatchExpr as usize] |= F_BLOCK_LIKE;
198 t[K::LoopExpr as usize] |= F_BLOCK_LIKE;
199 t[K::WhileExpr as usize] |= F_BLOCK_LIKE;
200 t[K::ForExpr as usize] |= F_BLOCK_LIKE;
201
202 t[K::ClosureExpr as usize] |= F_CF_CUT;
204 t[K::TokenTree as usize] |= F_CF_CUT | F_SEMA_SKIP;
205 t[K::Attr as usize] |= F_CF_CUT | F_SEMA_SKIP;
206 t[K::ConstBlockPat as usize] |= F_CF_CUT | F_SEMA_SKIP;
207 t[K::Path as usize] |= F_CF_CUT | F_SEMA_SKIP;
208 t[K::ParamList as usize] |= F_CF_CUT | F_SEMA_SKIP;
209 t[K::GenericParamList as usize] |= F_CF_CUT | F_SEMA_SKIP;
210 t[K::WhereClause as usize] |= F_CF_CUT | F_SEMA_SKIP;
211
212 t[K::Name as usize] |= F_SEMA_SKIP;
214 t[K::Lifetime as usize] |= F_SEMA_SKIP;
215 t[K::Label as usize] |= F_SEMA_SKIP;
216 t[K::Visibility as usize] |= F_SEMA_SKIP;
217 t[K::RetType as usize] |= F_SEMA_SKIP;
218 t[K::GenericArgList as usize] |= F_SEMA_SKIP;
219
220 t
221};
222
223impl SyntaxKind {
224 #[inline(always)]
226 pub const fn is_expr(self) -> bool {
227 (KIND_FLAGS[self as usize] & F_EXPR) != 0
228 }
229
230 #[inline(always)]
232 pub const fn is_pat(self) -> bool {
233 (KIND_FLAGS[self as usize] & F_PAT) != 0
234 }
235
236 #[inline(always)]
238 pub const fn is_type(self) -> bool {
239 (KIND_FLAGS[self as usize] & F_TYPE) != 0
240 }
241
242 #[inline(always)]
244 pub const fn is_item(self) -> bool {
245 (KIND_FLAGS[self as usize] & F_ITEM) != 0
246 }
247
248 #[inline(always)]
250 pub const fn is_block_like(self) -> bool {
251 (KIND_FLAGS[self as usize] & F_BLOCK_LIKE) != 0
252 }
253
254 #[inline(always)]
255 pub(crate) const fn is_cf_cutoff(self) -> bool {
256 (KIND_FLAGS[self as usize] & F_CF_CUT) != 0
257 }
258
259 #[inline(always)]
260 pub(crate) const fn is_sema_skip(self) -> bool {
261 (KIND_FLAGS[self as usize] & F_SEMA_SKIP) != 0
262 }
263}