aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-09 09:47:05 +0100
committerAleksey Kladov <[email protected]>2020-04-09 10:04:18 +0100
commit8f01e62bb962fbe282344125f6ace54326efcaa3 (patch)
treee3982d1b2adace537e621ece4706603e657e18de
parent68196ccc10c60de52bb771d295879456f73ede95 (diff)
Scale back the traits
-rw-r--r--crates/ra_syntax/src/ast.rs108
-rw-r--r--crates/ra_syntax/src/ast/generated.rs3030
-rw-r--r--xtask/src/codegen/gen_syntax.rs168
3 files changed, 3061 insertions, 245 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index 1ac0201b8..ab0f44dd2 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -11,10 +11,7 @@ pub mod make;
11use std::marker::PhantomData; 11use std::marker::PhantomData;
12 12
13use crate::{ 13use crate::{
14 syntax_node::{ 14 syntax_node::{SyntaxNode, SyntaxNodeChildren, SyntaxToken},
15 NodeOrToken, SyntaxElement, SyntaxElementChildren, SyntaxNode, SyntaxNodeChildren,
16 SyntaxToken,
17 },
18 SmolStr, SyntaxKind, 15 SmolStr, SyntaxKind,
19}; 16};
20 17
@@ -33,24 +30,16 @@ pub use self::{
33/// conversion itself has zero runtime cost: ast and syntax nodes have exactly 30/// conversion itself has zero runtime cost: ast and syntax nodes have exactly
34/// the same representation: a pointer to the tree root and a pointer to the 31/// the same representation: a pointer to the tree root and a pointer to the
35/// node itself. 32/// node itself.
36pub trait AstNode: AstElement { 33pub trait AstNode {
37 fn can_cast(kind: SyntaxKind) -> bool 34 fn can_cast(kind: SyntaxKind) -> bool
38 where 35 where
39 Self: Sized; 36 Self: Sized;
40 37
41 fn cast_or_return(syntax: SyntaxNode) -> Result<Self, SyntaxNode>
42 where
43 Self: Sized;
44
45 fn cast(syntax: SyntaxNode) -> Option<Self> 38 fn cast(syntax: SyntaxNode) -> Option<Self>
46 where 39 where
47 Self: Sized, 40 Self: Sized;
48 {
49 <Self as AstNode>::cast_or_return(syntax).ok()
50 }
51 41
52 fn syntax(&self) -> &SyntaxNode; 42 fn syntax(&self) -> &SyntaxNode;
53 fn into_syntax(self) -> SyntaxNode;
54} 43}
55 44
56#[test] 45#[test]
@@ -59,51 +48,22 @@ fn assert_ast_is_object_safe() {
59} 48}
60 49
61/// Like `AstNode`, but wraps tokens rather than interior nodes. 50/// Like `AstNode`, but wraps tokens rather than interior nodes.
62pub trait AstToken: AstElement { 51pub trait AstToken {
63 fn can_cast(token: SyntaxKind) -> bool 52 fn can_cast(token: SyntaxKind) -> bool
64 where 53 where
65 Self: Sized; 54 Self: Sized;
66 55
67 fn cast_or_return(syntax: SyntaxToken) -> Result<Self, SyntaxToken>
68 where
69 Self: Sized;
70
71 fn cast(syntax: SyntaxToken) -> Option<Self> 56 fn cast(syntax: SyntaxToken) -> Option<Self>
72 where 57 where
73 Self: Sized, 58 Self: Sized;
74 {
75 <Self as AstToken>::cast_or_return(syntax).ok()
76 }
77 59
78 fn syntax(&self) -> &SyntaxToken; 60 fn syntax(&self) -> &SyntaxToken;
79 fn into_syntax(self) -> SyntaxToken;
80 61
81 fn text(&self) -> &SmolStr { 62 fn text(&self) -> &SmolStr {
82 self.syntax().text() 63 self.syntax().text()
83 } 64 }
84} 65}
85 66
86/// Like `AstNode`, but wraps either nodes or tokens rather than interior nodes.
87pub trait AstElement: std::fmt::Display {
88 fn can_cast_element(kind: SyntaxKind) -> bool
89 where
90 Self: Sized;
91
92 fn cast_or_return_element(syntax: SyntaxElement) -> Result<Self, SyntaxElement>
93 where
94 Self: Sized;
95
96 fn cast_element(syntax: SyntaxElement) -> Option<Self>
97 where
98 Self: Sized,
99 {
100 <Self as AstElement>::cast_or_return_element(syntax).ok()
101 }
102
103 fn syntax_element(&self) -> NodeOrToken<&SyntaxNode, &SyntaxToken>;
104 fn into_syntax_element(self) -> SyntaxElement;
105}
106
107/// An iterator over `SyntaxNode` children of a particular AST type. 67/// An iterator over `SyntaxNode` children of a particular AST type.
108#[derive(Debug, Clone)] 68#[derive(Debug, Clone)]
109pub struct AstChildren<N> { 69pub struct AstChildren<N> {
@@ -132,64 +92,6 @@ fn children<P: AstNode + ?Sized, C: AstNode>(parent: &P) -> AstChildren<C> {
132 AstChildren::new(parent.syntax()) 92 AstChildren::new(parent.syntax())
133} 93}
134 94
135/// An iterator over `SyntaxToken` children of a particular AST type.
136#[derive(Debug, Clone)]
137pub struct AstChildTokens<N> {
138 inner: SyntaxElementChildren,
139 ph: PhantomData<N>,
140}
141
142impl<N> AstChildTokens<N> {
143 fn new(parent: &SyntaxNode) -> Self {
144 AstChildTokens { inner: parent.children_with_tokens(), ph: PhantomData }
145 }
146}
147
148impl<N: AstToken> Iterator for AstChildTokens<N> {
149 type Item = N;
150 fn next(&mut self) -> Option<N> {
151 self.inner.by_ref().filter_map(|x| x.into_token()).find_map(N::cast)
152 }
153}
154
155fn child_token_opt<P: AstNode + ?Sized, C: AstToken>(parent: &P) -> Option<C> {
156 child_tokens(parent).next()
157}
158
159fn child_tokens<P: AstNode + ?Sized, C: AstToken>(parent: &P) -> AstChildTokens<C> {
160 AstChildTokens::new(parent.syntax())
161}
162
163/// An iterator over `SyntaxNode` children of a particular AST type.
164#[derive(Debug, Clone)]
165pub struct AstChildElements<N> {
166 inner: SyntaxElementChildren,
167 ph: PhantomData<N>,
168}
169
170impl<N> AstChildElements<N> {
171 fn new(parent: &SyntaxNode) -> Self {
172 AstChildElements { inner: parent.children_with_tokens(), ph: PhantomData }
173 }
174}
175
176impl<N: AstElement> Iterator for AstChildElements<N> {
177 type Item = N;
178 fn next(&mut self) -> Option<N> {
179 self.inner.by_ref().find_map(N::cast_element)
180 }
181}
182
183#[allow(dead_code)]
184fn child_element_opt<P: AstNode + ?Sized, C: AstElement>(parent: &P) -> Option<C> {
185 child_elements(parent).next()
186}
187
188#[allow(dead_code)]
189fn child_elements<P: AstNode + ?Sized, C: AstElement>(parent: &P) -> AstChildElements<C> {
190 AstChildElements::new(parent.syntax())
191}
192
193#[test] 95#[test]
194fn test_doc_comment_none() { 96fn test_doc_comment_none() {
195 let file = SourceFile::parse( 97 let file = SourceFile::parse(
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index 0c339b987..385fddc89 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -1,11 +1,3037 @@
1//! Generated file, do not edit by hand, see `xtask/src/codegen` 1//! Generated file, do not edit by hand, see `xtask/src/codegen`
2 2
3#[allow(unused_imports)]
3use crate::{ 4use crate::{
4 ast::{self, AstChildren, AstNode}, 5 ast::{self, AstChildren, AstNode, AstToken},
6 NodeOrToken, SyntaxElement,
5 SyntaxKind::{self, *}, 7 SyntaxKind::{self, *},
6 SyntaxNode, 8 SyntaxNode, SyntaxToken,
7}; 9};
8#[derive(Debug, Clone, PartialEq, Eq, Hash)] 10#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11pub struct Semi {
12 pub(crate) syntax: SyntaxToken,
13}
14impl std::fmt::Display for Semi {
15 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
16 std::fmt::Display::fmt(&self.syntax, f)
17 }
18}
19impl AstToken for Semi {
20 fn can_cast(kind: SyntaxKind) -> bool {
21 match kind {
22 SEMI => true,
23 _ => false,
24 }
25 }
26 fn cast(syntax: SyntaxToken) -> Option<Self> {
27 if Self::can_cast(syntax.kind()) {
28 Some(Self { syntax })
29 } else {
30 None
31 }
32 }
33 fn syntax(&self) -> &SyntaxToken {
34 &self.syntax
35 }
36}
37#[derive(Debug, Clone, PartialEq, Eq, Hash)]
38pub struct Comma {
39 pub(crate) syntax: SyntaxToken,
40}
41impl std::fmt::Display for Comma {
42 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
43 std::fmt::Display::fmt(&self.syntax, f)
44 }
45}
46impl AstToken for Comma {
47 fn can_cast(kind: SyntaxKind) -> bool {
48 match kind {
49 COMMA => true,
50 _ => false,
51 }
52 }
53 fn cast(syntax: SyntaxToken) -> Option<Self> {
54 if Self::can_cast(syntax.kind()) {
55 Some(Self { syntax })
56 } else {
57 None
58 }
59 }
60 fn syntax(&self) -> &SyntaxToken {
61 &self.syntax
62 }
63}
64#[derive(Debug, Clone, PartialEq, Eq, Hash)]
65pub struct LParen {
66 pub(crate) syntax: SyntaxToken,
67}
68impl std::fmt::Display for LParen {
69 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
70 std::fmt::Display::fmt(&self.syntax, f)
71 }
72}
73impl AstToken for LParen {
74 fn can_cast(kind: SyntaxKind) -> bool {
75 match kind {
76 L_PAREN => true,
77 _ => false,
78 }
79 }
80 fn cast(syntax: SyntaxToken) -> Option<Self> {
81 if Self::can_cast(syntax.kind()) {
82 Some(Self { syntax })
83 } else {
84 None
85 }
86 }
87 fn syntax(&self) -> &SyntaxToken {
88 &self.syntax
89 }
90}
91#[derive(Debug, Clone, PartialEq, Eq, Hash)]
92pub struct RParen {
93 pub(crate) syntax: SyntaxToken,
94}
95impl std::fmt::Display for RParen {
96 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
97 std::fmt::Display::fmt(&self.syntax, f)
98 }
99}
100impl AstToken for RParen {
101 fn can_cast(kind: SyntaxKind) -> bool {
102 match kind {
103 R_PAREN => true,
104 _ => false,
105 }
106 }
107 fn cast(syntax: SyntaxToken) -> Option<Self> {
108 if Self::can_cast(syntax.kind()) {
109 Some(Self { syntax })
110 } else {
111 None
112 }
113 }
114 fn syntax(&self) -> &SyntaxToken {
115 &self.syntax
116 }
117}
118#[derive(Debug, Clone, PartialEq, Eq, Hash)]
119pub struct LCurly {
120 pub(crate) syntax: SyntaxToken,
121}
122impl std::fmt::Display for LCurly {
123 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
124 std::fmt::Display::fmt(&self.syntax, f)
125 }
126}
127impl AstToken for LCurly {
128 fn can_cast(kind: SyntaxKind) -> bool {
129 match kind {
130 L_CURLY => true,
131 _ => false,
132 }
133 }
134 fn cast(syntax: SyntaxToken) -> Option<Self> {
135 if Self::can_cast(syntax.kind()) {
136 Some(Self { syntax })
137 } else {
138 None
139 }
140 }
141 fn syntax(&self) -> &SyntaxToken {
142 &self.syntax
143 }
144}
145#[derive(Debug, Clone, PartialEq, Eq, Hash)]
146pub struct RCurly {
147 pub(crate) syntax: SyntaxToken,
148}
149impl std::fmt::Display for RCurly {
150 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
151 std::fmt::Display::fmt(&self.syntax, f)
152 }
153}
154impl AstToken for RCurly {
155 fn can_cast(kind: SyntaxKind) -> bool {
156 match kind {
157 R_CURLY => true,
158 _ => false,
159 }
160 }
161 fn cast(syntax: SyntaxToken) -> Option<Self> {
162 if Self::can_cast(syntax.kind()) {
163 Some(Self { syntax })
164 } else {
165 None
166 }
167 }
168 fn syntax(&self) -> &SyntaxToken {
169 &self.syntax
170 }
171}
172#[derive(Debug, Clone, PartialEq, Eq, Hash)]
173pub struct LBrack {
174 pub(crate) syntax: SyntaxToken,
175}
176impl std::fmt::Display for LBrack {
177 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
178 std::fmt::Display::fmt(&self.syntax, f)
179 }
180}
181impl AstToken for LBrack {
182 fn can_cast(kind: SyntaxKind) -> bool {
183 match kind {
184 L_BRACK => true,
185 _ => false,
186 }
187 }
188 fn cast(syntax: SyntaxToken) -> Option<Self> {
189 if Self::can_cast(syntax.kind()) {
190 Some(Self { syntax })
191 } else {
192 None
193 }
194 }
195 fn syntax(&self) -> &SyntaxToken {
196 &self.syntax
197 }
198}
199#[derive(Debug, Clone, PartialEq, Eq, Hash)]
200pub struct RBrack {
201 pub(crate) syntax: SyntaxToken,
202}
203impl std::fmt::Display for RBrack {
204 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
205 std::fmt::Display::fmt(&self.syntax, f)
206 }
207}
208impl AstToken for RBrack {
209 fn can_cast(kind: SyntaxKind) -> bool {
210 match kind {
211 R_BRACK => true,
212 _ => false,
213 }
214 }
215 fn cast(syntax: SyntaxToken) -> Option<Self> {
216 if Self::can_cast(syntax.kind()) {
217 Some(Self { syntax })
218 } else {
219 None
220 }
221 }
222 fn syntax(&self) -> &SyntaxToken {
223 &self.syntax
224 }
225}
226#[derive(Debug, Clone, PartialEq, Eq, Hash)]
227pub struct LAngle {
228 pub(crate) syntax: SyntaxToken,
229}
230impl std::fmt::Display for LAngle {
231 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
232 std::fmt::Display::fmt(&self.syntax, f)
233 }
234}
235impl AstToken for LAngle {
236 fn can_cast(kind: SyntaxKind) -> bool {
237 match kind {
238 L_ANGLE => true,
239 _ => false,
240 }
241 }
242 fn cast(syntax: SyntaxToken) -> Option<Self> {
243 if Self::can_cast(syntax.kind()) {
244 Some(Self { syntax })
245 } else {
246 None
247 }
248 }
249 fn syntax(&self) -> &SyntaxToken {
250 &self.syntax
251 }
252}
253#[derive(Debug, Clone, PartialEq, Eq, Hash)]
254pub struct RAngle {
255 pub(crate) syntax: SyntaxToken,
256}
257impl std::fmt::Display for RAngle {
258 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
259 std::fmt::Display::fmt(&self.syntax, f)
260 }
261}
262impl AstToken for RAngle {
263 fn can_cast(kind: SyntaxKind) -> bool {
264 match kind {
265 R_ANGLE => true,
266 _ => false,
267 }
268 }
269 fn cast(syntax: SyntaxToken) -> Option<Self> {
270 if Self::can_cast(syntax.kind()) {
271 Some(Self { syntax })
272 } else {
273 None
274 }
275 }
276 fn syntax(&self) -> &SyntaxToken {
277 &self.syntax
278 }
279}
280#[derive(Debug, Clone, PartialEq, Eq, Hash)]
281pub struct At {
282 pub(crate) syntax: SyntaxToken,
283}
284impl std::fmt::Display for At {
285 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
286 std::fmt::Display::fmt(&self.syntax, f)
287 }
288}
289impl AstToken for At {
290 fn can_cast(kind: SyntaxKind) -> bool {
291 match kind {
292 AT => true,
293 _ => false,
294 }
295 }
296 fn cast(syntax: SyntaxToken) -> Option<Self> {
297 if Self::can_cast(syntax.kind()) {
298 Some(Self { syntax })
299 } else {
300 None
301 }
302 }
303 fn syntax(&self) -> &SyntaxToken {
304 &self.syntax
305 }
306}
307#[derive(Debug, Clone, PartialEq, Eq, Hash)]
308pub struct Pound {
309 pub(crate) syntax: SyntaxToken,
310}
311impl std::fmt::Display for Pound {
312 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
313 std::fmt::Display::fmt(&self.syntax, f)
314 }
315}
316impl AstToken for Pound {
317 fn can_cast(kind: SyntaxKind) -> bool {
318 match kind {
319 POUND => true,
320 _ => false,
321 }
322 }
323 fn cast(syntax: SyntaxToken) -> Option<Self> {
324 if Self::can_cast(syntax.kind()) {
325 Some(Self { syntax })
326 } else {
327 None
328 }
329 }
330 fn syntax(&self) -> &SyntaxToken {
331 &self.syntax
332 }
333}
334#[derive(Debug, Clone, PartialEq, Eq, Hash)]
335pub struct Tilde {
336 pub(crate) syntax: SyntaxToken,
337}
338impl std::fmt::Display for Tilde {
339 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
340 std::fmt::Display::fmt(&self.syntax, f)
341 }
342}
343impl AstToken for Tilde {
344 fn can_cast(kind: SyntaxKind) -> bool {
345 match kind {
346 TILDE => true,
347 _ => false,
348 }
349 }
350 fn cast(syntax: SyntaxToken) -> Option<Self> {
351 if Self::can_cast(syntax.kind()) {
352 Some(Self { syntax })
353 } else {
354 None
355 }
356 }
357 fn syntax(&self) -> &SyntaxToken {
358 &self.syntax
359 }
360}
361#[derive(Debug, Clone, PartialEq, Eq, Hash)]
362pub struct Question {
363 pub(crate) syntax: SyntaxToken,
364}
365impl std::fmt::Display for Question {
366 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
367 std::fmt::Display::fmt(&self.syntax, f)
368 }
369}
370impl AstToken for Question {
371 fn can_cast(kind: SyntaxKind) -> bool {
372 match kind {
373 QUESTION => true,
374 _ => false,
375 }
376 }
377 fn cast(syntax: SyntaxToken) -> Option<Self> {
378 if Self::can_cast(syntax.kind()) {
379 Some(Self { syntax })
380 } else {
381 None
382 }
383 }
384 fn syntax(&self) -> &SyntaxToken {
385 &self.syntax
386 }
387}
388#[derive(Debug, Clone, PartialEq, Eq, Hash)]
389pub struct Dollar {
390 pub(crate) syntax: SyntaxToken,
391}
392impl std::fmt::Display for Dollar {
393 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
394 std::fmt::Display::fmt(&self.syntax, f)
395 }
396}
397impl AstToken for Dollar {
398 fn can_cast(kind: SyntaxKind) -> bool {
399 match kind {
400 DOLLAR => true,
401 _ => false,
402 }
403 }
404 fn cast(syntax: SyntaxToken) -> Option<Self> {
405 if Self::can_cast(syntax.kind()) {
406 Some(Self { syntax })
407 } else {
408 None
409 }
410 }
411 fn syntax(&self) -> &SyntaxToken {
412 &self.syntax
413 }
414}
415#[derive(Debug, Clone, PartialEq, Eq, Hash)]
416pub struct Amp {
417 pub(crate) syntax: SyntaxToken,
418}
419impl std::fmt::Display for Amp {
420 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
421 std::fmt::Display::fmt(&self.syntax, f)
422 }
423}
424impl AstToken for Amp {
425 fn can_cast(kind: SyntaxKind) -> bool {
426 match kind {
427 AMP => true,
428 _ => false,
429 }
430 }
431 fn cast(syntax: SyntaxToken) -> Option<Self> {
432 if Self::can_cast(syntax.kind()) {
433 Some(Self { syntax })
434 } else {
435 None
436 }
437 }
438 fn syntax(&self) -> &SyntaxToken {
439 &self.syntax
440 }
441}
442#[derive(Debug, Clone, PartialEq, Eq, Hash)]
443pub struct Pipe {
444 pub(crate) syntax: SyntaxToken,
445}
446impl std::fmt::Display for Pipe {
447 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
448 std::fmt::Display::fmt(&self.syntax, f)
449 }
450}
451impl AstToken for Pipe {
452 fn can_cast(kind: SyntaxKind) -> bool {
453 match kind {
454 PIPE => true,
455 _ => false,
456 }
457 }
458 fn cast(syntax: SyntaxToken) -> Option<Self> {
459 if Self::can_cast(syntax.kind()) {
460 Some(Self { syntax })
461 } else {
462 None
463 }
464 }
465 fn syntax(&self) -> &SyntaxToken {
466 &self.syntax
467 }
468}
469#[derive(Debug, Clone, PartialEq, Eq, Hash)]
470pub struct Plus {
471 pub(crate) syntax: SyntaxToken,
472}
473impl std::fmt::Display for Plus {
474 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
475 std::fmt::Display::fmt(&self.syntax, f)
476 }
477}
478impl AstToken for Plus {
479 fn can_cast(kind: SyntaxKind) -> bool {
480 match kind {
481 PLUS => true,
482 _ => false,
483 }
484 }
485 fn cast(syntax: SyntaxToken) -> Option<Self> {
486 if Self::can_cast(syntax.kind()) {
487 Some(Self { syntax })
488 } else {
489 None
490 }
491 }
492 fn syntax(&self) -> &SyntaxToken {
493 &self.syntax
494 }
495}
496#[derive(Debug, Clone, PartialEq, Eq, Hash)]
497pub struct Star {
498 pub(crate) syntax: SyntaxToken,
499}
500impl std::fmt::Display for Star {
501 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
502 std::fmt::Display::fmt(&self.syntax, f)
503 }
504}
505impl AstToken for Star {
506 fn can_cast(kind: SyntaxKind) -> bool {
507 match kind {
508 STAR => true,
509 _ => false,
510 }
511 }
512 fn cast(syntax: SyntaxToken) -> Option<Self> {
513 if Self::can_cast(syntax.kind()) {
514 Some(Self { syntax })
515 } else {
516 None
517 }
518 }
519 fn syntax(&self) -> &SyntaxToken {
520 &self.syntax
521 }
522}
523#[derive(Debug, Clone, PartialEq, Eq, Hash)]
524pub struct Slash {
525 pub(crate) syntax: SyntaxToken,
526}
527impl std::fmt::Display for Slash {
528 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
529 std::fmt::Display::fmt(&self.syntax, f)
530 }
531}
532impl AstToken for Slash {
533 fn can_cast(kind: SyntaxKind) -> bool {
534 match kind {
535 SLASH => true,
536 _ => false,
537 }
538 }
539 fn cast(syntax: SyntaxToken) -> Option<Self> {
540 if Self::can_cast(syntax.kind()) {
541 Some(Self { syntax })
542 } else {
543 None
544 }
545 }
546 fn syntax(&self) -> &SyntaxToken {
547 &self.syntax
548 }
549}
550#[derive(Debug, Clone, PartialEq, Eq, Hash)]
551pub struct Caret {
552 pub(crate) syntax: SyntaxToken,
553}
554impl std::fmt::Display for Caret {
555 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
556 std::fmt::Display::fmt(&self.syntax, f)
557 }
558}
559impl AstToken for Caret {
560 fn can_cast(kind: SyntaxKind) -> bool {
561 match kind {
562 CARET => true,
563 _ => false,
564 }
565 }
566 fn cast(syntax: SyntaxToken) -> Option<Self> {
567 if Self::can_cast(syntax.kind()) {
568 Some(Self { syntax })
569 } else {
570 None
571 }
572 }
573 fn syntax(&self) -> &SyntaxToken {
574 &self.syntax
575 }
576}
577#[derive(Debug, Clone, PartialEq, Eq, Hash)]
578pub struct Percent {
579 pub(crate) syntax: SyntaxToken,
580}
581impl std::fmt::Display for Percent {
582 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
583 std::fmt::Display::fmt(&self.syntax, f)
584 }
585}
586impl AstToken for Percent {
587 fn can_cast(kind: SyntaxKind) -> bool {
588 match kind {
589 PERCENT => true,
590 _ => false,
591 }
592 }
593 fn cast(syntax: SyntaxToken) -> Option<Self> {
594 if Self::can_cast(syntax.kind()) {
595 Some(Self { syntax })
596 } else {
597 None
598 }
599 }
600 fn syntax(&self) -> &SyntaxToken {
601 &self.syntax
602 }
603}
604#[derive(Debug, Clone, PartialEq, Eq, Hash)]
605pub struct Underscore {
606 pub(crate) syntax: SyntaxToken,
607}
608impl std::fmt::Display for Underscore {
609 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
610 std::fmt::Display::fmt(&self.syntax, f)
611 }
612}
613impl AstToken for Underscore {
614 fn can_cast(kind: SyntaxKind) -> bool {
615 match kind {
616 UNDERSCORE => true,
617 _ => false,
618 }
619 }
620 fn cast(syntax: SyntaxToken) -> Option<Self> {
621 if Self::can_cast(syntax.kind()) {
622 Some(Self { syntax })
623 } else {
624 None
625 }
626 }
627 fn syntax(&self) -> &SyntaxToken {
628 &self.syntax
629 }
630}
631#[derive(Debug, Clone, PartialEq, Eq, Hash)]
632pub struct Dot {
633 pub(crate) syntax: SyntaxToken,
634}
635impl std::fmt::Display for Dot {
636 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
637 std::fmt::Display::fmt(&self.syntax, f)
638 }
639}
640impl AstToken for Dot {
641 fn can_cast(kind: SyntaxKind) -> bool {
642 match kind {
643 DOT => true,
644 _ => false,
645 }
646 }
647 fn cast(syntax: SyntaxToken) -> Option<Self> {
648 if Self::can_cast(syntax.kind()) {
649 Some(Self { syntax })
650 } else {
651 None
652 }
653 }
654 fn syntax(&self) -> &SyntaxToken {
655 &self.syntax
656 }
657}
658#[derive(Debug, Clone, PartialEq, Eq, Hash)]
659pub struct Dotdot {
660 pub(crate) syntax: SyntaxToken,
661}
662impl std::fmt::Display for Dotdot {
663 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
664 std::fmt::Display::fmt(&self.syntax, f)
665 }
666}
667impl AstToken for Dotdot {
668 fn can_cast(kind: SyntaxKind) -> bool {
669 match kind {
670 DOTDOT => true,
671 _ => false,
672 }
673 }
674 fn cast(syntax: SyntaxToken) -> Option<Self> {
675 if Self::can_cast(syntax.kind()) {
676 Some(Self { syntax })
677 } else {
678 None
679 }
680 }
681 fn syntax(&self) -> &SyntaxToken {
682 &self.syntax
683 }
684}
685#[derive(Debug, Clone, PartialEq, Eq, Hash)]
686pub struct Dotdotdot {
687 pub(crate) syntax: SyntaxToken,
688}
689impl std::fmt::Display for Dotdotdot {
690 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
691 std::fmt::Display::fmt(&self.syntax, f)
692 }
693}
694impl AstToken for Dotdotdot {
695 fn can_cast(kind: SyntaxKind) -> bool {
696 match kind {
697 DOTDOTDOT => true,
698 _ => false,
699 }
700 }
701 fn cast(syntax: SyntaxToken) -> Option<Self> {
702 if Self::can_cast(syntax.kind()) {
703 Some(Self { syntax })
704 } else {
705 None
706 }
707 }
708 fn syntax(&self) -> &SyntaxToken {
709 &self.syntax
710 }
711}
712#[derive(Debug, Clone, PartialEq, Eq, Hash)]
713pub struct Dotdoteq {
714 pub(crate) syntax: SyntaxToken,
715}
716impl std::fmt::Display for Dotdoteq {
717 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
718 std::fmt::Display::fmt(&self.syntax, f)
719 }
720}
721impl AstToken for Dotdoteq {
722 fn can_cast(kind: SyntaxKind) -> bool {
723 match kind {
724 DOTDOTEQ => true,
725 _ => false,
726 }
727 }
728 fn cast(syntax: SyntaxToken) -> Option<Self> {
729 if Self::can_cast(syntax.kind()) {
730 Some(Self { syntax })
731 } else {
732 None
733 }
734 }
735 fn syntax(&self) -> &SyntaxToken {
736 &self.syntax
737 }
738}
739#[derive(Debug, Clone, PartialEq, Eq, Hash)]
740pub struct Colon {
741 pub(crate) syntax: SyntaxToken,
742}
743impl std::fmt::Display for Colon {
744 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
745 std::fmt::Display::fmt(&self.syntax, f)
746 }
747}
748impl AstToken for Colon {
749 fn can_cast(kind: SyntaxKind) -> bool {
750 match kind {
751 COLON => true,
752 _ => false,
753 }
754 }
755 fn cast(syntax: SyntaxToken) -> Option<Self> {
756 if Self::can_cast(syntax.kind()) {
757 Some(Self { syntax })
758 } else {
759 None
760 }
761 }
762 fn syntax(&self) -> &SyntaxToken {
763 &self.syntax
764 }
765}
766#[derive(Debug, Clone, PartialEq, Eq, Hash)]
767pub struct Coloncolon {
768 pub(crate) syntax: SyntaxToken,
769}
770impl std::fmt::Display for Coloncolon {
771 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
772 std::fmt::Display::fmt(&self.syntax, f)
773 }
774}
775impl AstToken for Coloncolon {
776 fn can_cast(kind: SyntaxKind) -> bool {
777 match kind {
778 COLONCOLON => true,
779 _ => false,
780 }
781 }
782 fn cast(syntax: SyntaxToken) -> Option<Self> {
783 if Self::can_cast(syntax.kind()) {
784 Some(Self { syntax })
785 } else {
786 None
787 }
788 }
789 fn syntax(&self) -> &SyntaxToken {
790 &self.syntax
791 }
792}
793#[derive(Debug, Clone, PartialEq, Eq, Hash)]
794pub struct Eq {
795 pub(crate) syntax: SyntaxToken,
796}
797impl std::fmt::Display for Eq {
798 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
799 std::fmt::Display::fmt(&self.syntax, f)
800 }
801}
802impl AstToken for Eq {
803 fn can_cast(kind: SyntaxKind) -> bool {
804 match kind {
805 EQ => true,
806 _ => false,
807 }
808 }
809 fn cast(syntax: SyntaxToken) -> Option<Self> {
810 if Self::can_cast(syntax.kind()) {
811 Some(Self { syntax })
812 } else {
813 None
814 }
815 }
816 fn syntax(&self) -> &SyntaxToken {
817 &self.syntax
818 }
819}
820#[derive(Debug, Clone, PartialEq, Eq, Hash)]
821pub struct Eqeq {
822 pub(crate) syntax: SyntaxToken,
823}
824impl std::fmt::Display for Eqeq {
825 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
826 std::fmt::Display::fmt(&self.syntax, f)
827 }
828}
829impl AstToken for Eqeq {
830 fn can_cast(kind: SyntaxKind) -> bool {
831 match kind {
832 EQEQ => true,
833 _ => false,
834 }
835 }
836 fn cast(syntax: SyntaxToken) -> Option<Self> {
837 if Self::can_cast(syntax.kind()) {
838 Some(Self { syntax })
839 } else {
840 None
841 }
842 }
843 fn syntax(&self) -> &SyntaxToken {
844 &self.syntax
845 }
846}
847#[derive(Debug, Clone, PartialEq, Eq, Hash)]
848pub struct FatArrow {
849 pub(crate) syntax: SyntaxToken,
850}
851impl std::fmt::Display for FatArrow {
852 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
853 std::fmt::Display::fmt(&self.syntax, f)
854 }
855}
856impl AstToken for FatArrow {
857 fn can_cast(kind: SyntaxKind) -> bool {
858 match kind {
859 FAT_ARROW => true,
860 _ => false,
861 }
862 }
863 fn cast(syntax: SyntaxToken) -> Option<Self> {
864 if Self::can_cast(syntax.kind()) {
865 Some(Self { syntax })
866 } else {
867 None
868 }
869 }
870 fn syntax(&self) -> &SyntaxToken {
871 &self.syntax
872 }
873}
874#[derive(Debug, Clone, PartialEq, Eq, Hash)]
875pub struct Excl {
876 pub(crate) syntax: SyntaxToken,
877}
878impl std::fmt::Display for Excl {
879 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
880 std::fmt::Display::fmt(&self.syntax, f)
881 }
882}
883impl AstToken for Excl {
884 fn can_cast(kind: SyntaxKind) -> bool {
885 match kind {
886 EXCL => true,
887 _ => false,
888 }
889 }
890 fn cast(syntax: SyntaxToken) -> Option<Self> {
891 if Self::can_cast(syntax.kind()) {
892 Some(Self { syntax })
893 } else {
894 None
895 }
896 }
897 fn syntax(&self) -> &SyntaxToken {
898 &self.syntax
899 }
900}
901#[derive(Debug, Clone, PartialEq, Eq, Hash)]
902pub struct Neq {
903 pub(crate) syntax: SyntaxToken,
904}
905impl std::fmt::Display for Neq {
906 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
907 std::fmt::Display::fmt(&self.syntax, f)
908 }
909}
910impl AstToken for Neq {
911 fn can_cast(kind: SyntaxKind) -> bool {
912 match kind {
913 NEQ => true,
914 _ => false,
915 }
916 }
917 fn cast(syntax: SyntaxToken) -> Option<Self> {
918 if Self::can_cast(syntax.kind()) {
919 Some(Self { syntax })
920 } else {
921 None
922 }
923 }
924 fn syntax(&self) -> &SyntaxToken {
925 &self.syntax
926 }
927}
928#[derive(Debug, Clone, PartialEq, Eq, Hash)]
929pub struct Minus {
930 pub(crate) syntax: SyntaxToken,
931}
932impl std::fmt::Display for Minus {
933 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
934 std::fmt::Display::fmt(&self.syntax, f)
935 }
936}
937impl AstToken for Minus {
938 fn can_cast(kind: SyntaxKind) -> bool {
939 match kind {
940 MINUS => true,
941 _ => false,
942 }
943 }
944 fn cast(syntax: SyntaxToken) -> Option<Self> {
945 if Self::can_cast(syntax.kind()) {
946 Some(Self { syntax })
947 } else {
948 None
949 }
950 }
951 fn syntax(&self) -> &SyntaxToken {
952 &self.syntax
953 }
954}
955#[derive(Debug, Clone, PartialEq, Eq, Hash)]
956pub struct ThinArrow {
957 pub(crate) syntax: SyntaxToken,
958}
959impl std::fmt::Display for ThinArrow {
960 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
961 std::fmt::Display::fmt(&self.syntax, f)
962 }
963}
964impl AstToken for ThinArrow {
965 fn can_cast(kind: SyntaxKind) -> bool {
966 match kind {
967 THIN_ARROW => true,
968 _ => false,
969 }
970 }
971 fn cast(syntax: SyntaxToken) -> Option<Self> {
972 if Self::can_cast(syntax.kind()) {
973 Some(Self { syntax })
974 } else {
975 None
976 }
977 }
978 fn syntax(&self) -> &SyntaxToken {
979 &self.syntax
980 }
981}
982#[derive(Debug, Clone, PartialEq, Eq, Hash)]
983pub struct Lteq {
984 pub(crate) syntax: SyntaxToken,
985}
986impl std::fmt::Display for Lteq {
987 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
988 std::fmt::Display::fmt(&self.syntax, f)
989 }
990}
991impl AstToken for Lteq {
992 fn can_cast(kind: SyntaxKind) -> bool {
993 match kind {
994 LTEQ => true,
995 _ => false,
996 }
997 }
998 fn cast(syntax: SyntaxToken) -> Option<Self> {
999 if Self::can_cast(syntax.kind()) {
1000 Some(Self { syntax })
1001 } else {
1002 None
1003 }
1004 }
1005 fn syntax(&self) -> &SyntaxToken {
1006 &self.syntax
1007 }
1008}
1009#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1010pub struct Gteq {
1011 pub(crate) syntax: SyntaxToken,
1012}
1013impl std::fmt::Display for Gteq {
1014 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1015 std::fmt::Display::fmt(&self.syntax, f)
1016 }
1017}
1018impl AstToken for Gteq {
1019 fn can_cast(kind: SyntaxKind) -> bool {
1020 match kind {
1021 GTEQ => true,
1022 _ => false,
1023 }
1024 }
1025 fn cast(syntax: SyntaxToken) -> Option<Self> {
1026 if Self::can_cast(syntax.kind()) {
1027 Some(Self { syntax })
1028 } else {
1029 None
1030 }
1031 }
1032 fn syntax(&self) -> &SyntaxToken {
1033 &self.syntax
1034 }
1035}
1036#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1037pub struct Pluseq {
1038 pub(crate) syntax: SyntaxToken,
1039}
1040impl std::fmt::Display for Pluseq {
1041 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1042 std::fmt::Display::fmt(&self.syntax, f)
1043 }
1044}
1045impl AstToken for Pluseq {
1046 fn can_cast(kind: SyntaxKind) -> bool {
1047 match kind {
1048 PLUSEQ => true,
1049 _ => false,
1050 }
1051 }
1052 fn cast(syntax: SyntaxToken) -> Option<Self> {
1053 if Self::can_cast(syntax.kind()) {
1054 Some(Self { syntax })
1055 } else {
1056 None
1057 }
1058 }
1059 fn syntax(&self) -> &SyntaxToken {
1060 &self.syntax
1061 }
1062}
1063#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1064pub struct Minuseq {
1065 pub(crate) syntax: SyntaxToken,
1066}
1067impl std::fmt::Display for Minuseq {
1068 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1069 std::fmt::Display::fmt(&self.syntax, f)
1070 }
1071}
1072impl AstToken for Minuseq {
1073 fn can_cast(kind: SyntaxKind) -> bool {
1074 match kind {
1075 MINUSEQ => true,
1076 _ => false,
1077 }
1078 }
1079 fn cast(syntax: SyntaxToken) -> Option<Self> {
1080 if Self::can_cast(syntax.kind()) {
1081 Some(Self { syntax })
1082 } else {
1083 None
1084 }
1085 }
1086 fn syntax(&self) -> &SyntaxToken {
1087 &self.syntax
1088 }
1089}
1090#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1091pub struct Pipeeq {
1092 pub(crate) syntax: SyntaxToken,
1093}
1094impl std::fmt::Display for Pipeeq {
1095 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1096 std::fmt::Display::fmt(&self.syntax, f)
1097 }
1098}
1099impl AstToken for Pipeeq {
1100 fn can_cast(kind: SyntaxKind) -> bool {
1101 match kind {
1102 PIPEEQ => true,
1103 _ => false,
1104 }
1105 }
1106 fn cast(syntax: SyntaxToken) -> Option<Self> {
1107 if Self::can_cast(syntax.kind()) {
1108 Some(Self { syntax })
1109 } else {
1110 None
1111 }
1112 }
1113 fn syntax(&self) -> &SyntaxToken {
1114 &self.syntax
1115 }
1116}
1117#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1118pub struct Ampeq {
1119 pub(crate) syntax: SyntaxToken,
1120}
1121impl std::fmt::Display for Ampeq {
1122 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1123 std::fmt::Display::fmt(&self.syntax, f)
1124 }
1125}
1126impl AstToken for Ampeq {
1127 fn can_cast(kind: SyntaxKind) -> bool {
1128 match kind {
1129 AMPEQ => true,
1130 _ => false,
1131 }
1132 }
1133 fn cast(syntax: SyntaxToken) -> Option<Self> {
1134 if Self::can_cast(syntax.kind()) {
1135 Some(Self { syntax })
1136 } else {
1137 None
1138 }
1139 }
1140 fn syntax(&self) -> &SyntaxToken {
1141 &self.syntax
1142 }
1143}
1144#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1145pub struct Careteq {
1146 pub(crate) syntax: SyntaxToken,
1147}
1148impl std::fmt::Display for Careteq {
1149 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1150 std::fmt::Display::fmt(&self.syntax, f)
1151 }
1152}
1153impl AstToken for Careteq {
1154 fn can_cast(kind: SyntaxKind) -> bool {
1155 match kind {
1156 CARETEQ => true,
1157 _ => false,
1158 }
1159 }
1160 fn cast(syntax: SyntaxToken) -> Option<Self> {
1161 if Self::can_cast(syntax.kind()) {
1162 Some(Self { syntax })
1163 } else {
1164 None
1165 }
1166 }
1167 fn syntax(&self) -> &SyntaxToken {
1168 &self.syntax
1169 }
1170}
1171#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1172pub struct Slasheq {
1173 pub(crate) syntax: SyntaxToken,
1174}
1175impl std::fmt::Display for Slasheq {
1176 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1177 std::fmt::Display::fmt(&self.syntax, f)
1178 }
1179}
1180impl AstToken for Slasheq {
1181 fn can_cast(kind: SyntaxKind) -> bool {
1182 match kind {
1183 SLASHEQ => true,
1184 _ => false,
1185 }
1186 }
1187 fn cast(syntax: SyntaxToken) -> Option<Self> {
1188 if Self::can_cast(syntax.kind()) {
1189 Some(Self { syntax })
1190 } else {
1191 None
1192 }
1193 }
1194 fn syntax(&self) -> &SyntaxToken {
1195 &self.syntax
1196 }
1197}
1198#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1199pub struct Stareq {
1200 pub(crate) syntax: SyntaxToken,
1201}
1202impl std::fmt::Display for Stareq {
1203 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1204 std::fmt::Display::fmt(&self.syntax, f)
1205 }
1206}
1207impl AstToken for Stareq {
1208 fn can_cast(kind: SyntaxKind) -> bool {
1209 match kind {
1210 STAREQ => true,
1211 _ => false,
1212 }
1213 }
1214 fn cast(syntax: SyntaxToken) -> Option<Self> {
1215 if Self::can_cast(syntax.kind()) {
1216 Some(Self { syntax })
1217 } else {
1218 None
1219 }
1220 }
1221 fn syntax(&self) -> &SyntaxToken {
1222 &self.syntax
1223 }
1224}
1225#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1226pub struct Percenteq {
1227 pub(crate) syntax: SyntaxToken,
1228}
1229impl std::fmt::Display for Percenteq {
1230 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1231 std::fmt::Display::fmt(&self.syntax, f)
1232 }
1233}
1234impl AstToken for Percenteq {
1235 fn can_cast(kind: SyntaxKind) -> bool {
1236 match kind {
1237 PERCENTEQ => true,
1238 _ => false,
1239 }
1240 }
1241 fn cast(syntax: SyntaxToken) -> Option<Self> {
1242 if Self::can_cast(syntax.kind()) {
1243 Some(Self { syntax })
1244 } else {
1245 None
1246 }
1247 }
1248 fn syntax(&self) -> &SyntaxToken {
1249 &self.syntax
1250 }
1251}
1252#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1253pub struct Ampamp {
1254 pub(crate) syntax: SyntaxToken,
1255}
1256impl std::fmt::Display for Ampamp {
1257 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1258 std::fmt::Display::fmt(&self.syntax, f)
1259 }
1260}
1261impl AstToken for Ampamp {
1262 fn can_cast(kind: SyntaxKind) -> bool {
1263 match kind {
1264 AMPAMP => true,
1265 _ => false,
1266 }
1267 }
1268 fn cast(syntax: SyntaxToken) -> Option<Self> {
1269 if Self::can_cast(syntax.kind()) {
1270 Some(Self { syntax })
1271 } else {
1272 None
1273 }
1274 }
1275 fn syntax(&self) -> &SyntaxToken {
1276 &self.syntax
1277 }
1278}
1279#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1280pub struct Pipepipe {
1281 pub(crate) syntax: SyntaxToken,
1282}
1283impl std::fmt::Display for Pipepipe {
1284 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1285 std::fmt::Display::fmt(&self.syntax, f)
1286 }
1287}
1288impl AstToken for Pipepipe {
1289 fn can_cast(kind: SyntaxKind) -> bool {
1290 match kind {
1291 PIPEPIPE => true,
1292 _ => false,
1293 }
1294 }
1295 fn cast(syntax: SyntaxToken) -> Option<Self> {
1296 if Self::can_cast(syntax.kind()) {
1297 Some(Self { syntax })
1298 } else {
1299 None
1300 }
1301 }
1302 fn syntax(&self) -> &SyntaxToken {
1303 &self.syntax
1304 }
1305}
1306#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1307pub struct Shl {
1308 pub(crate) syntax: SyntaxToken,
1309}
1310impl std::fmt::Display for Shl {
1311 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1312 std::fmt::Display::fmt(&self.syntax, f)
1313 }
1314}
1315impl AstToken for Shl {
1316 fn can_cast(kind: SyntaxKind) -> bool {
1317 match kind {
1318 SHL => true,
1319 _ => false,
1320 }
1321 }
1322 fn cast(syntax: SyntaxToken) -> Option<Self> {
1323 if Self::can_cast(syntax.kind()) {
1324 Some(Self { syntax })
1325 } else {
1326 None
1327 }
1328 }
1329 fn syntax(&self) -> &SyntaxToken {
1330 &self.syntax
1331 }
1332}
1333#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1334pub struct Shr {
1335 pub(crate) syntax: SyntaxToken,
1336}
1337impl std::fmt::Display for Shr {
1338 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1339 std::fmt::Display::fmt(&self.syntax, f)
1340 }
1341}
1342impl AstToken for Shr {
1343 fn can_cast(kind: SyntaxKind) -> bool {
1344 match kind {
1345 SHR => true,
1346 _ => false,
1347 }
1348 }
1349 fn cast(syntax: SyntaxToken) -> Option<Self> {
1350 if Self::can_cast(syntax.kind()) {
1351 Some(Self { syntax })
1352 } else {
1353 None
1354 }
1355 }
1356 fn syntax(&self) -> &SyntaxToken {
1357 &self.syntax
1358 }
1359}
1360#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1361pub struct Shleq {
1362 pub(crate) syntax: SyntaxToken,
1363}
1364impl std::fmt::Display for Shleq {
1365 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1366 std::fmt::Display::fmt(&self.syntax, f)
1367 }
1368}
1369impl AstToken for Shleq {
1370 fn can_cast(kind: SyntaxKind) -> bool {
1371 match kind {
1372 SHLEQ => true,
1373 _ => false,
1374 }
1375 }
1376 fn cast(syntax: SyntaxToken) -> Option<Self> {
1377 if Self::can_cast(syntax.kind()) {
1378 Some(Self { syntax })
1379 } else {
1380 None
1381 }
1382 }
1383 fn syntax(&self) -> &SyntaxToken {
1384 &self.syntax
1385 }
1386}
1387#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1388pub struct Shreq {
1389 pub(crate) syntax: SyntaxToken,
1390}
1391impl std::fmt::Display for Shreq {
1392 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1393 std::fmt::Display::fmt(&self.syntax, f)
1394 }
1395}
1396impl AstToken for Shreq {
1397 fn can_cast(kind: SyntaxKind) -> bool {
1398 match kind {
1399 SHREQ => true,
1400 _ => false,
1401 }
1402 }
1403 fn cast(syntax: SyntaxToken) -> Option<Self> {
1404 if Self::can_cast(syntax.kind()) {
1405 Some(Self { syntax })
1406 } else {
1407 None
1408 }
1409 }
1410 fn syntax(&self) -> &SyntaxToken {
1411 &self.syntax
1412 }
1413}
1414#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1415pub struct AsKw {
1416 pub(crate) syntax: SyntaxToken,
1417}
1418impl std::fmt::Display for AsKw {
1419 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1420 std::fmt::Display::fmt(&self.syntax, f)
1421 }
1422}
1423impl AstToken for AsKw {
1424 fn can_cast(kind: SyntaxKind) -> bool {
1425 match kind {
1426 AS_KW => true,
1427 _ => false,
1428 }
1429 }
1430 fn cast(syntax: SyntaxToken) -> Option<Self> {
1431 if Self::can_cast(syntax.kind()) {
1432 Some(Self { syntax })
1433 } else {
1434 None
1435 }
1436 }
1437 fn syntax(&self) -> &SyntaxToken {
1438 &self.syntax
1439 }
1440}
1441#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1442pub struct AsyncKw {
1443 pub(crate) syntax: SyntaxToken,
1444}
1445impl std::fmt::Display for AsyncKw {
1446 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1447 std::fmt::Display::fmt(&self.syntax, f)
1448 }
1449}
1450impl AstToken for AsyncKw {
1451 fn can_cast(kind: SyntaxKind) -> bool {
1452 match kind {
1453 ASYNC_KW => true,
1454 _ => false,
1455 }
1456 }
1457 fn cast(syntax: SyntaxToken) -> Option<Self> {
1458 if Self::can_cast(syntax.kind()) {
1459 Some(Self { syntax })
1460 } else {
1461 None
1462 }
1463 }
1464 fn syntax(&self) -> &SyntaxToken {
1465 &self.syntax
1466 }
1467}
1468#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1469pub struct AwaitKw {
1470 pub(crate) syntax: SyntaxToken,
1471}
1472impl std::fmt::Display for AwaitKw {
1473 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1474 std::fmt::Display::fmt(&self.syntax, f)
1475 }
1476}
1477impl AstToken for AwaitKw {
1478 fn can_cast(kind: SyntaxKind) -> bool {
1479 match kind {
1480 AWAIT_KW => true,
1481 _ => false,
1482 }
1483 }
1484 fn cast(syntax: SyntaxToken) -> Option<Self> {
1485 if Self::can_cast(syntax.kind()) {
1486 Some(Self { syntax })
1487 } else {
1488 None
1489 }
1490 }
1491 fn syntax(&self) -> &SyntaxToken {
1492 &self.syntax
1493 }
1494}
1495#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1496pub struct BoxKw {
1497 pub(crate) syntax: SyntaxToken,
1498}
1499impl std::fmt::Display for BoxKw {
1500 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1501 std::fmt::Display::fmt(&self.syntax, f)
1502 }
1503}
1504impl AstToken for BoxKw {
1505 fn can_cast(kind: SyntaxKind) -> bool {
1506 match kind {
1507 BOX_KW => true,
1508 _ => false,
1509 }
1510 }
1511 fn cast(syntax: SyntaxToken) -> Option<Self> {
1512 if Self::can_cast(syntax.kind()) {
1513 Some(Self { syntax })
1514 } else {
1515 None
1516 }
1517 }
1518 fn syntax(&self) -> &SyntaxToken {
1519 &self.syntax
1520 }
1521}
1522#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1523pub struct BreakKw {
1524 pub(crate) syntax: SyntaxToken,
1525}
1526impl std::fmt::Display for BreakKw {
1527 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1528 std::fmt::Display::fmt(&self.syntax, f)
1529 }
1530}
1531impl AstToken for BreakKw {
1532 fn can_cast(kind: SyntaxKind) -> bool {
1533 match kind {
1534 BREAK_KW => true,
1535 _ => false,
1536 }
1537 }
1538 fn cast(syntax: SyntaxToken) -> Option<Self> {
1539 if Self::can_cast(syntax.kind()) {
1540 Some(Self { syntax })
1541 } else {
1542 None
1543 }
1544 }
1545 fn syntax(&self) -> &SyntaxToken {
1546 &self.syntax
1547 }
1548}
1549#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1550pub struct ConstKw {
1551 pub(crate) syntax: SyntaxToken,
1552}
1553impl std::fmt::Display for ConstKw {
1554 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1555 std::fmt::Display::fmt(&self.syntax, f)
1556 }
1557}
1558impl AstToken for ConstKw {
1559 fn can_cast(kind: SyntaxKind) -> bool {
1560 match kind {
1561 CONST_KW => true,
1562 _ => false,
1563 }
1564 }
1565 fn cast(syntax: SyntaxToken) -> Option<Self> {
1566 if Self::can_cast(syntax.kind()) {
1567 Some(Self { syntax })
1568 } else {
1569 None
1570 }
1571 }
1572 fn syntax(&self) -> &SyntaxToken {
1573 &self.syntax
1574 }
1575}
1576#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1577pub struct ContinueKw {
1578 pub(crate) syntax: SyntaxToken,
1579}
1580impl std::fmt::Display for ContinueKw {
1581 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1582 std::fmt::Display::fmt(&self.syntax, f)
1583 }
1584}
1585impl AstToken for ContinueKw {
1586 fn can_cast(kind: SyntaxKind) -> bool {
1587 match kind {
1588 CONTINUE_KW => true,
1589 _ => false,
1590 }
1591 }
1592 fn cast(syntax: SyntaxToken) -> Option<Self> {
1593 if Self::can_cast(syntax.kind()) {
1594 Some(Self { syntax })
1595 } else {
1596 None
1597 }
1598 }
1599 fn syntax(&self) -> &SyntaxToken {
1600 &self.syntax
1601 }
1602}
1603#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1604pub struct CrateKw {
1605 pub(crate) syntax: SyntaxToken,
1606}
1607impl std::fmt::Display for CrateKw {
1608 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1609 std::fmt::Display::fmt(&self.syntax, f)
1610 }
1611}
1612impl AstToken for CrateKw {
1613 fn can_cast(kind: SyntaxKind) -> bool {
1614 match kind {
1615 CRATE_KW => true,
1616 _ => false,
1617 }
1618 }
1619 fn cast(syntax: SyntaxToken) -> Option<Self> {
1620 if Self::can_cast(syntax.kind()) {
1621 Some(Self { syntax })
1622 } else {
1623 None
1624 }
1625 }
1626 fn syntax(&self) -> &SyntaxToken {
1627 &self.syntax
1628 }
1629}
1630#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1631pub struct DynKw {
1632 pub(crate) syntax: SyntaxToken,
1633}
1634impl std::fmt::Display for DynKw {
1635 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1636 std::fmt::Display::fmt(&self.syntax, f)
1637 }
1638}
1639impl AstToken for DynKw {
1640 fn can_cast(kind: SyntaxKind) -> bool {
1641 match kind {
1642 DYN_KW => true,
1643 _ => false,
1644 }
1645 }
1646 fn cast(syntax: SyntaxToken) -> Option<Self> {
1647 if Self::can_cast(syntax.kind()) {
1648 Some(Self { syntax })
1649 } else {
1650 None
1651 }
1652 }
1653 fn syntax(&self) -> &SyntaxToken {
1654 &self.syntax
1655 }
1656}
1657#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1658pub struct ElseKw {
1659 pub(crate) syntax: SyntaxToken,
1660}
1661impl std::fmt::Display for ElseKw {
1662 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1663 std::fmt::Display::fmt(&self.syntax, f)
1664 }
1665}
1666impl AstToken for ElseKw {
1667 fn can_cast(kind: SyntaxKind) -> bool {
1668 match kind {
1669 ELSE_KW => true,
1670 _ => false,
1671 }
1672 }
1673 fn cast(syntax: SyntaxToken) -> Option<Self> {
1674 if Self::can_cast(syntax.kind()) {
1675 Some(Self { syntax })
1676 } else {
1677 None
1678 }
1679 }
1680 fn syntax(&self) -> &SyntaxToken {
1681 &self.syntax
1682 }
1683}
1684#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1685pub struct EnumKw {
1686 pub(crate) syntax: SyntaxToken,
1687}
1688impl std::fmt::Display for EnumKw {
1689 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1690 std::fmt::Display::fmt(&self.syntax, f)
1691 }
1692}
1693impl AstToken for EnumKw {
1694 fn can_cast(kind: SyntaxKind) -> bool {
1695 match kind {
1696 ENUM_KW => true,
1697 _ => false,
1698 }
1699 }
1700 fn cast(syntax: SyntaxToken) -> Option<Self> {
1701 if Self::can_cast(syntax.kind()) {
1702 Some(Self { syntax })
1703 } else {
1704 None
1705 }
1706 }
1707 fn syntax(&self) -> &SyntaxToken {
1708 &self.syntax
1709 }
1710}
1711#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1712pub struct ExternKw {
1713 pub(crate) syntax: SyntaxToken,
1714}
1715impl std::fmt::Display for ExternKw {
1716 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1717 std::fmt::Display::fmt(&self.syntax, f)
1718 }
1719}
1720impl AstToken for ExternKw {
1721 fn can_cast(kind: SyntaxKind) -> bool {
1722 match kind {
1723 EXTERN_KW => true,
1724 _ => false,
1725 }
1726 }
1727 fn cast(syntax: SyntaxToken) -> Option<Self> {
1728 if Self::can_cast(syntax.kind()) {
1729 Some(Self { syntax })
1730 } else {
1731 None
1732 }
1733 }
1734 fn syntax(&self) -> &SyntaxToken {
1735 &self.syntax
1736 }
1737}
1738#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1739pub struct FalseKw {
1740 pub(crate) syntax: SyntaxToken,
1741}
1742impl std::fmt::Display for FalseKw {
1743 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1744 std::fmt::Display::fmt(&self.syntax, f)
1745 }
1746}
1747impl AstToken for FalseKw {
1748 fn can_cast(kind: SyntaxKind) -> bool {
1749 match kind {
1750 FALSE_KW => true,
1751 _ => false,
1752 }
1753 }
1754 fn cast(syntax: SyntaxToken) -> Option<Self> {
1755 if Self::can_cast(syntax.kind()) {
1756 Some(Self { syntax })
1757 } else {
1758 None
1759 }
1760 }
1761 fn syntax(&self) -> &SyntaxToken {
1762 &self.syntax
1763 }
1764}
1765#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1766pub struct FnKw {
1767 pub(crate) syntax: SyntaxToken,
1768}
1769impl std::fmt::Display for FnKw {
1770 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1771 std::fmt::Display::fmt(&self.syntax, f)
1772 }
1773}
1774impl AstToken for FnKw {
1775 fn can_cast(kind: SyntaxKind) -> bool {
1776 match kind {
1777 FN_KW => true,
1778 _ => false,
1779 }
1780 }
1781 fn cast(syntax: SyntaxToken) -> Option<Self> {
1782 if Self::can_cast(syntax.kind()) {
1783 Some(Self { syntax })
1784 } else {
1785 None
1786 }
1787 }
1788 fn syntax(&self) -> &SyntaxToken {
1789 &self.syntax
1790 }
1791}
1792#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1793pub struct ForKw {
1794 pub(crate) syntax: SyntaxToken,
1795}
1796impl std::fmt::Display for ForKw {
1797 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1798 std::fmt::Display::fmt(&self.syntax, f)
1799 }
1800}
1801impl AstToken for ForKw {
1802 fn can_cast(kind: SyntaxKind) -> bool {
1803 match kind {
1804 FOR_KW => true,
1805 _ => false,
1806 }
1807 }
1808 fn cast(syntax: SyntaxToken) -> Option<Self> {
1809 if Self::can_cast(syntax.kind()) {
1810 Some(Self { syntax })
1811 } else {
1812 None
1813 }
1814 }
1815 fn syntax(&self) -> &SyntaxToken {
1816 &self.syntax
1817 }
1818}
1819#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1820pub struct IfKw {
1821 pub(crate) syntax: SyntaxToken,
1822}
1823impl std::fmt::Display for IfKw {
1824 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1825 std::fmt::Display::fmt(&self.syntax, f)
1826 }
1827}
1828impl AstToken for IfKw {
1829 fn can_cast(kind: SyntaxKind) -> bool {
1830 match kind {
1831 IF_KW => true,
1832 _ => false,
1833 }
1834 }
1835 fn cast(syntax: SyntaxToken) -> Option<Self> {
1836 if Self::can_cast(syntax.kind()) {
1837 Some(Self { syntax })
1838 } else {
1839 None
1840 }
1841 }
1842 fn syntax(&self) -> &SyntaxToken {
1843 &self.syntax
1844 }
1845}
1846#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1847pub struct ImplKw {
1848 pub(crate) syntax: SyntaxToken,
1849}
1850impl std::fmt::Display for ImplKw {
1851 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1852 std::fmt::Display::fmt(&self.syntax, f)
1853 }
1854}
1855impl AstToken for ImplKw {
1856 fn can_cast(kind: SyntaxKind) -> bool {
1857 match kind {
1858 IMPL_KW => true,
1859 _ => false,
1860 }
1861 }
1862 fn cast(syntax: SyntaxToken) -> Option<Self> {
1863 if Self::can_cast(syntax.kind()) {
1864 Some(Self { syntax })
1865 } else {
1866 None
1867 }
1868 }
1869 fn syntax(&self) -> &SyntaxToken {
1870 &self.syntax
1871 }
1872}
1873#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1874pub struct InKw {
1875 pub(crate) syntax: SyntaxToken,
1876}
1877impl std::fmt::Display for InKw {
1878 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1879 std::fmt::Display::fmt(&self.syntax, f)
1880 }
1881}
1882impl AstToken for InKw {
1883 fn can_cast(kind: SyntaxKind) -> bool {
1884 match kind {
1885 IN_KW => true,
1886 _ => false,
1887 }
1888 }
1889 fn cast(syntax: SyntaxToken) -> Option<Self> {
1890 if Self::can_cast(syntax.kind()) {
1891 Some(Self { syntax })
1892 } else {
1893 None
1894 }
1895 }
1896 fn syntax(&self) -> &SyntaxToken {
1897 &self.syntax
1898 }
1899}
1900#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1901pub struct LetKw {
1902 pub(crate) syntax: SyntaxToken,
1903}
1904impl std::fmt::Display for LetKw {
1905 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1906 std::fmt::Display::fmt(&self.syntax, f)
1907 }
1908}
1909impl AstToken for LetKw {
1910 fn can_cast(kind: SyntaxKind) -> bool {
1911 match kind {
1912 LET_KW => true,
1913 _ => false,
1914 }
1915 }
1916 fn cast(syntax: SyntaxToken) -> Option<Self> {
1917 if Self::can_cast(syntax.kind()) {
1918 Some(Self { syntax })
1919 } else {
1920 None
1921 }
1922 }
1923 fn syntax(&self) -> &SyntaxToken {
1924 &self.syntax
1925 }
1926}
1927#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1928pub struct LoopKw {
1929 pub(crate) syntax: SyntaxToken,
1930}
1931impl std::fmt::Display for LoopKw {
1932 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1933 std::fmt::Display::fmt(&self.syntax, f)
1934 }
1935}
1936impl AstToken for LoopKw {
1937 fn can_cast(kind: SyntaxKind) -> bool {
1938 match kind {
1939 LOOP_KW => true,
1940 _ => false,
1941 }
1942 }
1943 fn cast(syntax: SyntaxToken) -> Option<Self> {
1944 if Self::can_cast(syntax.kind()) {
1945 Some(Self { syntax })
1946 } else {
1947 None
1948 }
1949 }
1950 fn syntax(&self) -> &SyntaxToken {
1951 &self.syntax
1952 }
1953}
1954#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1955pub struct MacroKw {
1956 pub(crate) syntax: SyntaxToken,
1957}
1958impl std::fmt::Display for MacroKw {
1959 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1960 std::fmt::Display::fmt(&self.syntax, f)
1961 }
1962}
1963impl AstToken for MacroKw {
1964 fn can_cast(kind: SyntaxKind) -> bool {
1965 match kind {
1966 MACRO_KW => true,
1967 _ => false,
1968 }
1969 }
1970 fn cast(syntax: SyntaxToken) -> Option<Self> {
1971 if Self::can_cast(syntax.kind()) {
1972 Some(Self { syntax })
1973 } else {
1974 None
1975 }
1976 }
1977 fn syntax(&self) -> &SyntaxToken {
1978 &self.syntax
1979 }
1980}
1981#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1982pub struct MatchKw {
1983 pub(crate) syntax: SyntaxToken,
1984}
1985impl std::fmt::Display for MatchKw {
1986 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1987 std::fmt::Display::fmt(&self.syntax, f)
1988 }
1989}
1990impl AstToken for MatchKw {
1991 fn can_cast(kind: SyntaxKind) -> bool {
1992 match kind {
1993 MATCH_KW => true,
1994 _ => false,
1995 }
1996 }
1997 fn cast(syntax: SyntaxToken) -> Option<Self> {
1998 if Self::can_cast(syntax.kind()) {
1999 Some(Self { syntax })
2000 } else {
2001 None
2002 }
2003 }
2004 fn syntax(&self) -> &SyntaxToken {
2005 &self.syntax
2006 }
2007}
2008#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2009pub struct ModKw {
2010 pub(crate) syntax: SyntaxToken,
2011}
2012impl std::fmt::Display for ModKw {
2013 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2014 std::fmt::Display::fmt(&self.syntax, f)
2015 }
2016}
2017impl AstToken for ModKw {
2018 fn can_cast(kind: SyntaxKind) -> bool {
2019 match kind {
2020 MOD_KW => true,
2021 _ => false,
2022 }
2023 }
2024 fn cast(syntax: SyntaxToken) -> Option<Self> {
2025 if Self::can_cast(syntax.kind()) {
2026 Some(Self { syntax })
2027 } else {
2028 None
2029 }
2030 }
2031 fn syntax(&self) -> &SyntaxToken {
2032 &self.syntax
2033 }
2034}
2035#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2036pub struct MoveKw {
2037 pub(crate) syntax: SyntaxToken,
2038}
2039impl std::fmt::Display for MoveKw {
2040 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2041 std::fmt::Display::fmt(&self.syntax, f)
2042 }
2043}
2044impl AstToken for MoveKw {
2045 fn can_cast(kind: SyntaxKind) -> bool {
2046 match kind {
2047 MOVE_KW => true,
2048 _ => false,
2049 }
2050 }
2051 fn cast(syntax: SyntaxToken) -> Option<Self> {
2052 if Self::can_cast(syntax.kind()) {
2053 Some(Self { syntax })
2054 } else {
2055 None
2056 }
2057 }
2058 fn syntax(&self) -> &SyntaxToken {
2059 &self.syntax
2060 }
2061}
2062#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2063pub struct MutKw {
2064 pub(crate) syntax: SyntaxToken,
2065}
2066impl std::fmt::Display for MutKw {
2067 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2068 std::fmt::Display::fmt(&self.syntax, f)
2069 }
2070}
2071impl AstToken for MutKw {
2072 fn can_cast(kind: SyntaxKind) -> bool {
2073 match kind {
2074 MUT_KW => true,
2075 _ => false,
2076 }
2077 }
2078 fn cast(syntax: SyntaxToken) -> Option<Self> {
2079 if Self::can_cast(syntax.kind()) {
2080 Some(Self { syntax })
2081 } else {
2082 None
2083 }
2084 }
2085 fn syntax(&self) -> &SyntaxToken {
2086 &self.syntax
2087 }
2088}
2089#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2090pub struct PubKw {
2091 pub(crate) syntax: SyntaxToken,
2092}
2093impl std::fmt::Display for PubKw {
2094 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2095 std::fmt::Display::fmt(&self.syntax, f)
2096 }
2097}
2098impl AstToken for PubKw {
2099 fn can_cast(kind: SyntaxKind) -> bool {
2100 match kind {
2101 PUB_KW => true,
2102 _ => false,
2103 }
2104 }
2105 fn cast(syntax: SyntaxToken) -> Option<Self> {
2106 if Self::can_cast(syntax.kind()) {
2107 Some(Self { syntax })
2108 } else {
2109 None
2110 }
2111 }
2112 fn syntax(&self) -> &SyntaxToken {
2113 &self.syntax
2114 }
2115}
2116#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2117pub struct RefKw {
2118 pub(crate) syntax: SyntaxToken,
2119}
2120impl std::fmt::Display for RefKw {
2121 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2122 std::fmt::Display::fmt(&self.syntax, f)
2123 }
2124}
2125impl AstToken for RefKw {
2126 fn can_cast(kind: SyntaxKind) -> bool {
2127 match kind {
2128 REF_KW => true,
2129 _ => false,
2130 }
2131 }
2132 fn cast(syntax: SyntaxToken) -> Option<Self> {
2133 if Self::can_cast(syntax.kind()) {
2134 Some(Self { syntax })
2135 } else {
2136 None
2137 }
2138 }
2139 fn syntax(&self) -> &SyntaxToken {
2140 &self.syntax
2141 }
2142}
2143#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2144pub struct ReturnKw {
2145 pub(crate) syntax: SyntaxToken,
2146}
2147impl std::fmt::Display for ReturnKw {
2148 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2149 std::fmt::Display::fmt(&self.syntax, f)
2150 }
2151}
2152impl AstToken for ReturnKw {
2153 fn can_cast(kind: SyntaxKind) -> bool {
2154 match kind {
2155 RETURN_KW => true,
2156 _ => false,
2157 }
2158 }
2159 fn cast(syntax: SyntaxToken) -> Option<Self> {
2160 if Self::can_cast(syntax.kind()) {
2161 Some(Self { syntax })
2162 } else {
2163 None
2164 }
2165 }
2166 fn syntax(&self) -> &SyntaxToken {
2167 &self.syntax
2168 }
2169}
2170#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2171pub struct SelfKw {
2172 pub(crate) syntax: SyntaxToken,
2173}
2174impl std::fmt::Display for SelfKw {
2175 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2176 std::fmt::Display::fmt(&self.syntax, f)
2177 }
2178}
2179impl AstToken for SelfKw {
2180 fn can_cast(kind: SyntaxKind) -> bool {
2181 match kind {
2182 SELF_KW => true,
2183 _ => false,
2184 }
2185 }
2186 fn cast(syntax: SyntaxToken) -> Option<Self> {
2187 if Self::can_cast(syntax.kind()) {
2188 Some(Self { syntax })
2189 } else {
2190 None
2191 }
2192 }
2193 fn syntax(&self) -> &SyntaxToken {
2194 &self.syntax
2195 }
2196}
2197#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2198pub struct StaticKw {
2199 pub(crate) syntax: SyntaxToken,
2200}
2201impl std::fmt::Display for StaticKw {
2202 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2203 std::fmt::Display::fmt(&self.syntax, f)
2204 }
2205}
2206impl AstToken for StaticKw {
2207 fn can_cast(kind: SyntaxKind) -> bool {
2208 match kind {
2209 STATIC_KW => true,
2210 _ => false,
2211 }
2212 }
2213 fn cast(syntax: SyntaxToken) -> Option<Self> {
2214 if Self::can_cast(syntax.kind()) {
2215 Some(Self { syntax })
2216 } else {
2217 None
2218 }
2219 }
2220 fn syntax(&self) -> &SyntaxToken {
2221 &self.syntax
2222 }
2223}
2224#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2225pub struct StructKw {
2226 pub(crate) syntax: SyntaxToken,
2227}
2228impl std::fmt::Display for StructKw {
2229 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2230 std::fmt::Display::fmt(&self.syntax, f)
2231 }
2232}
2233impl AstToken for StructKw {
2234 fn can_cast(kind: SyntaxKind) -> bool {
2235 match kind {
2236 STRUCT_KW => true,
2237 _ => false,
2238 }
2239 }
2240 fn cast(syntax: SyntaxToken) -> Option<Self> {
2241 if Self::can_cast(syntax.kind()) {
2242 Some(Self { syntax })
2243 } else {
2244 None
2245 }
2246 }
2247 fn syntax(&self) -> &SyntaxToken {
2248 &self.syntax
2249 }
2250}
2251#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2252pub struct SuperKw {
2253 pub(crate) syntax: SyntaxToken,
2254}
2255impl std::fmt::Display for SuperKw {
2256 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2257 std::fmt::Display::fmt(&self.syntax, f)
2258 }
2259}
2260impl AstToken for SuperKw {
2261 fn can_cast(kind: SyntaxKind) -> bool {
2262 match kind {
2263 SUPER_KW => true,
2264 _ => false,
2265 }
2266 }
2267 fn cast(syntax: SyntaxToken) -> Option<Self> {
2268 if Self::can_cast(syntax.kind()) {
2269 Some(Self { syntax })
2270 } else {
2271 None
2272 }
2273 }
2274 fn syntax(&self) -> &SyntaxToken {
2275 &self.syntax
2276 }
2277}
2278#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2279pub struct TraitKw {
2280 pub(crate) syntax: SyntaxToken,
2281}
2282impl std::fmt::Display for TraitKw {
2283 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2284 std::fmt::Display::fmt(&self.syntax, f)
2285 }
2286}
2287impl AstToken for TraitKw {
2288 fn can_cast(kind: SyntaxKind) -> bool {
2289 match kind {
2290 TRAIT_KW => true,
2291 _ => false,
2292 }
2293 }
2294 fn cast(syntax: SyntaxToken) -> Option<Self> {
2295 if Self::can_cast(syntax.kind()) {
2296 Some(Self { syntax })
2297 } else {
2298 None
2299 }
2300 }
2301 fn syntax(&self) -> &SyntaxToken {
2302 &self.syntax
2303 }
2304}
2305#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2306pub struct TrueKw {
2307 pub(crate) syntax: SyntaxToken,
2308}
2309impl std::fmt::Display for TrueKw {
2310 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2311 std::fmt::Display::fmt(&self.syntax, f)
2312 }
2313}
2314impl AstToken for TrueKw {
2315 fn can_cast(kind: SyntaxKind) -> bool {
2316 match kind {
2317 TRUE_KW => true,
2318 _ => false,
2319 }
2320 }
2321 fn cast(syntax: SyntaxToken) -> Option<Self> {
2322 if Self::can_cast(syntax.kind()) {
2323 Some(Self { syntax })
2324 } else {
2325 None
2326 }
2327 }
2328 fn syntax(&self) -> &SyntaxToken {
2329 &self.syntax
2330 }
2331}
2332#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2333pub struct TryKw {
2334 pub(crate) syntax: SyntaxToken,
2335}
2336impl std::fmt::Display for TryKw {
2337 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2338 std::fmt::Display::fmt(&self.syntax, f)
2339 }
2340}
2341impl AstToken for TryKw {
2342 fn can_cast(kind: SyntaxKind) -> bool {
2343 match kind {
2344 TRY_KW => true,
2345 _ => false,
2346 }
2347 }
2348 fn cast(syntax: SyntaxToken) -> Option<Self> {
2349 if Self::can_cast(syntax.kind()) {
2350 Some(Self { syntax })
2351 } else {
2352 None
2353 }
2354 }
2355 fn syntax(&self) -> &SyntaxToken {
2356 &self.syntax
2357 }
2358}
2359#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2360pub struct TypeKw {
2361 pub(crate) syntax: SyntaxToken,
2362}
2363impl std::fmt::Display for TypeKw {
2364 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2365 std::fmt::Display::fmt(&self.syntax, f)
2366 }
2367}
2368impl AstToken for TypeKw {
2369 fn can_cast(kind: SyntaxKind) -> bool {
2370 match kind {
2371 TYPE_KW => true,
2372 _ => false,
2373 }
2374 }
2375 fn cast(syntax: SyntaxToken) -> Option<Self> {
2376 if Self::can_cast(syntax.kind()) {
2377 Some(Self { syntax })
2378 } else {
2379 None
2380 }
2381 }
2382 fn syntax(&self) -> &SyntaxToken {
2383 &self.syntax
2384 }
2385}
2386#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2387pub struct UnsafeKw {
2388 pub(crate) syntax: SyntaxToken,
2389}
2390impl std::fmt::Display for UnsafeKw {
2391 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2392 std::fmt::Display::fmt(&self.syntax, f)
2393 }
2394}
2395impl AstToken for UnsafeKw {
2396 fn can_cast(kind: SyntaxKind) -> bool {
2397 match kind {
2398 UNSAFE_KW => true,
2399 _ => false,
2400 }
2401 }
2402 fn cast(syntax: SyntaxToken) -> Option<Self> {
2403 if Self::can_cast(syntax.kind()) {
2404 Some(Self { syntax })
2405 } else {
2406 None
2407 }
2408 }
2409 fn syntax(&self) -> &SyntaxToken {
2410 &self.syntax
2411 }
2412}
2413#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2414pub struct UseKw {
2415 pub(crate) syntax: SyntaxToken,
2416}
2417impl std::fmt::Display for UseKw {
2418 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2419 std::fmt::Display::fmt(&self.syntax, f)
2420 }
2421}
2422impl AstToken for UseKw {
2423 fn can_cast(kind: SyntaxKind) -> bool {
2424 match kind {
2425 USE_KW => true,
2426 _ => false,
2427 }
2428 }
2429 fn cast(syntax: SyntaxToken) -> Option<Self> {
2430 if Self::can_cast(syntax.kind()) {
2431 Some(Self { syntax })
2432 } else {
2433 None
2434 }
2435 }
2436 fn syntax(&self) -> &SyntaxToken {
2437 &self.syntax
2438 }
2439}
2440#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2441pub struct WhereKw {
2442 pub(crate) syntax: SyntaxToken,
2443}
2444impl std::fmt::Display for WhereKw {
2445 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2446 std::fmt::Display::fmt(&self.syntax, f)
2447 }
2448}
2449impl AstToken for WhereKw {
2450 fn can_cast(kind: SyntaxKind) -> bool {
2451 match kind {
2452 WHERE_KW => true,
2453 _ => false,
2454 }
2455 }
2456 fn cast(syntax: SyntaxToken) -> Option<Self> {
2457 if Self::can_cast(syntax.kind()) {
2458 Some(Self { syntax })
2459 } else {
2460 None
2461 }
2462 }
2463 fn syntax(&self) -> &SyntaxToken {
2464 &self.syntax
2465 }
2466}
2467#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2468pub struct WhileKw {
2469 pub(crate) syntax: SyntaxToken,
2470}
2471impl std::fmt::Display for WhileKw {
2472 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2473 std::fmt::Display::fmt(&self.syntax, f)
2474 }
2475}
2476impl AstToken for WhileKw {
2477 fn can_cast(kind: SyntaxKind) -> bool {
2478 match kind {
2479 WHILE_KW => true,
2480 _ => false,
2481 }
2482 }
2483 fn cast(syntax: SyntaxToken) -> Option<Self> {
2484 if Self::can_cast(syntax.kind()) {
2485 Some(Self { syntax })
2486 } else {
2487 None
2488 }
2489 }
2490 fn syntax(&self) -> &SyntaxToken {
2491 &self.syntax
2492 }
2493}
2494#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2495pub struct AutoKw {
2496 pub(crate) syntax: SyntaxToken,
2497}
2498impl std::fmt::Display for AutoKw {
2499 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2500 std::fmt::Display::fmt(&self.syntax, f)
2501 }
2502}
2503impl AstToken for AutoKw {
2504 fn can_cast(kind: SyntaxKind) -> bool {
2505 match kind {
2506 AUTO_KW => true,
2507 _ => false,
2508 }
2509 }
2510 fn cast(syntax: SyntaxToken) -> Option<Self> {
2511 if Self::can_cast(syntax.kind()) {
2512 Some(Self { syntax })
2513 } else {
2514 None
2515 }
2516 }
2517 fn syntax(&self) -> &SyntaxToken {
2518 &self.syntax
2519 }
2520}
2521#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2522pub struct DefaultKw {
2523 pub(crate) syntax: SyntaxToken,
2524}
2525impl std::fmt::Display for DefaultKw {
2526 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2527 std::fmt::Display::fmt(&self.syntax, f)
2528 }
2529}
2530impl AstToken for DefaultKw {
2531 fn can_cast(kind: SyntaxKind) -> bool {
2532 match kind {
2533 DEFAULT_KW => true,
2534 _ => false,
2535 }
2536 }
2537 fn cast(syntax: SyntaxToken) -> Option<Self> {
2538 if Self::can_cast(syntax.kind()) {
2539 Some(Self { syntax })
2540 } else {
2541 None
2542 }
2543 }
2544 fn syntax(&self) -> &SyntaxToken {
2545 &self.syntax
2546 }
2547}
2548#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2549pub struct ExistentialKw {
2550 pub(crate) syntax: SyntaxToken,
2551}
2552impl std::fmt::Display for ExistentialKw {
2553 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2554 std::fmt::Display::fmt(&self.syntax, f)
2555 }
2556}
2557impl AstToken for ExistentialKw {
2558 fn can_cast(kind: SyntaxKind) -> bool {
2559 match kind {
2560 EXISTENTIAL_KW => true,
2561 _ => false,
2562 }
2563 }
2564 fn cast(syntax: SyntaxToken) -> Option<Self> {
2565 if Self::can_cast(syntax.kind()) {
2566 Some(Self { syntax })
2567 } else {
2568 None
2569 }
2570 }
2571 fn syntax(&self) -> &SyntaxToken {
2572 &self.syntax
2573 }
2574}
2575#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2576pub struct UnionKw {
2577 pub(crate) syntax: SyntaxToken,
2578}
2579impl std::fmt::Display for UnionKw {
2580 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2581 std::fmt::Display::fmt(&self.syntax, f)
2582 }
2583}
2584impl AstToken for UnionKw {
2585 fn can_cast(kind: SyntaxKind) -> bool {
2586 match kind {
2587 UNION_KW => true,
2588 _ => false,
2589 }
2590 }
2591 fn cast(syntax: SyntaxToken) -> Option<Self> {
2592 if Self::can_cast(syntax.kind()) {
2593 Some(Self { syntax })
2594 } else {
2595 None
2596 }
2597 }
2598 fn syntax(&self) -> &SyntaxToken {
2599 &self.syntax
2600 }
2601}
2602#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2603pub struct IntNumber {
2604 pub(crate) syntax: SyntaxToken,
2605}
2606impl std::fmt::Display for IntNumber {
2607 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2608 std::fmt::Display::fmt(&self.syntax, f)
2609 }
2610}
2611impl AstToken for IntNumber {
2612 fn can_cast(kind: SyntaxKind) -> bool {
2613 match kind {
2614 INT_NUMBER => true,
2615 _ => false,
2616 }
2617 }
2618 fn cast(syntax: SyntaxToken) -> Option<Self> {
2619 if Self::can_cast(syntax.kind()) {
2620 Some(Self { syntax })
2621 } else {
2622 None
2623 }
2624 }
2625 fn syntax(&self) -> &SyntaxToken {
2626 &self.syntax
2627 }
2628}
2629#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2630pub struct FloatNumber {
2631 pub(crate) syntax: SyntaxToken,
2632}
2633impl std::fmt::Display for FloatNumber {
2634 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2635 std::fmt::Display::fmt(&self.syntax, f)
2636 }
2637}
2638impl AstToken for FloatNumber {
2639 fn can_cast(kind: SyntaxKind) -> bool {
2640 match kind {
2641 FLOAT_NUMBER => true,
2642 _ => false,
2643 }
2644 }
2645 fn cast(syntax: SyntaxToken) -> Option<Self> {
2646 if Self::can_cast(syntax.kind()) {
2647 Some(Self { syntax })
2648 } else {
2649 None
2650 }
2651 }
2652 fn syntax(&self) -> &SyntaxToken {
2653 &self.syntax
2654 }
2655}
2656#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2657pub struct Char {
2658 pub(crate) syntax: SyntaxToken,
2659}
2660impl std::fmt::Display for Char {
2661 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2662 std::fmt::Display::fmt(&self.syntax, f)
2663 }
2664}
2665impl AstToken for Char {
2666 fn can_cast(kind: SyntaxKind) -> bool {
2667 match kind {
2668 CHAR => true,
2669 _ => false,
2670 }
2671 }
2672 fn cast(syntax: SyntaxToken) -> Option<Self> {
2673 if Self::can_cast(syntax.kind()) {
2674 Some(Self { syntax })
2675 } else {
2676 None
2677 }
2678 }
2679 fn syntax(&self) -> &SyntaxToken {
2680 &self.syntax
2681 }
2682}
2683#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2684pub struct Byte {
2685 pub(crate) syntax: SyntaxToken,
2686}
2687impl std::fmt::Display for Byte {
2688 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2689 std::fmt::Display::fmt(&self.syntax, f)
2690 }
2691}
2692impl AstToken for Byte {
2693 fn can_cast(kind: SyntaxKind) -> bool {
2694 match kind {
2695 BYTE => true,
2696 _ => false,
2697 }
2698 }
2699 fn cast(syntax: SyntaxToken) -> Option<Self> {
2700 if Self::can_cast(syntax.kind()) {
2701 Some(Self { syntax })
2702 } else {
2703 None
2704 }
2705 }
2706 fn syntax(&self) -> &SyntaxToken {
2707 &self.syntax
2708 }
2709}
2710#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2711pub struct String {
2712 pub(crate) syntax: SyntaxToken,
2713}
2714impl std::fmt::Display for String {
2715 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2716 std::fmt::Display::fmt(&self.syntax, f)
2717 }
2718}
2719impl AstToken for String {
2720 fn can_cast(kind: SyntaxKind) -> bool {
2721 match kind {
2722 STRING => true,
2723 _ => false,
2724 }
2725 }
2726 fn cast(syntax: SyntaxToken) -> Option<Self> {
2727 if Self::can_cast(syntax.kind()) {
2728 Some(Self { syntax })
2729 } else {
2730 None
2731 }
2732 }
2733 fn syntax(&self) -> &SyntaxToken {
2734 &self.syntax
2735 }
2736}
2737#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2738pub struct RawString {
2739 pub(crate) syntax: SyntaxToken,
2740}
2741impl std::fmt::Display for RawString {
2742 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2743 std::fmt::Display::fmt(&self.syntax, f)
2744 }
2745}
2746impl AstToken for RawString {
2747 fn can_cast(kind: SyntaxKind) -> bool {
2748 match kind {
2749 RAW_STRING => true,
2750 _ => false,
2751 }
2752 }
2753 fn cast(syntax: SyntaxToken) -> Option<Self> {
2754 if Self::can_cast(syntax.kind()) {
2755 Some(Self { syntax })
2756 } else {
2757 None
2758 }
2759 }
2760 fn syntax(&self) -> &SyntaxToken {
2761 &self.syntax
2762 }
2763}
2764#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2765pub struct ByteString {
2766 pub(crate) syntax: SyntaxToken,
2767}
2768impl std::fmt::Display for ByteString {
2769 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2770 std::fmt::Display::fmt(&self.syntax, f)
2771 }
2772}
2773impl AstToken for ByteString {
2774 fn can_cast(kind: SyntaxKind) -> bool {
2775 match kind {
2776 BYTE_STRING => true,
2777 _ => false,
2778 }
2779 }
2780 fn cast(syntax: SyntaxToken) -> Option<Self> {
2781 if Self::can_cast(syntax.kind()) {
2782 Some(Self { syntax })
2783 } else {
2784 None
2785 }
2786 }
2787 fn syntax(&self) -> &SyntaxToken {
2788 &self.syntax
2789 }
2790}
2791#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2792pub struct RawByteString {
2793 pub(crate) syntax: SyntaxToken,
2794}
2795impl std::fmt::Display for RawByteString {
2796 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2797 std::fmt::Display::fmt(&self.syntax, f)
2798 }
2799}
2800impl AstToken for RawByteString {
2801 fn can_cast(kind: SyntaxKind) -> bool {
2802 match kind {
2803 RAW_BYTE_STRING => true,
2804 _ => false,
2805 }
2806 }
2807 fn cast(syntax: SyntaxToken) -> Option<Self> {
2808 if Self::can_cast(syntax.kind()) {
2809 Some(Self { syntax })
2810 } else {
2811 None
2812 }
2813 }
2814 fn syntax(&self) -> &SyntaxToken {
2815 &self.syntax
2816 }
2817}
2818#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2819pub struct Error {
2820 pub(crate) syntax: SyntaxToken,
2821}
2822impl std::fmt::Display for Error {
2823 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2824 std::fmt::Display::fmt(&self.syntax, f)
2825 }
2826}
2827impl AstToken for Error {
2828 fn can_cast(kind: SyntaxKind) -> bool {
2829 match kind {
2830 ERROR => true,
2831 _ => false,
2832 }
2833 }
2834 fn cast(syntax: SyntaxToken) -> Option<Self> {
2835 if Self::can_cast(syntax.kind()) {
2836 Some(Self { syntax })
2837 } else {
2838 None
2839 }
2840 }
2841 fn syntax(&self) -> &SyntaxToken {
2842 &self.syntax
2843 }
2844}
2845#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2846pub struct Ident {
2847 pub(crate) syntax: SyntaxToken,
2848}
2849impl std::fmt::Display for Ident {
2850 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2851 std::fmt::Display::fmt(&self.syntax, f)
2852 }
2853}
2854impl AstToken for Ident {
2855 fn can_cast(kind: SyntaxKind) -> bool {
2856 match kind {
2857 IDENT => true,
2858 _ => false,
2859 }
2860 }
2861 fn cast(syntax: SyntaxToken) -> Option<Self> {
2862 if Self::can_cast(syntax.kind()) {
2863 Some(Self { syntax })
2864 } else {
2865 None
2866 }
2867 }
2868 fn syntax(&self) -> &SyntaxToken {
2869 &self.syntax
2870 }
2871}
2872#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2873pub struct Whitespace {
2874 pub(crate) syntax: SyntaxToken,
2875}
2876impl std::fmt::Display for Whitespace {
2877 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2878 std::fmt::Display::fmt(&self.syntax, f)
2879 }
2880}
2881impl AstToken for Whitespace {
2882 fn can_cast(kind: SyntaxKind) -> bool {
2883 match kind {
2884 WHITESPACE => true,
2885 _ => false,
2886 }
2887 }
2888 fn cast(syntax: SyntaxToken) -> Option<Self> {
2889 if Self::can_cast(syntax.kind()) {
2890 Some(Self { syntax })
2891 } else {
2892 None
2893 }
2894 }
2895 fn syntax(&self) -> &SyntaxToken {
2896 &self.syntax
2897 }
2898}
2899#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2900pub struct Lifetime {
2901 pub(crate) syntax: SyntaxToken,
2902}
2903impl std::fmt::Display for Lifetime {
2904 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2905 std::fmt::Display::fmt(&self.syntax, f)
2906 }
2907}
2908impl AstToken for Lifetime {
2909 fn can_cast(kind: SyntaxKind) -> bool {
2910 match kind {
2911 LIFETIME => true,
2912 _ => false,
2913 }
2914 }
2915 fn cast(syntax: SyntaxToken) -> Option<Self> {
2916 if Self::can_cast(syntax.kind()) {
2917 Some(Self { syntax })
2918 } else {
2919 None
2920 }
2921 }
2922 fn syntax(&self) -> &SyntaxToken {
2923 &self.syntax
2924 }
2925}
2926#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2927pub struct Comment {
2928 pub(crate) syntax: SyntaxToken,
2929}
2930impl std::fmt::Display for Comment {
2931 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2932 std::fmt::Display::fmt(&self.syntax, f)
2933 }
2934}
2935impl AstToken for Comment {
2936 fn can_cast(kind: SyntaxKind) -> bool {
2937 match kind {
2938 COMMENT => true,
2939 _ => false,
2940 }
2941 }
2942 fn cast(syntax: SyntaxToken) -> Option<Self> {
2943 if Self::can_cast(syntax.kind()) {
2944 Some(Self { syntax })
2945 } else {
2946 None
2947 }
2948 }
2949 fn syntax(&self) -> &SyntaxToken {
2950 &self.syntax
2951 }
2952}
2953#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2954pub struct Shebang {
2955 pub(crate) syntax: SyntaxToken,
2956}
2957impl std::fmt::Display for Shebang {
2958 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2959 std::fmt::Display::fmt(&self.syntax, f)
2960 }
2961}
2962impl AstToken for Shebang {
2963 fn can_cast(kind: SyntaxKind) -> bool {
2964 match kind {
2965 SHEBANG => true,
2966 _ => false,
2967 }
2968 }
2969 fn cast(syntax: SyntaxToken) -> Option<Self> {
2970 if Self::can_cast(syntax.kind()) {
2971 Some(Self { syntax })
2972 } else {
2973 None
2974 }
2975 }
2976 fn syntax(&self) -> &SyntaxToken {
2977 &self.syntax
2978 }
2979}
2980#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2981pub struct LDollar {
2982 pub(crate) syntax: SyntaxToken,
2983}
2984impl std::fmt::Display for LDollar {
2985 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2986 std::fmt::Display::fmt(&self.syntax, f)
2987 }
2988}
2989impl AstToken for LDollar {
2990 fn can_cast(kind: SyntaxKind) -> bool {
2991 match kind {
2992 L_DOLLAR => true,
2993 _ => false,
2994 }
2995 }
2996 fn cast(syntax: SyntaxToken) -> Option<Self> {
2997 if Self::can_cast(syntax.kind()) {
2998 Some(Self { syntax })
2999 } else {
3000 None
3001 }
3002 }
3003 fn syntax(&self) -> &SyntaxToken {
3004 &self.syntax
3005 }
3006}
3007#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3008pub struct RDollar {
3009 pub(crate) syntax: SyntaxToken,
3010}
3011impl std::fmt::Display for RDollar {
3012 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
3013 std::fmt::Display::fmt(&self.syntax, f)
3014 }
3015}
3016impl AstToken for RDollar {
3017 fn can_cast(kind: SyntaxKind) -> bool {
3018 match kind {
3019 R_DOLLAR => true,
3020 _ => false,
3021 }
3022 }
3023 fn cast(syntax: SyntaxToken) -> Option<Self> {
3024 if Self::can_cast(syntax.kind()) {
3025 Some(Self { syntax })
3026 } else {
3027 None
3028 }
3029 }
3030 fn syntax(&self) -> &SyntaxToken {
3031 &self.syntax
3032 }
3033}
3034#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9pub struct SourceFile { 3035pub struct SourceFile {
10 pub(crate) syntax: SyntaxNode, 3036 pub(crate) syntax: SyntaxNode,
11} 3037}
diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs
index c730c75ee..2dfb68371 100644
--- a/xtask/src/codegen/gen_syntax.rs
+++ b/xtask/src/codegen/gen_syntax.rs
@@ -97,11 +97,13 @@ fn generate_ast(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
97 let name = format_ident!("{}", to_pascal_case(kind_str)); 97 let name = format_ident!("{}", to_pascal_case(kind_str));
98 quote! { 98 quote! {
99 #[derive(Debug, Clone, PartialEq, Eq, Hash)] 99 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
100 pub struct #name(SyntaxToken); 100 pub struct #name {
101 pub(crate) syntax: SyntaxToken,
102 }
101 103
102 impl std::fmt::Display for #name { 104 impl std::fmt::Display for #name {
103 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 105 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
104 std::fmt::Display::fmt(self.syntax(), f) 106 std::fmt::Display::fmt(&self.syntax, f)
105 } 107 }
106 } 108 }
107 109
@@ -112,29 +114,10 @@ fn generate_ast(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
112 _ => false, 114 _ => false,
113 } 115 }
114 } 116 }
115 fn cast_or_return(syntax: SyntaxToken) -> Result<Self, SyntaxToken> { 117 fn cast(syntax: SyntaxToken) -> Option<Self> {
116 if Self::can_cast(syntax.kind()) { Ok(Self(syntax)) } else { Err(syntax) } 118 if Self::can_cast(syntax.kind()) { Some(Self { syntax }) } else { None }
117 }
118 fn syntax(&self) -> &SyntaxToken { &self.0 }
119 fn into_syntax(self) -> SyntaxToken { self.0 }
120 }
121
122 impl AstElement for #name {
123 fn can_cast_element(kind: SyntaxKind) -> bool {
124 match kind {
125 #kind => true,
126 _ => false,
127 }
128 }
129 fn cast_or_return_element(syntax: SyntaxElement) -> Result<Self, SyntaxElement> {
130 if Self::can_cast_element(syntax.kind()) { Ok(Self(syntax.into_token().unwrap())) } else { Err(syntax) }
131 }
132 fn syntax_element(&self) -> NodeOrToken<&SyntaxNode, &SyntaxToken> {
133 NodeOrToken::Token(&self.0)
134 }
135 fn into_syntax_element(self) -> SyntaxElement {
136 NodeOrToken::Token(self.0)
137 } 119 }
120 fn syntax(&self) -> &SyntaxToken { &self.syntax }
138 } 121 }
139 } 122 }
140 }); 123 });
@@ -156,28 +139,21 @@ fn generate_ast(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
156 FieldSrc::Optional(ty) | FieldSrc::Many(ty) => ty, 139 FieldSrc::Optional(ty) | FieldSrc::Many(ty) => ty,
157 FieldSrc::Shorthand => name, 140 FieldSrc::Shorthand => name,
158 }; 141 };
159 let element_kinds = &element_kinds_map.get(*ty).unwrap_or_else(|| panic!("type not found: {}", *ty)); 142
160 let iter = if !element_kinds.has_tokens {
161 format_ident!("AstChildren")
162 } else if !element_kinds.has_nodes {
163 format_ident!("AstChildTokens")
164 } else {
165 format_ident!("AstChildElements")
166 };
167 let ty = format_ident!("{}", ty); 143 let ty = format_ident!("{}", ty);
168 144
169 match field { 145 match field {
170 FieldSrc::Many(_) => { 146 FieldSrc::Many(_) => {
171 quote! { 147 quote! {
172 pub fn #method_name(&self) -> #iter<#ty> { 148 pub fn #method_name(&self) -> AstChildren<#ty> {
173 #iter::new(&self.syntax) 149 AstChildren::new(&self.syntax)
174 } 150 }
175 } 151 }
176 } 152 }
177 FieldSrc::Optional(_) | FieldSrc::Shorthand => { 153 FieldSrc::Optional(_) | FieldSrc::Shorthand => {
178 quote! { 154 quote! {
179 pub fn #method_name(&self) -> Option<#ty> { 155 pub fn #method_name(&self) -> Option<#ty> {
180 #iter::new(&self.syntax).next() 156 AstChildren::new(&self.syntax).next()
181 } 157 }
182 } 158 }
183 } 159 }
@@ -203,29 +179,10 @@ fn generate_ast(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
203 _ => false, 179 _ => false,
204 } 180 }
205 } 181 }
206 fn cast_or_return(syntax: SyntaxNode) -> Result<Self, SyntaxNode> { 182 fn cast(syntax: SyntaxNode) -> Option<Self> {
207 if Self::can_cast(syntax.kind()) { Ok(Self { syntax }) } else { Err(syntax) } 183 if Self::can_cast(syntax.kind()) { Some(Self { syntax }) } else { None }
208 } 184 }
209 fn syntax(&self) -> &SyntaxNode { &self.syntax } 185 fn syntax(&self) -> &SyntaxNode { &self.syntax }
210 fn into_syntax(self) -> SyntaxNode { self.syntax }
211 }
212
213 impl AstElement for #name {
214 fn can_cast_element(kind: SyntaxKind) -> bool {
215 match kind {
216 #kind => true,
217 _ => false,
218 }
219 }
220 fn cast_or_return_element(syntax: SyntaxElement) -> Result<Self, SyntaxElement> {
221 if Self::can_cast_element(syntax.kind()) { Ok(Self { syntax: syntax.into_node().unwrap() }) } else { Err(syntax) }
222 }
223 fn syntax_element(&self) -> NodeOrToken<&SyntaxNode, &SyntaxToken> {
224 NodeOrToken::Node(&self.syntax)
225 }
226 fn into_syntax_element(self) -> SyntaxElement {
227 NodeOrToken::Node(self.syntax)
228 }
229 } 186 }
230 187
231 #(#traits)* 188 #(#traits)*
@@ -238,71 +195,16 @@ fn generate_ast(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
238 195
239 let enums = grammar.enums.iter().map(|en| { 196 let enums = grammar.enums.iter().map(|en| {
240 let variants = en.variants.iter().map(|var| format_ident!("{}", var)).collect::<Vec<_>>(); 197 let variants = en.variants.iter().map(|var| format_ident!("{}", var)).collect::<Vec<_>>();
241 let element_kinds = &element_kinds_map[&en.name.to_string()];
242 let name = format_ident!("{}", en.name); 198 let name = format_ident!("{}", en.name);
243 let kinds = en.variants 199 let kinds = variants
244 .iter() 200 .iter()
245 .map(|name| { 201 .map(|name| format_ident!("{}", to_upper_snake_case(&name.to_string())))
246 element_kinds_map[*name].kinds.iter().collect::<Vec<_>>()
247 })
248 .collect::<Vec<_>>(); 202 .collect::<Vec<_>>();
249 let traits = en.traits.iter().map(|trait_name| { 203 let traits = en.traits.iter().map(|trait_name| {
250 let trait_name = format_ident!("{}", trait_name); 204 let trait_name = format_ident!("{}", trait_name);
251 quote!(impl ast::#trait_name for #name {}) 205 quote!(impl ast::#trait_name for #name {})
252 }); 206 });
253 207
254 let all_kinds = &element_kinds.kinds;
255
256 let specific_ast_trait = if element_kinds.has_nodes != element_kinds.has_tokens {
257 let (ast_trait, syntax_type) = if element_kinds.has_tokens {
258 (
259 quote!(AstToken),
260 quote!(SyntaxToken),
261 )
262 } else {
263 (
264 quote!(AstNode),
265 quote!(SyntaxNode),
266 )
267 };
268
269 quote! {
270 impl #ast_trait for #name {
271 fn can_cast(kind: SyntaxKind) -> bool {
272 match kind {
273 #(#all_kinds)|* => true,
274 _ => false,
275 }
276 }
277 #[allow(unreachable_patterns)]
278 fn cast_or_return(syntax: #syntax_type) -> Result<Self, #syntax_type> {
279 match syntax.kind() {
280 #(
281 #(#kinds)|* => #variants::cast_or_return(syntax).map(|x| #name::#variants(x)),
282 )*
283 _ => Err(syntax),
284 }
285 }
286 fn syntax(&self) -> &#syntax_type {
287 match self {
288 #(
289 #name::#variants(it) => it.syntax(),
290 )*
291 }
292 }
293 fn into_syntax(self) -> #syntax_type {
294 match self {
295 #(
296 #name::#variants(it) => it.into_syntax(),
297 )*
298 }
299 }
300 }
301 }
302 } else {
303 Default::default()
304 };
305
306 quote! { 208 quote! {
307 #[derive(Debug, Clone, PartialEq, Eq, Hash)] 209 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
308 pub enum #name { 210 pub enum #name {
@@ -319,48 +221,34 @@ fn generate_ast(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
319 221
320 impl std::fmt::Display for #name { 222 impl std::fmt::Display for #name {
321 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 223 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
322 match self { 224 std::fmt::Display::fmt(self.syntax(), f)
323 #(
324 #name::#variants(it) => std::fmt::Display::fmt(it, f),
325 )*
326 }
327 } 225 }
328 } 226 }
329 227
330 #specific_ast_trait 228 impl AstNode for #name {
331 229 fn can_cast(kind: SyntaxKind) -> bool {
332 impl AstElement for #name {
333 fn can_cast_element(kind: SyntaxKind) -> bool {
334 match kind { 230 match kind {
335 #(#all_kinds)|* => true, 231 #(#kinds)|* => true,
336 _ => false, 232 _ => false,
337 } 233 }
338 } 234 }
339 #[allow(unreachable_patterns)] 235 fn cast(syntax: SyntaxNode) -> Option<Self> {
340 fn cast_or_return_element(syntax: SyntaxElement) -> Result<Self, SyntaxElement> { 236 let res = match syntax.kind() {
341 match syntax.kind() {
342 #( 237 #(
343 #(#kinds)|* => #variants::cast_or_return_element(syntax).map(|x| #name::#variants(x)), 238 #kinds => #name::#variants(#variants { syntax }),
344 )* 239 )*
345 _ => Err(syntax), 240 _ => return None,
346 } 241 };
242 Some(res)
347 } 243 }
348 fn syntax_element(&self) -> NodeOrToken<&SyntaxNode, &SyntaxToken> { 244 fn syntax(&self) -> &SyntaxNode {
349 match self { 245 match self {
350 #( 246 #(
351 #name::#variants(it) => it.syntax_element(), 247 #name::#variants(it) => &it.syntax,
352 )*
353 }
354 }
355 fn into_syntax_element(self) -> SyntaxElement {
356 match self {
357 #(
358 #name::#variants(it) => it.into_syntax_element(),
359 )* 248 )*
360 } 249 }
361 } 250 }
362 } 251 }
363
364 #(#traits)* 252 #(#traits)*
365 } 253 }
366 }); 254 });
@@ -380,7 +268,7 @@ fn generate_ast(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
380 #[allow(unused_imports)] 268 #[allow(unused_imports)]
381 use crate::{ 269 use crate::{
382 SyntaxNode, SyntaxToken, SyntaxElement, NodeOrToken, SyntaxKind::{self, *}, 270 SyntaxNode, SyntaxToken, SyntaxElement, NodeOrToken, SyntaxKind::{self, *},
383 ast::{self, AstNode, AstToken, AstElement, AstChildren, AstChildTokens, AstChildElements}, 271 ast::{self, AstNode, AstToken, AstChildren},
384 }; 272 };
385 273
386 #(#tokens)* 274 #(#tokens)*