aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/ast
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-09-16 10:54:24 +0100
committerAleksey Kladov <[email protected]>2018-09-16 11:07:39 +0100
commitb5021411a84822cb3f1e3aeffad9550dd15bdeb6 (patch)
tree9dca564f8e51b298dced01c4ce669c756dce3142 /crates/libsyntax2/src/ast
parentba0bfeee12e19da40b5eabc8d0408639af10e96f (diff)
rename all things
Diffstat (limited to 'crates/libsyntax2/src/ast')
-rw-r--r--crates/libsyntax2/src/ast/generated.rs2142
-rw-r--r--crates/libsyntax2/src/ast/generated.rs.tera83
-rw-r--r--crates/libsyntax2/src/ast/mod.rs206
3 files changed, 0 insertions, 2431 deletions
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs
deleted file mode 100644
index c945c094a..000000000
--- a/crates/libsyntax2/src/ast/generated.rs
+++ /dev/null
@@ -1,2142 +0,0 @@
1use {
2 ast,
3 SyntaxNodeRef, AstNode,
4 SyntaxKind::*,
5};
6
7// ArgList
8#[derive(Debug, Clone, Copy)]
9pub struct ArgList<'a> {
10 syntax: SyntaxNodeRef<'a>,
11}
12
13impl<'a> AstNode<'a> for ArgList<'a> {
14 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
15 match syntax.kind() {
16 ARG_LIST => Some(ArgList { syntax }),
17 _ => None,
18 }
19 }
20 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
21}
22
23impl<'a> ArgList<'a> {
24 pub fn args(self) -> impl Iterator<Item = Expr<'a>> + 'a {
25 super::children(self)
26 }
27}
28
29// ArrayExpr
30#[derive(Debug, Clone, Copy)]
31pub struct ArrayExpr<'a> {
32 syntax: SyntaxNodeRef<'a>,
33}
34
35impl<'a> AstNode<'a> for ArrayExpr<'a> {
36 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
37 match syntax.kind() {
38 ARRAY_EXPR => Some(ArrayExpr { syntax }),
39 _ => None,
40 }
41 }
42 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
43}
44
45impl<'a> ArrayExpr<'a> {}
46
47// ArrayType
48#[derive(Debug, Clone, Copy)]
49pub struct ArrayType<'a> {
50 syntax: SyntaxNodeRef<'a>,
51}
52
53impl<'a> AstNode<'a> for ArrayType<'a> {
54 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
55 match syntax.kind() {
56 ARRAY_TYPE => Some(ArrayType { syntax }),
57 _ => None,
58 }
59 }
60 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
61}
62
63impl<'a> ArrayType<'a> {}
64
65// Attr
66#[derive(Debug, Clone, Copy)]
67pub struct Attr<'a> {
68 syntax: SyntaxNodeRef<'a>,
69}
70
71impl<'a> AstNode<'a> for Attr<'a> {
72 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
73 match syntax.kind() {
74 ATTR => Some(Attr { syntax }),
75 _ => None,
76 }
77 }
78 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
79}
80
81impl<'a> Attr<'a> {pub fn value(self) -> Option<TokenTree<'a>> {
82 super::child_opt(self)
83 }
84}
85
86// BinExpr
87#[derive(Debug, Clone, Copy)]
88pub struct BinExpr<'a> {
89 syntax: SyntaxNodeRef<'a>,
90}
91
92impl<'a> AstNode<'a> for BinExpr<'a> {
93 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
94 match syntax.kind() {
95 BIN_EXPR => Some(BinExpr { syntax }),
96 _ => None,
97 }
98 }
99 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
100}
101
102impl<'a> BinExpr<'a> {}
103
104// BindPat
105#[derive(Debug, Clone, Copy)]
106pub struct BindPat<'a> {
107 syntax: SyntaxNodeRef<'a>,
108}
109
110impl<'a> AstNode<'a> for BindPat<'a> {
111 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
112 match syntax.kind() {
113 BIND_PAT => Some(BindPat { syntax }),
114 _ => None,
115 }
116 }
117 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
118}
119
120impl<'a> ast::NameOwner<'a> for BindPat<'a> {}
121impl<'a> BindPat<'a> {}
122
123// Block
124#[derive(Debug, Clone, Copy)]
125pub struct Block<'a> {
126 syntax: SyntaxNodeRef<'a>,
127}
128
129impl<'a> AstNode<'a> for Block<'a> {
130 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
131 match syntax.kind() {
132 BLOCK => Some(Block { syntax }),
133 _ => None,
134 }
135 }
136 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
137}
138
139impl<'a> Block<'a> {
140 pub fn statements(self) -> impl Iterator<Item = Stmt<'a>> + 'a {
141 super::children(self)
142 }
143pub fn expr(self) -> Option<Expr<'a>> {
144 super::child_opt(self)
145 }
146}
147
148// BlockExpr
149#[derive(Debug, Clone, Copy)]
150pub struct BlockExpr<'a> {
151 syntax: SyntaxNodeRef<'a>,
152}
153
154impl<'a> AstNode<'a> for BlockExpr<'a> {
155 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
156 match syntax.kind() {
157 BLOCK_EXPR => Some(BlockExpr { syntax }),
158 _ => None,
159 }
160 }
161 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
162}
163
164impl<'a> BlockExpr<'a> {pub fn block(self) -> Option<Block<'a>> {
165 super::child_opt(self)
166 }
167}
168
169// BreakExpr
170#[derive(Debug, Clone, Copy)]
171pub struct BreakExpr<'a> {
172 syntax: SyntaxNodeRef<'a>,
173}
174
175impl<'a> AstNode<'a> for BreakExpr<'a> {
176 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
177 match syntax.kind() {
178 BREAK_EXPR => Some(BreakExpr { syntax }),
179 _ => None,
180 }
181 }
182 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
183}
184
185impl<'a> BreakExpr<'a> {}
186
187// CallExpr
188#[derive(Debug, Clone, Copy)]
189pub struct CallExpr<'a> {
190 syntax: SyntaxNodeRef<'a>,
191}
192
193impl<'a> AstNode<'a> for CallExpr<'a> {
194 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
195 match syntax.kind() {
196 CALL_EXPR => Some(CallExpr { syntax }),
197 _ => None,
198 }
199 }
200 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
201}
202
203impl<'a> ast::ArgListOwner<'a> for CallExpr<'a> {}
204impl<'a> CallExpr<'a> {pub fn expr(self) -> Option<Expr<'a>> {
205 super::child_opt(self)
206 }
207}
208
209// CastExpr
210#[derive(Debug, Clone, Copy)]
211pub struct CastExpr<'a> {
212 syntax: SyntaxNodeRef<'a>,
213}
214
215impl<'a> AstNode<'a> for CastExpr<'a> {
216 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
217 match syntax.kind() {
218 CAST_EXPR => Some(CastExpr { syntax }),
219 _ => None,
220 }
221 }
222 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
223}
224
225impl<'a> CastExpr<'a> {}
226
227// Condition
228#[derive(Debug, Clone, Copy)]
229pub struct Condition<'a> {
230 syntax: SyntaxNodeRef<'a>,
231}
232
233impl<'a> AstNode<'a> for Condition<'a> {
234 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
235 match syntax.kind() {
236 CONDITION => Some(Condition { syntax }),
237 _ => None,
238 }
239 }
240 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
241}
242
243impl<'a> Condition<'a> {pub fn pat(self) -> Option<Pat<'a>> {
244 super::child_opt(self)
245 }
246pub fn expr(self) -> Option<Expr<'a>> {
247 super::child_opt(self)
248 }
249}
250
251// ConstDef
252#[derive(Debug, Clone, Copy)]
253pub struct ConstDef<'a> {
254 syntax: SyntaxNodeRef<'a>,
255}
256
257impl<'a> AstNode<'a> for ConstDef<'a> {
258 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
259 match syntax.kind() {
260 CONST_DEF => Some(ConstDef { syntax }),
261 _ => None,
262 }
263 }
264 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
265}
266
267impl<'a> ast::NameOwner<'a> for ConstDef<'a> {}
268impl<'a> ast::TypeParamsOwner<'a> for ConstDef<'a> {}
269impl<'a> ast::AttrsOwner<'a> for ConstDef<'a> {}
270impl<'a> ConstDef<'a> {}
271
272// ContinueExpr
273#[derive(Debug, Clone, Copy)]
274pub struct ContinueExpr<'a> {
275 syntax: SyntaxNodeRef<'a>,
276}
277
278impl<'a> AstNode<'a> for ContinueExpr<'a> {
279 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
280 match syntax.kind() {
281 CONTINUE_EXPR => Some(ContinueExpr { syntax }),
282 _ => None,
283 }
284 }
285 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
286}
287
288impl<'a> ContinueExpr<'a> {}
289
290// DynTraitType
291#[derive(Debug, Clone, Copy)]
292pub struct DynTraitType<'a> {
293 syntax: SyntaxNodeRef<'a>,
294}
295
296impl<'a> AstNode<'a> for DynTraitType<'a> {
297 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
298 match syntax.kind() {
299 DYN_TRAIT_TYPE => Some(DynTraitType { syntax }),
300 _ => None,
301 }
302 }
303 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
304}
305
306impl<'a> DynTraitType<'a> {}
307
308// EnumDef
309#[derive(Debug, Clone, Copy)]
310pub struct EnumDef<'a> {
311 syntax: SyntaxNodeRef<'a>,
312}
313
314impl<'a> AstNode<'a> for EnumDef<'a> {
315 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
316 match syntax.kind() {
317 ENUM_DEF => Some(EnumDef { syntax }),
318 _ => None,
319 }
320 }
321 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
322}
323
324impl<'a> ast::NameOwner<'a> for EnumDef<'a> {}
325impl<'a> ast::TypeParamsOwner<'a> for EnumDef<'a> {}
326impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {}
327impl<'a> EnumDef<'a> {}
328
329// Expr
330#[derive(Debug, Clone, Copy)]
331pub enum Expr<'a> {
332 TupleExpr(TupleExpr<'a>),
333 ArrayExpr(ArrayExpr<'a>),
334 ParenExpr(ParenExpr<'a>),
335 PathExpr(PathExpr<'a>),
336 LambdaExpr(LambdaExpr<'a>),
337 IfExpr(IfExpr<'a>),
338 LoopExpr(LoopExpr<'a>),
339 ForExpr(ForExpr<'a>),
340 WhileExpr(WhileExpr<'a>),
341 ContinueExpr(ContinueExpr<'a>),
342 BreakExpr(BreakExpr<'a>),
343 Label(Label<'a>),
344 BlockExpr(BlockExpr<'a>),
345 ReturnExpr(ReturnExpr<'a>),
346 MatchExpr(MatchExpr<'a>),
347 MatchArmList(MatchArmList<'a>),
348 MatchArm(MatchArm<'a>),
349 MatchGuard(MatchGuard<'a>),
350 StructLit(StructLit<'a>),
351 NamedFieldList(NamedFieldList<'a>),
352 NamedField(NamedField<'a>),
353 CallExpr(CallExpr<'a>),
354 IndexExpr(IndexExpr<'a>),
355 MethodCallExpr(MethodCallExpr<'a>),
356 FieldExpr(FieldExpr<'a>),
357 TryExpr(TryExpr<'a>),
358 CastExpr(CastExpr<'a>),
359 RefExpr(RefExpr<'a>),
360 PrefixExpr(PrefixExpr<'a>),
361 RangeExpr(RangeExpr<'a>),
362 BinExpr(BinExpr<'a>),
363 Literal(Literal<'a>),
364}
365
366impl<'a> AstNode<'a> for Expr<'a> {
367 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
368 match syntax.kind() {
369 TUPLE_EXPR => Some(Expr::TupleExpr(TupleExpr { syntax })),
370 ARRAY_EXPR => Some(Expr::ArrayExpr(ArrayExpr { syntax })),
371 PAREN_EXPR => Some(Expr::ParenExpr(ParenExpr { syntax })),
372 PATH_EXPR => Some(Expr::PathExpr(PathExpr { syntax })),
373 LAMBDA_EXPR => Some(Expr::LambdaExpr(LambdaExpr { syntax })),
374 IF_EXPR => Some(Expr::IfExpr(IfExpr { syntax })),
375 LOOP_EXPR => Some(Expr::LoopExpr(LoopExpr { syntax })),
376 FOR_EXPR => Some(Expr::ForExpr(ForExpr { syntax })),
377 WHILE_EXPR => Some(Expr::WhileExpr(WhileExpr { syntax })),
378 CONTINUE_EXPR => Some(Expr::ContinueExpr(ContinueExpr { syntax })),
379 BREAK_EXPR => Some(Expr::BreakExpr(BreakExpr { syntax })),
380 LABEL => Some(Expr::Label(Label { syntax })),
381 BLOCK_EXPR => Some(Expr::BlockExpr(BlockExpr { syntax })),
382 RETURN_EXPR => Some(Expr::ReturnExpr(ReturnExpr { syntax })),
383 MATCH_EXPR => Some(Expr::MatchExpr(MatchExpr { syntax })),
384 MATCH_ARM_LIST => Some(Expr::MatchArmList(MatchArmList { syntax })),
385 MATCH_ARM => Some(Expr::MatchArm(MatchArm { syntax })),
386 MATCH_GUARD => Some(Expr::MatchGuard(MatchGuard { syntax })),
387 STRUCT_LIT => Some(Expr::StructLit(StructLit { syntax })),
388 NAMED_FIELD_LIST => Some(Expr::NamedFieldList(NamedFieldList { syntax })),
389 NAMED_FIELD => Some(Expr::NamedField(NamedField { syntax })),
390 CALL_EXPR => Some(Expr::CallExpr(CallExpr { syntax })),
391 INDEX_EXPR => Some(Expr::IndexExpr(IndexExpr { syntax })),
392 METHOD_CALL_EXPR => Some(Expr::MethodCallExpr(MethodCallExpr { syntax })),
393 FIELD_EXPR => Some(Expr::FieldExpr(FieldExpr { syntax })),
394 TRY_EXPR => Some(Expr::TryExpr(TryExpr { syntax })),
395 CAST_EXPR => Some(Expr::CastExpr(CastExpr { syntax })),
396 REF_EXPR => Some(Expr::RefExpr(RefExpr { syntax })),
397 PREFIX_EXPR => Some(Expr::PrefixExpr(PrefixExpr { syntax })),
398 RANGE_EXPR => Some(Expr::RangeExpr(RangeExpr { syntax })),
399 BIN_EXPR => Some(Expr::BinExpr(BinExpr { syntax })),
400 LITERAL => Some(Expr::Literal(Literal { syntax })),
401 _ => None,
402 }
403 }
404 fn syntax(self) -> SyntaxNodeRef<'a> {
405 match self {
406 Expr::TupleExpr(inner) => inner.syntax(),
407 Expr::ArrayExpr(inner) => inner.syntax(),
408 Expr::ParenExpr(inner) => inner.syntax(),
409 Expr::PathExpr(inner) => inner.syntax(),
410 Expr::LambdaExpr(inner) => inner.syntax(),
411 Expr::IfExpr(inner) => inner.syntax(),
412 Expr::LoopExpr(inner) => inner.syntax(),
413 Expr::ForExpr(inner) => inner.syntax(),
414 Expr::WhileExpr(inner) => inner.syntax(),
415 Expr::ContinueExpr(inner) => inner.syntax(),
416 Expr::BreakExpr(inner) => inner.syntax(),
417 Expr::Label(inner) => inner.syntax(),
418 Expr::BlockExpr(inner) => inner.syntax(),
419 Expr::ReturnExpr(inner) => inner.syntax(),
420 Expr::MatchExpr(inner) => inner.syntax(),
421 Expr::MatchArmList(inner) => inner.syntax(),
422 Expr::MatchArm(inner) => inner.syntax(),
423 Expr::MatchGuard(inner) => inner.syntax(),
424 Expr::StructLit(inner) => inner.syntax(),
425 Expr::NamedFieldList(inner) => inner.syntax(),
426 Expr::NamedField(inner) => inner.syntax(),
427 Expr::CallExpr(inner) => inner.syntax(),
428 Expr::IndexExpr(inner) => inner.syntax(),
429 Expr::MethodCallExpr(inner) => inner.syntax(),
430 Expr::FieldExpr(inner) => inner.syntax(),
431 Expr::TryExpr(inner) => inner.syntax(),
432 Expr::CastExpr(inner) => inner.syntax(),
433 Expr::RefExpr(inner) => inner.syntax(),
434 Expr::PrefixExpr(inner) => inner.syntax(),
435 Expr::RangeExpr(inner) => inner.syntax(),
436 Expr::BinExpr(inner) => inner.syntax(),
437 Expr::Literal(inner) => inner.syntax(),
438 }
439 }
440}
441
442impl<'a> Expr<'a> {}
443
444// ExprStmt
445#[derive(Debug, Clone, Copy)]
446pub struct ExprStmt<'a> {
447 syntax: SyntaxNodeRef<'a>,
448}
449
450impl<'a> AstNode<'a> for ExprStmt<'a> {
451 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
452 match syntax.kind() {
453 EXPR_STMT => Some(ExprStmt { syntax }),
454 _ => None,
455 }
456 }
457 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
458}
459
460impl<'a> ExprStmt<'a> {pub fn expr(self) -> Option<Expr<'a>> {
461 super::child_opt(self)
462 }
463}
464
465// ExternCrateItem
466#[derive(Debug, Clone, Copy)]
467pub struct ExternCrateItem<'a> {
468 syntax: SyntaxNodeRef<'a>,
469}
470
471impl<'a> AstNode<'a> for ExternCrateItem<'a> {
472 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
473 match syntax.kind() {
474 EXTERN_CRATE_ITEM => Some(ExternCrateItem { syntax }),
475 _ => None,
476 }
477 }
478 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
479}
480
481impl<'a> ExternCrateItem<'a> {}
482
483// FieldExpr
484#[derive(Debug, Clone, Copy)]
485pub struct FieldExpr<'a> {
486 syntax: SyntaxNodeRef<'a>,
487}
488
489impl<'a> AstNode<'a> for FieldExpr<'a> {
490 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
491 match syntax.kind() {
492 FIELD_EXPR => Some(FieldExpr { syntax }),
493 _ => None,
494 }
495 }
496 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
497}
498
499impl<'a> FieldExpr<'a> {}
500
501// FieldPatList
502#[derive(Debug, Clone, Copy)]
503pub struct FieldPatList<'a> {
504 syntax: SyntaxNodeRef<'a>,
505}
506
507impl<'a> AstNode<'a> for FieldPatList<'a> {
508 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
509 match syntax.kind() {
510 FIELD_PAT_LIST => Some(FieldPatList { syntax }),
511 _ => None,
512 }
513 }
514 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
515}
516
517impl<'a> FieldPatList<'a> {}
518
519// FnDef
520#[derive(Debug, Clone, Copy)]
521pub struct FnDef<'a> {
522 syntax: SyntaxNodeRef<'a>,
523}
524
525impl<'a> AstNode<'a> for FnDef<'a> {
526 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
527 match syntax.kind() {
528 FN_DEF => Some(FnDef { syntax }),
529 _ => None,
530 }
531 }
532 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
533}
534
535impl<'a> ast::NameOwner<'a> for FnDef<'a> {}
536impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {}
537impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {}
538impl<'a> FnDef<'a> {pub fn param_list(self) -> Option<ParamList<'a>> {
539 super::child_opt(self)
540 }
541pub fn body(self) -> Option<Block<'a>> {
542 super::child_opt(self)
543 }
544pub fn ret_type(self) -> Option<RetType<'a>> {
545 super::child_opt(self)
546 }
547}
548
549// FnPointerType
550#[derive(Debug, Clone, Copy)]
551pub struct FnPointerType<'a> {
552 syntax: SyntaxNodeRef<'a>,
553}
554
555impl<'a> AstNode<'a> for FnPointerType<'a> {
556 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
557 match syntax.kind() {
558 FN_POINTER_TYPE => Some(FnPointerType { syntax }),
559 _ => None,
560 }
561 }
562 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
563}
564
565impl<'a> FnPointerType<'a> {}
566
567// ForExpr
568#[derive(Debug, Clone, Copy)]
569pub struct ForExpr<'a> {
570 syntax: SyntaxNodeRef<'a>,
571}
572
573impl<'a> AstNode<'a> for ForExpr<'a> {
574 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
575 match syntax.kind() {
576 FOR_EXPR => Some(ForExpr { syntax }),
577 _ => None,
578 }
579 }
580 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
581}
582
583impl<'a> ast::LoopBodyOwner<'a> for ForExpr<'a> {}
584impl<'a> ForExpr<'a> {pub fn pat(self) -> Option<Pat<'a>> {
585 super::child_opt(self)
586 }
587pub fn iterable(self) -> Option<Expr<'a>> {
588 super::child_opt(self)
589 }
590}
591
592// ForType
593#[derive(Debug, Clone, Copy)]
594pub struct ForType<'a> {
595 syntax: SyntaxNodeRef<'a>,
596}
597
598impl<'a> AstNode<'a> for ForType<'a> {
599 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
600 match syntax.kind() {
601 FOR_TYPE => Some(ForType { syntax }),
602 _ => None,
603 }
604 }
605 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
606}
607
608impl<'a> ForType<'a> {}
609
610// IfExpr
611#[derive(Debug, Clone, Copy)]
612pub struct IfExpr<'a> {
613 syntax: SyntaxNodeRef<'a>,
614}
615
616impl<'a> AstNode<'a> for IfExpr<'a> {
617 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
618 match syntax.kind() {
619 IF_EXPR => Some(IfExpr { syntax }),
620 _ => None,
621 }
622 }
623 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
624}
625
626impl<'a> IfExpr<'a> {pub fn condition(self) -> Option<Condition<'a>> {
627 super::child_opt(self)
628 }
629}
630
631// ImplItem
632#[derive(Debug, Clone, Copy)]
633pub struct ImplItem<'a> {
634 syntax: SyntaxNodeRef<'a>,
635}
636
637impl<'a> AstNode<'a> for ImplItem<'a> {
638 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
639 match syntax.kind() {
640 IMPL_ITEM => Some(ImplItem { syntax }),
641 _ => None,
642 }
643 }
644 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
645}
646
647impl<'a> ImplItem<'a> {}
648
649// ImplTraitType
650#[derive(Debug, Clone, Copy)]
651pub struct ImplTraitType<'a> {
652 syntax: SyntaxNodeRef<'a>,
653}
654
655impl<'a> AstNode<'a> for ImplTraitType<'a> {
656 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
657 match syntax.kind() {
658 IMPL_TRAIT_TYPE => Some(ImplTraitType { syntax }),
659 _ => None,
660 }
661 }
662 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
663}
664
665impl<'a> ImplTraitType<'a> {}
666
667// IndexExpr
668#[derive(Debug, Clone, Copy)]
669pub struct IndexExpr<'a> {
670 syntax: SyntaxNodeRef<'a>,
671}
672
673impl<'a> AstNode<'a> for IndexExpr<'a> {
674 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
675 match syntax.kind() {
676 INDEX_EXPR => Some(IndexExpr { syntax }),
677 _ => None,
678 }
679 }
680 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
681}
682
683impl<'a> IndexExpr<'a> {}
684
685// ItemList
686#[derive(Debug, Clone, Copy)]
687pub struct ItemList<'a> {
688 syntax: SyntaxNodeRef<'a>,
689}
690
691impl<'a> AstNode<'a> for ItemList<'a> {
692 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
693 match syntax.kind() {
694 ITEM_LIST => Some(ItemList { syntax }),
695 _ => None,
696 }
697 }
698 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
699}
700
701impl<'a> ast::FnDefOwner<'a> for ItemList<'a> {}
702impl<'a> ast::ModuleItemOwner<'a> for ItemList<'a> {}
703impl<'a> ItemList<'a> {}
704
705// Label
706#[derive(Debug, Clone, Copy)]
707pub struct Label<'a> {
708 syntax: SyntaxNodeRef<'a>,
709}
710
711impl<'a> AstNode<'a> for Label<'a> {
712 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
713 match syntax.kind() {
714 LABEL => Some(Label { syntax }),
715 _ => None,
716 }
717 }
718 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
719}
720
721impl<'a> Label<'a> {}
722
723// LambdaExpr
724#[derive(Debug, Clone, Copy)]
725pub struct LambdaExpr<'a> {
726 syntax: SyntaxNodeRef<'a>,
727}
728
729impl<'a> AstNode<'a> for LambdaExpr<'a> {
730 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
731 match syntax.kind() {
732 LAMBDA_EXPR => Some(LambdaExpr { syntax }),
733 _ => None,
734 }
735 }
736 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
737}
738
739impl<'a> LambdaExpr<'a> {pub fn param_list(self) -> Option<ParamList<'a>> {
740 super::child_opt(self)
741 }
742pub fn body(self) -> Option<Expr<'a>> {
743 super::child_opt(self)
744 }
745}
746
747// LetStmt
748#[derive(Debug, Clone, Copy)]
749pub struct LetStmt<'a> {
750 syntax: SyntaxNodeRef<'a>,
751}
752
753impl<'a> AstNode<'a> for LetStmt<'a> {
754 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
755 match syntax.kind() {
756 LET_STMT => Some(LetStmt { syntax }),
757 _ => None,
758 }
759 }
760 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
761}
762
763impl<'a> LetStmt<'a> {pub fn pat(self) -> Option<Pat<'a>> {
764 super::child_opt(self)
765 }
766pub fn initializer(self) -> Option<Expr<'a>> {
767 super::child_opt(self)
768 }
769}
770
771// Lifetime
772#[derive(Debug, Clone, Copy)]
773pub struct Lifetime<'a> {
774 syntax: SyntaxNodeRef<'a>,
775}
776
777impl<'a> AstNode<'a> for Lifetime<'a> {
778 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
779 match syntax.kind() {
780 LIFETIME => Some(Lifetime { syntax }),
781 _ => None,
782 }
783 }
784 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
785}
786
787impl<'a> Lifetime<'a> {}
788
789// LifetimeParam
790#[derive(Debug, Clone, Copy)]
791pub struct LifetimeParam<'a> {
792 syntax: SyntaxNodeRef<'a>,
793}
794
795impl<'a> AstNode<'a> for LifetimeParam<'a> {
796 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
797 match syntax.kind() {
798 LIFETIME_PARAM => Some(LifetimeParam { syntax }),
799 _ => None,
800 }
801 }
802 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
803}
804
805impl<'a> LifetimeParam<'a> {pub fn lifetime(self) -> Option<Lifetime<'a>> {
806 super::child_opt(self)
807 }
808}
809
810// Literal
811#[derive(Debug, Clone, Copy)]
812pub struct Literal<'a> {
813 syntax: SyntaxNodeRef<'a>,
814}
815
816impl<'a> AstNode<'a> for Literal<'a> {
817 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
818 match syntax.kind() {
819 LITERAL => Some(Literal { syntax }),
820 _ => None,
821 }
822 }
823 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
824}
825
826impl<'a> Literal<'a> {}
827
828// LoopExpr
829#[derive(Debug, Clone, Copy)]
830pub struct LoopExpr<'a> {
831 syntax: SyntaxNodeRef<'a>,
832}
833
834impl<'a> AstNode<'a> for LoopExpr<'a> {
835 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
836 match syntax.kind() {
837 LOOP_EXPR => Some(LoopExpr { syntax }),
838 _ => None,
839 }
840 }
841 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
842}
843
844impl<'a> ast::LoopBodyOwner<'a> for LoopExpr<'a> {}
845impl<'a> LoopExpr<'a> {}
846
847// MatchArm
848#[derive(Debug, Clone, Copy)]
849pub struct MatchArm<'a> {
850 syntax: SyntaxNodeRef<'a>,
851}
852
853impl<'a> AstNode<'a> for MatchArm<'a> {
854 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
855 match syntax.kind() {
856 MATCH_ARM => Some(MatchArm { syntax }),
857 _ => None,
858 }
859 }
860 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
861}
862
863impl<'a> MatchArm<'a> {
864 pub fn pats(self) -> impl Iterator<Item = Pat<'a>> + 'a {
865 super::children(self)
866 }
867pub fn guard(self) -> Option<MatchGuard<'a>> {
868 super::child_opt(self)
869 }
870pub fn expr(self) -> Option<Expr<'a>> {
871 super::child_opt(self)
872 }
873}
874
875// MatchArmList
876#[derive(Debug, Clone, Copy)]
877pub struct MatchArmList<'a> {
878 syntax: SyntaxNodeRef<'a>,
879}
880
881impl<'a> AstNode<'a> for MatchArmList<'a> {
882 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
883 match syntax.kind() {
884 MATCH_ARM_LIST => Some(MatchArmList { syntax }),
885 _ => None,
886 }
887 }
888 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
889}
890
891impl<'a> MatchArmList<'a> {
892 pub fn arms(self) -> impl Iterator<Item = MatchArm<'a>> + 'a {
893 super::children(self)
894 }
895}
896
897// MatchExpr
898#[derive(Debug, Clone, Copy)]
899pub struct MatchExpr<'a> {
900 syntax: SyntaxNodeRef<'a>,
901}
902
903impl<'a> AstNode<'a> for MatchExpr<'a> {
904 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
905 match syntax.kind() {
906 MATCH_EXPR => Some(MatchExpr { syntax }),
907 _ => None,
908 }
909 }
910 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
911}
912
913impl<'a> MatchExpr<'a> {pub fn expr(self) -> Option<Expr<'a>> {
914 super::child_opt(self)
915 }
916pub fn match_arm_list(self) -> Option<MatchArmList<'a>> {
917 super::child_opt(self)
918 }
919}
920
921// MatchGuard
922#[derive(Debug, Clone, Copy)]
923pub struct MatchGuard<'a> {
924 syntax: SyntaxNodeRef<'a>,
925}
926
927impl<'a> AstNode<'a> for MatchGuard<'a> {
928 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
929 match syntax.kind() {
930 MATCH_GUARD => Some(MatchGuard { syntax }),
931 _ => None,
932 }
933 }
934 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
935}
936
937impl<'a> MatchGuard<'a> {}
938
939// MethodCallExpr
940#[derive(Debug, Clone, Copy)]
941pub struct MethodCallExpr<'a> {
942 syntax: SyntaxNodeRef<'a>,
943}
944
945impl<'a> AstNode<'a> for MethodCallExpr<'a> {
946 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
947 match syntax.kind() {
948 METHOD_CALL_EXPR => Some(MethodCallExpr { syntax }),
949 _ => None,
950 }
951 }
952 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
953}
954
955impl<'a> ast::ArgListOwner<'a> for MethodCallExpr<'a> {}
956impl<'a> MethodCallExpr<'a> {pub fn expr(self) -> Option<Expr<'a>> {
957 super::child_opt(self)
958 }
959}
960
961// Module
962#[derive(Debug, Clone, Copy)]
963pub struct Module<'a> {
964 syntax: SyntaxNodeRef<'a>,
965}
966
967impl<'a> AstNode<'a> for Module<'a> {
968 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
969 match syntax.kind() {
970 MODULE => Some(Module { syntax }),
971 _ => None,
972 }
973 }
974 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
975}
976
977impl<'a> ast::NameOwner<'a> for Module<'a> {}
978impl<'a> ast::AttrsOwner<'a> for Module<'a> {}
979impl<'a> Module<'a> {pub fn item_list(self) -> Option<ItemList<'a>> {
980 super::child_opt(self)
981 }
982}
983
984// ModuleItem
985#[derive(Debug, Clone, Copy)]
986pub enum ModuleItem<'a> {
987 StructDef(StructDef<'a>),
988 EnumDef(EnumDef<'a>),
989 FnDef(FnDef<'a>),
990 TraitDef(TraitDef<'a>),
991 TypeDef(TypeDef<'a>),
992 ImplItem(ImplItem<'a>),
993 UseItem(UseItem<'a>),
994 ExternCrateItem(ExternCrateItem<'a>),
995 ConstDef(ConstDef<'a>),
996 StaticDef(StaticDef<'a>),
997 Module(Module<'a>),
998}
999
1000impl<'a> AstNode<'a> for ModuleItem<'a> {
1001 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1002 match syntax.kind() {
1003 STRUCT_DEF => Some(ModuleItem::StructDef(StructDef { syntax })),
1004 ENUM_DEF => Some(ModuleItem::EnumDef(EnumDef { syntax })),
1005 FN_DEF => Some(ModuleItem::FnDef(FnDef { syntax })),
1006 TRAIT_DEF => Some(ModuleItem::TraitDef(TraitDef { syntax })),
1007 TYPE_DEF => Some(ModuleItem::TypeDef(TypeDef { syntax })),
1008 IMPL_ITEM => Some(ModuleItem::ImplItem(ImplItem { syntax })),
1009 USE_ITEM => Some(ModuleItem::UseItem(UseItem { syntax })),
1010 EXTERN_CRATE_ITEM => Some(ModuleItem::ExternCrateItem(ExternCrateItem { syntax })),
1011 CONST_DEF => Some(ModuleItem::ConstDef(ConstDef { syntax })),
1012 STATIC_DEF => Some(ModuleItem::StaticDef(StaticDef { syntax })),
1013 MODULE => Some(ModuleItem::Module(Module { syntax })),
1014 _ => None,
1015 }
1016 }
1017 fn syntax(self) -> SyntaxNodeRef<'a> {
1018 match self {
1019 ModuleItem::StructDef(inner) => inner.syntax(),
1020 ModuleItem::EnumDef(inner) => inner.syntax(),
1021 ModuleItem::FnDef(inner) => inner.syntax(),
1022 ModuleItem::TraitDef(inner) => inner.syntax(),
1023 ModuleItem::TypeDef(inner) => inner.syntax(),
1024 ModuleItem::ImplItem(inner) => inner.syntax(),
1025 ModuleItem::UseItem(inner) => inner.syntax(),
1026 ModuleItem::ExternCrateItem(inner) => inner.syntax(),
1027 ModuleItem::ConstDef(inner) => inner.syntax(),
1028 ModuleItem::StaticDef(inner) => inner.syntax(),
1029 ModuleItem::Module(inner) => inner.syntax(),
1030 }
1031 }
1032}
1033
1034impl<'a> ModuleItem<'a> {}
1035
1036// Name
1037#[derive(Debug, Clone, Copy)]
1038pub struct Name<'a> {
1039 syntax: SyntaxNodeRef<'a>,
1040}
1041
1042impl<'a> AstNode<'a> for Name<'a> {
1043 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1044 match syntax.kind() {
1045 NAME => Some(Name { syntax }),
1046 _ => None,
1047 }
1048 }
1049 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1050}
1051
1052impl<'a> Name<'a> {}
1053
1054// NameRef
1055#[derive(Debug, Clone, Copy)]
1056pub struct NameRef<'a> {
1057 syntax: SyntaxNodeRef<'a>,
1058}
1059
1060impl<'a> AstNode<'a> for NameRef<'a> {
1061 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1062 match syntax.kind() {
1063 NAME_REF => Some(NameRef { syntax }),
1064 _ => None,
1065 }
1066 }
1067 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1068}
1069
1070impl<'a> NameRef<'a> {}
1071
1072// NamedField
1073#[derive(Debug, Clone, Copy)]
1074pub struct NamedField<'a> {
1075 syntax: SyntaxNodeRef<'a>,
1076}
1077
1078impl<'a> AstNode<'a> for NamedField<'a> {
1079 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1080 match syntax.kind() {
1081 NAMED_FIELD => Some(NamedField { syntax }),
1082 _ => None,
1083 }
1084 }
1085 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1086}
1087
1088impl<'a> NamedField<'a> {}
1089
1090// NamedFieldDef
1091#[derive(Debug, Clone, Copy)]
1092pub struct NamedFieldDef<'a> {
1093 syntax: SyntaxNodeRef<'a>,
1094}
1095
1096impl<'a> AstNode<'a> for NamedFieldDef<'a> {
1097 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1098 match syntax.kind() {
1099 NAMED_FIELD_DEF => Some(NamedFieldDef { syntax }),
1100 _ => None,
1101 }
1102 }
1103 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1104}
1105
1106impl<'a> ast::NameOwner<'a> for NamedFieldDef<'a> {}
1107impl<'a> ast::AttrsOwner<'a> for NamedFieldDef<'a> {}
1108impl<'a> NamedFieldDef<'a> {}
1109
1110// NamedFieldList
1111#[derive(Debug, Clone, Copy)]
1112pub struct NamedFieldList<'a> {
1113 syntax: SyntaxNodeRef<'a>,
1114}
1115
1116impl<'a> AstNode<'a> for NamedFieldList<'a> {
1117 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1118 match syntax.kind() {
1119 NAMED_FIELD_LIST => Some(NamedFieldList { syntax }),
1120 _ => None,
1121 }
1122 }
1123 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1124}
1125
1126impl<'a> NamedFieldList<'a> {}
1127
1128// NeverType
1129#[derive(Debug, Clone, Copy)]
1130pub struct NeverType<'a> {
1131 syntax: SyntaxNodeRef<'a>,
1132}
1133
1134impl<'a> AstNode<'a> for NeverType<'a> {
1135 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1136 match syntax.kind() {
1137 NEVER_TYPE => Some(NeverType { syntax }),
1138 _ => None,
1139 }
1140 }
1141 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1142}
1143
1144impl<'a> NeverType<'a> {}
1145
1146// NominalDef
1147#[derive(Debug, Clone, Copy)]
1148pub enum NominalDef<'a> {
1149 StructDef(StructDef<'a>),
1150 EnumDef(EnumDef<'a>),
1151}
1152
1153impl<'a> AstNode<'a> for NominalDef<'a> {
1154 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1155 match syntax.kind() {
1156 STRUCT_DEF => Some(NominalDef::StructDef(StructDef { syntax })),
1157 ENUM_DEF => Some(NominalDef::EnumDef(EnumDef { syntax })),
1158 _ => None,
1159 }
1160 }
1161 fn syntax(self) -> SyntaxNodeRef<'a> {
1162 match self {
1163 NominalDef::StructDef(inner) => inner.syntax(),
1164 NominalDef::EnumDef(inner) => inner.syntax(),
1165 }
1166 }
1167}
1168
1169impl<'a> ast::NameOwner<'a> for NominalDef<'a> {}
1170impl<'a> ast::TypeParamsOwner<'a> for NominalDef<'a> {}
1171impl<'a> ast::AttrsOwner<'a> for NominalDef<'a> {}
1172impl<'a> NominalDef<'a> {}
1173
1174// Param
1175#[derive(Debug, Clone, Copy)]
1176pub struct Param<'a> {
1177 syntax: SyntaxNodeRef<'a>,
1178}
1179
1180impl<'a> AstNode<'a> for Param<'a> {
1181 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1182 match syntax.kind() {
1183 PARAM => Some(Param { syntax }),
1184 _ => None,
1185 }
1186 }
1187 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1188}
1189
1190impl<'a> Param<'a> {pub fn pat(self) -> Option<Pat<'a>> {
1191 super::child_opt(self)
1192 }
1193}
1194
1195// ParamList
1196#[derive(Debug, Clone, Copy)]
1197pub struct ParamList<'a> {
1198 syntax: SyntaxNodeRef<'a>,
1199}
1200
1201impl<'a> AstNode<'a> for ParamList<'a> {
1202 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1203 match syntax.kind() {
1204 PARAM_LIST => Some(ParamList { syntax }),
1205 _ => None,
1206 }
1207 }
1208 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1209}
1210
1211impl<'a> ParamList<'a> {
1212 pub fn params(self) -> impl Iterator<Item = Param<'a>> + 'a {
1213 super::children(self)
1214 }
1215pub fn self_param(self) -> Option<SelfParam<'a>> {
1216 super::child_opt(self)
1217 }
1218}
1219
1220// ParenExpr
1221#[derive(Debug, Clone, Copy)]
1222pub struct ParenExpr<'a> {
1223 syntax: SyntaxNodeRef<'a>,
1224}
1225
1226impl<'a> AstNode<'a> for ParenExpr<'a> {
1227 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1228 match syntax.kind() {
1229 PAREN_EXPR => Some(ParenExpr { syntax }),
1230 _ => None,
1231 }
1232 }
1233 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1234}
1235
1236impl<'a> ParenExpr<'a> {}
1237
1238// ParenType
1239#[derive(Debug, Clone, Copy)]
1240pub struct ParenType<'a> {
1241 syntax: SyntaxNodeRef<'a>,
1242}
1243
1244impl<'a> AstNode<'a> for ParenType<'a> {
1245 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1246 match syntax.kind() {
1247 PAREN_TYPE => Some(ParenType { syntax }),
1248 _ => None,
1249 }
1250 }
1251 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1252}
1253
1254impl<'a> ParenType<'a> {}
1255
1256// Pat
1257#[derive(Debug, Clone, Copy)]
1258pub enum Pat<'a> {
1259 RefPat(RefPat<'a>),
1260 BindPat(BindPat<'a>),
1261 PlaceholderPat(PlaceholderPat<'a>),
1262 PathPat(PathPat<'a>),
1263 StructPat(StructPat<'a>),
1264 FieldPatList(FieldPatList<'a>),
1265 TupleStructPat(TupleStructPat<'a>),
1266 TuplePat(TuplePat<'a>),
1267 SlicePat(SlicePat<'a>),
1268 RangePat(RangePat<'a>),
1269}
1270
1271impl<'a> AstNode<'a> for Pat<'a> {
1272 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1273 match syntax.kind() {
1274 REF_PAT => Some(Pat::RefPat(RefPat { syntax })),
1275 BIND_PAT => Some(Pat::BindPat(BindPat { syntax })),
1276 PLACEHOLDER_PAT => Some(Pat::PlaceholderPat(PlaceholderPat { syntax })),
1277 PATH_PAT => Some(Pat::PathPat(PathPat { syntax })),
1278 STRUCT_PAT => Some(Pat::StructPat(StructPat { syntax })),
1279 FIELD_PAT_LIST => Some(Pat::FieldPatList(FieldPatList { syntax })),
1280 TUPLE_STRUCT_PAT => Some(Pat::TupleStructPat(TupleStructPat { syntax })),
1281 TUPLE_PAT => Some(Pat::TuplePat(TuplePat { syntax })),
1282 SLICE_PAT => Some(Pat::SlicePat(SlicePat { syntax })),
1283 RANGE_PAT => Some(Pat::RangePat(RangePat { syntax })),
1284 _ => None,
1285 }
1286 }
1287 fn syntax(self) -> SyntaxNodeRef<'a> {
1288 match self {
1289 Pat::RefPat(inner) => inner.syntax(),
1290 Pat::BindPat(inner) => inner.syntax(),
1291 Pat::PlaceholderPat(inner) => inner.syntax(),
1292 Pat::PathPat(inner) => inner.syntax(),
1293 Pat::StructPat(inner) => inner.syntax(),
1294 Pat::FieldPatList(inner) => inner.syntax(),
1295 Pat::TupleStructPat(inner) => inner.syntax(),
1296 Pat::TuplePat(inner) => inner.syntax(),
1297 Pat::SlicePat(inner) => inner.syntax(),
1298 Pat::RangePat(inner) => inner.syntax(),
1299 }
1300 }
1301}
1302
1303impl<'a> Pat<'a> {}
1304
1305// Path
1306#[derive(Debug, Clone, Copy)]
1307pub struct Path<'a> {
1308 syntax: SyntaxNodeRef<'a>,
1309}
1310
1311impl<'a> AstNode<'a> for Path<'a> {
1312 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1313 match syntax.kind() {
1314 PATH => Some(Path { syntax }),
1315 _ => None,
1316 }
1317 }
1318 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1319}
1320
1321impl<'a> Path<'a> {pub fn segment(self) -> Option<PathSegment<'a>> {
1322 super::child_opt(self)
1323 }
1324}
1325
1326// PathExpr
1327#[derive(Debug, Clone, Copy)]
1328pub struct PathExpr<'a> {
1329 syntax: SyntaxNodeRef<'a>,
1330}
1331
1332impl<'a> AstNode<'a> for PathExpr<'a> {
1333 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1334 match syntax.kind() {
1335 PATH_EXPR => Some(PathExpr { syntax }),
1336 _ => None,
1337 }
1338 }
1339 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1340}
1341
1342impl<'a> PathExpr<'a> {}
1343
1344// PathPat
1345#[derive(Debug, Clone, Copy)]
1346pub struct PathPat<'a> {
1347 syntax: SyntaxNodeRef<'a>,
1348}
1349
1350impl<'a> AstNode<'a> for PathPat<'a> {
1351 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1352 match syntax.kind() {
1353 PATH_PAT => Some(PathPat { syntax }),
1354 _ => None,
1355 }
1356 }
1357 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1358}
1359
1360impl<'a> PathPat<'a> {}
1361
1362// PathSegment
1363#[derive(Debug, Clone, Copy)]
1364pub struct PathSegment<'a> {
1365 syntax: SyntaxNodeRef<'a>,
1366}
1367
1368impl<'a> AstNode<'a> for PathSegment<'a> {
1369 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1370 match syntax.kind() {
1371 PATH_SEGMENT => Some(PathSegment { syntax }),
1372 _ => None,
1373 }
1374 }
1375 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1376}
1377
1378impl<'a> PathSegment<'a> {pub fn name_ref(self) -> Option<NameRef<'a>> {
1379 super::child_opt(self)
1380 }
1381}
1382
1383// PathType
1384#[derive(Debug, Clone, Copy)]
1385pub struct PathType<'a> {
1386 syntax: SyntaxNodeRef<'a>,
1387}
1388
1389impl<'a> AstNode<'a> for PathType<'a> {
1390 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1391 match syntax.kind() {
1392 PATH_TYPE => Some(PathType { syntax }),
1393 _ => None,
1394 }
1395 }
1396 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1397}
1398
1399impl<'a> PathType<'a> {}
1400
1401// PlaceholderPat
1402#[derive(Debug, Clone, Copy)]
1403pub struct PlaceholderPat<'a> {
1404 syntax: SyntaxNodeRef<'a>,
1405}
1406
1407impl<'a> AstNode<'a> for PlaceholderPat<'a> {
1408 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1409 match syntax.kind() {
1410 PLACEHOLDER_PAT => Some(PlaceholderPat { syntax }),
1411 _ => None,
1412 }
1413 }
1414 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1415}
1416
1417impl<'a> PlaceholderPat<'a> {}
1418
1419// PlaceholderType
1420#[derive(Debug, Clone, Copy)]
1421pub struct PlaceholderType<'a> {
1422 syntax: SyntaxNodeRef<'a>,
1423}
1424
1425impl<'a> AstNode<'a> for PlaceholderType<'a> {
1426 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1427 match syntax.kind() {
1428 PLACEHOLDER_TYPE => Some(PlaceholderType { syntax }),
1429 _ => None,
1430 }
1431 }
1432 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1433}
1434
1435impl<'a> PlaceholderType<'a> {}
1436
1437// PointerType
1438#[derive(Debug, Clone, Copy)]
1439pub struct PointerType<'a> {
1440 syntax: SyntaxNodeRef<'a>,
1441}
1442
1443impl<'a> AstNode<'a> for PointerType<'a> {
1444 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1445 match syntax.kind() {
1446 POINTER_TYPE => Some(PointerType { syntax }),
1447 _ => None,
1448 }
1449 }
1450 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1451}
1452
1453impl<'a> PointerType<'a> {}
1454
1455// PrefixExpr
1456#[derive(Debug, Clone, Copy)]
1457pub struct PrefixExpr<'a> {
1458 syntax: SyntaxNodeRef<'a>,
1459}
1460
1461impl<'a> AstNode<'a> for PrefixExpr<'a> {
1462 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1463 match syntax.kind() {
1464 PREFIX_EXPR => Some(PrefixExpr { syntax }),
1465 _ => None,
1466 }
1467 }
1468 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1469}
1470
1471impl<'a> PrefixExpr<'a> {}
1472
1473// RangeExpr
1474#[derive(Debug, Clone, Copy)]
1475pub struct RangeExpr<'a> {
1476 syntax: SyntaxNodeRef<'a>,
1477}
1478
1479impl<'a> AstNode<'a> for RangeExpr<'a> {
1480 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1481 match syntax.kind() {
1482 RANGE_EXPR => Some(RangeExpr { syntax }),
1483 _ => None,
1484 }
1485 }
1486 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1487}
1488
1489impl<'a> RangeExpr<'a> {}
1490
1491// RangePat
1492#[derive(Debug, Clone, Copy)]
1493pub struct RangePat<'a> {
1494 syntax: SyntaxNodeRef<'a>,
1495}
1496
1497impl<'a> AstNode<'a> for RangePat<'a> {
1498 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1499 match syntax.kind() {
1500 RANGE_PAT => Some(RangePat { syntax }),
1501 _ => None,
1502 }
1503 }
1504 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1505}
1506
1507impl<'a> RangePat<'a> {}
1508
1509// RefExpr
1510#[derive(Debug, Clone, Copy)]
1511pub struct RefExpr<'a> {
1512 syntax: SyntaxNodeRef<'a>,
1513}
1514
1515impl<'a> AstNode<'a> for RefExpr<'a> {
1516 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1517 match syntax.kind() {
1518 REF_EXPR => Some(RefExpr { syntax }),
1519 _ => None,
1520 }
1521 }
1522 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1523}
1524
1525impl<'a> RefExpr<'a> {}
1526
1527// RefPat
1528#[derive(Debug, Clone, Copy)]
1529pub struct RefPat<'a> {
1530 syntax: SyntaxNodeRef<'a>,
1531}
1532
1533impl<'a> AstNode<'a> for RefPat<'a> {
1534 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1535 match syntax.kind() {
1536 REF_PAT => Some(RefPat { syntax }),
1537 _ => None,
1538 }
1539 }
1540 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1541}
1542
1543impl<'a> RefPat<'a> {}
1544
1545// ReferenceType
1546#[derive(Debug, Clone, Copy)]
1547pub struct ReferenceType<'a> {
1548 syntax: SyntaxNodeRef<'a>,
1549}
1550
1551impl<'a> AstNode<'a> for ReferenceType<'a> {
1552 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1553 match syntax.kind() {
1554 REFERENCE_TYPE => Some(ReferenceType { syntax }),
1555 _ => None,
1556 }
1557 }
1558 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1559}
1560
1561impl<'a> ReferenceType<'a> {}
1562
1563// RetType
1564#[derive(Debug, Clone, Copy)]
1565pub struct RetType<'a> {
1566 syntax: SyntaxNodeRef<'a>,
1567}
1568
1569impl<'a> AstNode<'a> for RetType<'a> {
1570 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1571 match syntax.kind() {
1572 RET_TYPE => Some(RetType { syntax }),
1573 _ => None,
1574 }
1575 }
1576 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1577}
1578
1579impl<'a> RetType<'a> {}
1580
1581// ReturnExpr
1582#[derive(Debug, Clone, Copy)]
1583pub struct ReturnExpr<'a> {
1584 syntax: SyntaxNodeRef<'a>,
1585}
1586
1587impl<'a> AstNode<'a> for ReturnExpr<'a> {
1588 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1589 match syntax.kind() {
1590 RETURN_EXPR => Some(ReturnExpr { syntax }),
1591 _ => None,
1592 }
1593 }
1594 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1595}
1596
1597impl<'a> ReturnExpr<'a> {}
1598
1599// Root
1600#[derive(Debug, Clone, Copy)]
1601pub struct Root<'a> {
1602 syntax: SyntaxNodeRef<'a>,
1603}
1604
1605impl<'a> AstNode<'a> for Root<'a> {
1606 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1607 match syntax.kind() {
1608 ROOT => Some(Root { syntax }),
1609 _ => None,
1610 }
1611 }
1612 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1613}
1614
1615impl<'a> ast::ModuleItemOwner<'a> for Root<'a> {}
1616impl<'a> ast::FnDefOwner<'a> for Root<'a> {}
1617impl<'a> Root<'a> {
1618 pub fn modules(self) -> impl Iterator<Item = Module<'a>> + 'a {
1619 super::children(self)
1620 }
1621}
1622
1623// SelfParam
1624#[derive(Debug, Clone, Copy)]
1625pub struct SelfParam<'a> {
1626 syntax: SyntaxNodeRef<'a>,
1627}
1628
1629impl<'a> AstNode<'a> for SelfParam<'a> {
1630 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1631 match syntax.kind() {
1632 SELF_PARAM => Some(SelfParam { syntax }),
1633 _ => None,
1634 }
1635 }
1636 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1637}
1638
1639impl<'a> SelfParam<'a> {}
1640
1641// SlicePat
1642#[derive(Debug, Clone, Copy)]
1643pub struct SlicePat<'a> {
1644 syntax: SyntaxNodeRef<'a>,
1645}
1646
1647impl<'a> AstNode<'a> for SlicePat<'a> {
1648 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1649 match syntax.kind() {
1650 SLICE_PAT => Some(SlicePat { syntax }),
1651 _ => None,
1652 }
1653 }
1654 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1655}
1656
1657impl<'a> SlicePat<'a> {}
1658
1659// SliceType
1660#[derive(Debug, Clone, Copy)]
1661pub struct SliceType<'a> {
1662 syntax: SyntaxNodeRef<'a>,
1663}
1664
1665impl<'a> AstNode<'a> for SliceType<'a> {
1666 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1667 match syntax.kind() {
1668 SLICE_TYPE => Some(SliceType { syntax }),
1669 _ => None,
1670 }
1671 }
1672 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1673}
1674
1675impl<'a> SliceType<'a> {}
1676
1677// StaticDef
1678#[derive(Debug, Clone, Copy)]
1679pub struct StaticDef<'a> {
1680 syntax: SyntaxNodeRef<'a>,
1681}
1682
1683impl<'a> AstNode<'a> for StaticDef<'a> {
1684 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1685 match syntax.kind() {
1686 STATIC_DEF => Some(StaticDef { syntax }),
1687 _ => None,
1688 }
1689 }
1690 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1691}
1692
1693impl<'a> ast::NameOwner<'a> for StaticDef<'a> {}
1694impl<'a> ast::TypeParamsOwner<'a> for StaticDef<'a> {}
1695impl<'a> ast::AttrsOwner<'a> for StaticDef<'a> {}
1696impl<'a> StaticDef<'a> {}
1697
1698// Stmt
1699#[derive(Debug, Clone, Copy)]
1700pub enum Stmt<'a> {
1701 ExprStmt(ExprStmt<'a>),
1702 LetStmt(LetStmt<'a>),
1703}
1704
1705impl<'a> AstNode<'a> for Stmt<'a> {
1706 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1707 match syntax.kind() {
1708 EXPR_STMT => Some(Stmt::ExprStmt(ExprStmt { syntax })),
1709 LET_STMT => Some(Stmt::LetStmt(LetStmt { syntax })),
1710 _ => None,
1711 }
1712 }
1713 fn syntax(self) -> SyntaxNodeRef<'a> {
1714 match self {
1715 Stmt::ExprStmt(inner) => inner.syntax(),
1716 Stmt::LetStmt(inner) => inner.syntax(),
1717 }
1718 }
1719}
1720
1721impl<'a> Stmt<'a> {}
1722
1723// StructDef
1724#[derive(Debug, Clone, Copy)]
1725pub struct StructDef<'a> {
1726 syntax: SyntaxNodeRef<'a>,
1727}
1728
1729impl<'a> AstNode<'a> for StructDef<'a> {
1730 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1731 match syntax.kind() {
1732 STRUCT_DEF => Some(StructDef { syntax }),
1733 _ => None,
1734 }
1735 }
1736 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1737}
1738
1739impl<'a> ast::NameOwner<'a> for StructDef<'a> {}
1740impl<'a> ast::TypeParamsOwner<'a> for StructDef<'a> {}
1741impl<'a> ast::AttrsOwner<'a> for StructDef<'a> {}
1742impl<'a> StructDef<'a> {
1743 pub fn fields(self) -> impl Iterator<Item = NamedFieldDef<'a>> + 'a {
1744 super::children(self)
1745 }
1746}
1747
1748// StructLit
1749#[derive(Debug, Clone, Copy)]
1750pub struct StructLit<'a> {
1751 syntax: SyntaxNodeRef<'a>,
1752}
1753
1754impl<'a> AstNode<'a> for StructLit<'a> {
1755 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1756 match syntax.kind() {
1757 STRUCT_LIT => Some(StructLit { syntax }),
1758 _ => None,
1759 }
1760 }
1761 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1762}
1763
1764impl<'a> StructLit<'a> {}
1765
1766// StructPat
1767#[derive(Debug, Clone, Copy)]
1768pub struct StructPat<'a> {
1769 syntax: SyntaxNodeRef<'a>,
1770}
1771
1772impl<'a> AstNode<'a> for StructPat<'a> {
1773 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1774 match syntax.kind() {
1775 STRUCT_PAT => Some(StructPat { syntax }),
1776 _ => None,
1777 }
1778 }
1779 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1780}
1781
1782impl<'a> StructPat<'a> {}
1783
1784// TokenTree
1785#[derive(Debug, Clone, Copy)]
1786pub struct TokenTree<'a> {
1787 syntax: SyntaxNodeRef<'a>,
1788}
1789
1790impl<'a> AstNode<'a> for TokenTree<'a> {
1791 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1792 match syntax.kind() {
1793 TOKEN_TREE => Some(TokenTree { syntax }),
1794 _ => None,
1795 }
1796 }
1797 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1798}
1799
1800impl<'a> TokenTree<'a> {}
1801
1802// TraitDef
1803#[derive(Debug, Clone, Copy)]
1804pub struct TraitDef<'a> {
1805 syntax: SyntaxNodeRef<'a>,
1806}
1807
1808impl<'a> AstNode<'a> for TraitDef<'a> {
1809 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1810 match syntax.kind() {
1811 TRAIT_DEF => Some(TraitDef { syntax }),
1812 _ => None,
1813 }
1814 }
1815 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1816}
1817
1818impl<'a> ast::NameOwner<'a> for TraitDef<'a> {}
1819impl<'a> ast::AttrsOwner<'a> for TraitDef<'a> {}
1820impl<'a> TraitDef<'a> {}
1821
1822// TryExpr
1823#[derive(Debug, Clone, Copy)]
1824pub struct TryExpr<'a> {
1825 syntax: SyntaxNodeRef<'a>,
1826}
1827
1828impl<'a> AstNode<'a> for TryExpr<'a> {
1829 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1830 match syntax.kind() {
1831 TRY_EXPR => Some(TryExpr { syntax }),
1832 _ => None,
1833 }
1834 }
1835 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1836}
1837
1838impl<'a> TryExpr<'a> {}
1839
1840// TupleExpr
1841#[derive(Debug, Clone, Copy)]
1842pub struct TupleExpr<'a> {
1843 syntax: SyntaxNodeRef<'a>,
1844}
1845
1846impl<'a> AstNode<'a> for TupleExpr<'a> {
1847 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1848 match syntax.kind() {
1849 TUPLE_EXPR => Some(TupleExpr { syntax }),
1850 _ => None,
1851 }
1852 }
1853 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1854}
1855
1856impl<'a> TupleExpr<'a> {}
1857
1858// TuplePat
1859#[derive(Debug, Clone, Copy)]
1860pub struct TuplePat<'a> {
1861 syntax: SyntaxNodeRef<'a>,
1862}
1863
1864impl<'a> AstNode<'a> for TuplePat<'a> {
1865 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1866 match syntax.kind() {
1867 TUPLE_PAT => Some(TuplePat { syntax }),
1868 _ => None,
1869 }
1870 }
1871 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1872}
1873
1874impl<'a> TuplePat<'a> {}
1875
1876// TupleStructPat
1877#[derive(Debug, Clone, Copy)]
1878pub struct TupleStructPat<'a> {
1879 syntax: SyntaxNodeRef<'a>,
1880}
1881
1882impl<'a> AstNode<'a> for TupleStructPat<'a> {
1883 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1884 match syntax.kind() {
1885 TUPLE_STRUCT_PAT => Some(TupleStructPat { syntax }),
1886 _ => None,
1887 }
1888 }
1889 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1890}
1891
1892impl<'a> TupleStructPat<'a> {}
1893
1894// TupleType
1895#[derive(Debug, Clone, Copy)]
1896pub struct TupleType<'a> {
1897 syntax: SyntaxNodeRef<'a>,
1898}
1899
1900impl<'a> AstNode<'a> for TupleType<'a> {
1901 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1902 match syntax.kind() {
1903 TUPLE_TYPE => Some(TupleType { syntax }),
1904 _ => None,
1905 }
1906 }
1907 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1908}
1909
1910impl<'a> TupleType<'a> {}
1911
1912// TypeDef
1913#[derive(Debug, Clone, Copy)]
1914pub struct TypeDef<'a> {
1915 syntax: SyntaxNodeRef<'a>,
1916}
1917
1918impl<'a> AstNode<'a> for TypeDef<'a> {
1919 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1920 match syntax.kind() {
1921 TYPE_DEF => Some(TypeDef { syntax }),
1922 _ => None,
1923 }
1924 }
1925 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1926}
1927
1928impl<'a> ast::NameOwner<'a> for TypeDef<'a> {}
1929impl<'a> ast::TypeParamsOwner<'a> for TypeDef<'a> {}
1930impl<'a> ast::AttrsOwner<'a> for TypeDef<'a> {}
1931impl<'a> TypeDef<'a> {}
1932
1933// TypeParam
1934#[derive(Debug, Clone, Copy)]
1935pub struct TypeParam<'a> {
1936 syntax: SyntaxNodeRef<'a>,
1937}
1938
1939impl<'a> AstNode<'a> for TypeParam<'a> {
1940 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1941 match syntax.kind() {
1942 TYPE_PARAM => Some(TypeParam { syntax }),
1943 _ => None,
1944 }
1945 }
1946 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1947}
1948
1949impl<'a> ast::NameOwner<'a> for TypeParam<'a> {}
1950impl<'a> TypeParam<'a> {}
1951
1952// TypeParamList
1953#[derive(Debug, Clone, Copy)]
1954pub struct TypeParamList<'a> {
1955 syntax: SyntaxNodeRef<'a>,
1956}
1957
1958impl<'a> AstNode<'a> for TypeParamList<'a> {
1959 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1960 match syntax.kind() {
1961 TYPE_PARAM_LIST => Some(TypeParamList { syntax }),
1962 _ => None,
1963 }
1964 }
1965 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1966}
1967
1968impl<'a> TypeParamList<'a> {
1969 pub fn type_params(self) -> impl Iterator<Item = TypeParam<'a>> + 'a {
1970 super::children(self)
1971 }
1972
1973 pub fn lifetime_params(self) -> impl Iterator<Item = LifetimeParam<'a>> + 'a {
1974 super::children(self)
1975 }
1976}
1977
1978// TypeRef
1979#[derive(Debug, Clone, Copy)]
1980pub enum TypeRef<'a> {
1981 ParenType(ParenType<'a>),
1982 TupleType(TupleType<'a>),
1983 NeverType(NeverType<'a>),
1984 PathType(PathType<'a>),
1985 PointerType(PointerType<'a>),
1986 ArrayType(ArrayType<'a>),
1987 SliceType(SliceType<'a>),
1988 ReferenceType(ReferenceType<'a>),
1989 PlaceholderType(PlaceholderType<'a>),
1990 FnPointerType(FnPointerType<'a>),
1991 ForType(ForType<'a>),
1992 ImplTraitType(ImplTraitType<'a>),
1993 DynTraitType(DynTraitType<'a>),
1994}
1995
1996impl<'a> AstNode<'a> for TypeRef<'a> {
1997 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1998 match syntax.kind() {
1999 PAREN_TYPE => Some(TypeRef::ParenType(ParenType { syntax })),
2000 TUPLE_TYPE => Some(TypeRef::TupleType(TupleType { syntax })),
2001 NEVER_TYPE => Some(TypeRef::NeverType(NeverType { syntax })),
2002 PATH_TYPE => Some(TypeRef::PathType(PathType { syntax })),
2003 POINTER_TYPE => Some(TypeRef::PointerType(PointerType { syntax })),
2004 ARRAY_TYPE => Some(TypeRef::ArrayType(ArrayType { syntax })),
2005 SLICE_TYPE => Some(TypeRef::SliceType(SliceType { syntax })),
2006 REFERENCE_TYPE => Some(TypeRef::ReferenceType(ReferenceType { syntax })),
2007 PLACEHOLDER_TYPE => Some(TypeRef::PlaceholderType(PlaceholderType { syntax })),
2008 FN_POINTER_TYPE => Some(TypeRef::FnPointerType(FnPointerType { syntax })),
2009 FOR_TYPE => Some(TypeRef::ForType(ForType { syntax })),
2010 IMPL_TRAIT_TYPE => Some(TypeRef::ImplTraitType(ImplTraitType { syntax })),
2011 DYN_TRAIT_TYPE => Some(TypeRef::DynTraitType(DynTraitType { syntax })),
2012 _ => None,
2013 }
2014 }
2015 fn syntax(self) -> SyntaxNodeRef<'a> {
2016 match self {
2017 TypeRef::ParenType(inner) => inner.syntax(),
2018 TypeRef::TupleType(inner) => inner.syntax(),
2019 TypeRef::NeverType(inner) => inner.syntax(),
2020 TypeRef::PathType(inner) => inner.syntax(),
2021 TypeRef::PointerType(inner) => inner.syntax(),
2022 TypeRef::ArrayType(inner) => inner.syntax(),
2023 TypeRef::SliceType(inner) => inner.syntax(),
2024 TypeRef::ReferenceType(inner) => inner.syntax(),
2025 TypeRef::PlaceholderType(inner) => inner.syntax(),
2026 TypeRef::FnPointerType(inner) => inner.syntax(),
2027 TypeRef::ForType(inner) => inner.syntax(),
2028 TypeRef::ImplTraitType(inner) => inner.syntax(),
2029 TypeRef::DynTraitType(inner) => inner.syntax(),
2030 }
2031 }
2032}
2033
2034impl<'a> TypeRef<'a> {}
2035
2036// UseItem
2037#[derive(Debug, Clone, Copy)]
2038pub struct UseItem<'a> {
2039 syntax: SyntaxNodeRef<'a>,
2040}
2041
2042impl<'a> AstNode<'a> for UseItem<'a> {
2043 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
2044 match syntax.kind() {
2045 USE_ITEM => Some(UseItem { syntax }),
2046 _ => None,
2047 }
2048 }
2049 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
2050}
2051
2052impl<'a> UseItem<'a> {pub fn use_tree(self) -> Option<UseTree<'a>> {
2053 super::child_opt(self)
2054 }
2055}
2056
2057// UseTree
2058#[derive(Debug, Clone, Copy)]
2059pub struct UseTree<'a> {
2060 syntax: SyntaxNodeRef<'a>,
2061}
2062
2063impl<'a> AstNode<'a> for UseTree<'a> {
2064 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
2065 match syntax.kind() {
2066 USE_TREE => Some(UseTree { syntax }),
2067 _ => None,
2068 }
2069 }
2070 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
2071}
2072
2073impl<'a> UseTree<'a> {pub fn path(self) -> Option<Path<'a>> {
2074 super::child_opt(self)
2075 }
2076pub fn use_tree_list(self) -> Option<UseTreeList<'a>> {
2077 super::child_opt(self)
2078 }
2079}
2080
2081// UseTreeList
2082#[derive(Debug, Clone, Copy)]
2083pub struct UseTreeList<'a> {
2084 syntax: SyntaxNodeRef<'a>,
2085}
2086
2087impl<'a> AstNode<'a> for UseTreeList<'a> {
2088 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
2089 match syntax.kind() {
2090 USE_TREE_LIST => Some(UseTreeList { syntax }),
2091 _ => None,
2092 }
2093 }
2094 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
2095}
2096
2097impl<'a> UseTreeList<'a> {
2098 pub fn use_trees(self) -> impl Iterator<Item = UseTree<'a>> + 'a {
2099 super::children(self)
2100 }
2101}
2102
2103// WhereClause
2104#[derive(Debug, Clone, Copy)]
2105pub struct WhereClause<'a> {
2106 syntax: SyntaxNodeRef<'a>,
2107}
2108
2109impl<'a> AstNode<'a> for WhereClause<'a> {
2110 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
2111 match syntax.kind() {
2112 WHERE_CLAUSE => Some(WhereClause { syntax }),
2113 _ => None,
2114 }
2115 }
2116 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
2117}
2118
2119impl<'a> WhereClause<'a> {}
2120
2121// WhileExpr
2122#[derive(Debug, Clone, Copy)]
2123pub struct WhileExpr<'a> {
2124 syntax: SyntaxNodeRef<'a>,
2125}
2126
2127impl<'a> AstNode<'a> for WhileExpr<'a> {
2128 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
2129 match syntax.kind() {
2130 WHILE_EXPR => Some(WhileExpr { syntax }),
2131 _ => None,
2132 }
2133 }
2134 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
2135}
2136
2137impl<'a> ast::LoopBodyOwner<'a> for WhileExpr<'a> {}
2138impl<'a> WhileExpr<'a> {pub fn condition(self) -> Option<Condition<'a>> {
2139 super::child_opt(self)
2140 }
2141}
2142
diff --git a/crates/libsyntax2/src/ast/generated.rs.tera b/crates/libsyntax2/src/ast/generated.rs.tera
deleted file mode 100644
index a72e9b732..000000000
--- a/crates/libsyntax2/src/ast/generated.rs.tera
+++ /dev/null
@@ -1,83 +0,0 @@
1use {
2 ast,
3 SyntaxNodeRef, AstNode,
4 SyntaxKind::*,
5};
6{% for node, methods in ast %}
7// {{ node }}
8{%- if methods.enum %}
9#[derive(Debug, Clone, Copy)]
10pub enum {{ node }}<'a> {
11{%- for kind in methods.enum %}
12 {{ kind }}({{ kind }}<'a>),
13{%- endfor %}
14}
15
16impl<'a> AstNode<'a> for {{ node }}<'a> {
17 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
18 match syntax.kind() {
19{%- for kind in methods.enum %}
20 {{ kind | SCREAM }} => Some({{ node }}::{{ kind }}({{ kind }} { syntax })),
21{%- endfor %}
22 _ => None,
23 }
24 }
25 fn syntax(self) -> SyntaxNodeRef<'a> {
26 match self {
27{%- for kind in methods.enum %}
28 {{ node }}::{{ kind }}(inner) => inner.syntax(),
29{%- endfor %}
30 }
31 }
32}
33{% else %}
34#[derive(Debug, Clone, Copy)]
35pub struct {{ node }}<'a> {
36 syntax: SyntaxNodeRef<'a>,
37}
38
39impl<'a> AstNode<'a> for {{ node }}<'a> {
40 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
41 match syntax.kind() {
42 {{ node | SCREAM }} => Some({{ node }} { syntax }),
43 _ => None,
44 }
45 }
46 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
47}
48{% endif %}
49{% if methods.traits -%}
50{%- for t in methods.traits -%}
51impl<'a> ast::{{ t }}<'a> for {{ node }}<'a> {}
52{% endfor -%}
53{%- endif -%}
54
55impl<'a> {{ node }}<'a> {
56{%- if methods.collections -%}
57{%- for m in methods.collections -%}
58{%- set method_name = m.0 -%}
59{%- set ChildName = m.1 %}
60 pub fn {{ method_name }}(self) -> impl Iterator<Item = {{ ChildName }}<'a>> + 'a {
61 super::children(self)
62 }
63{% endfor -%}
64{%- endif -%}
65
66{%- if methods.options -%}
67{%- for m in methods.options -%}
68
69{%- if m is string -%}
70{%- set method_name = m | snake -%}
71{%- set ChildName = m %}
72{%- else -%}
73{%- set method_name = m.0 -%}
74{%- set ChildName = m.1 %}
75{%- endif -%}
76
77 pub fn {{ method_name }}(self) -> Option<{{ ChildName }}<'a>> {
78 super::child_opt(self)
79 }
80{% endfor -%}
81{%- endif -%}
82}
83{% endfor %}
diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs
deleted file mode 100644
index a6da82957..000000000
--- a/crates/libsyntax2/src/ast/mod.rs
+++ /dev/null
@@ -1,206 +0,0 @@
1mod generated;
2
3use std::marker::PhantomData;
4
5use itertools::Itertools;
6use smol_str::SmolStr;
7
8use {
9 SyntaxNodeRef, SyntaxKind::*,
10 yellow::{RefRoot, SyntaxNodeChildren},
11};
12pub use self::generated::*;
13
14pub trait AstNode<'a>: Clone + Copy + 'a {
15 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self>
16 where Self: Sized;
17 fn syntax(self) -> SyntaxNodeRef<'a>;
18}
19
20pub trait NameOwner<'a>: AstNode<'a> {
21 fn name(self) -> Option<Name<'a>> {
22 child_opt(self)
23 }
24}
25
26pub trait LoopBodyOwner<'a>: AstNode<'a> {
27 fn loop_body(self) -> Option<Block<'a>> {
28 child_opt(self)
29 }
30}
31
32pub trait ArgListOwner<'a>: AstNode<'a> {
33 fn arg_list(self) -> Option<ArgList<'a>> {
34 child_opt(self)
35 }
36}
37
38pub trait FnDefOwner<'a>: AstNode<'a> {
39 fn functions(self) -> AstChildren<'a, FnDef<'a>> {
40 children(self)
41 }
42}
43
44pub trait ModuleItemOwner<'a>: AstNode<'a> {
45 fn items(self) -> AstChildren<'a, ModuleItem<'a>> {
46 children(self)
47 }
48}
49
50pub trait TypeParamsOwner<'a>: AstNode<'a> {
51 fn type_param_list(self) -> Option<TypeParamList<'a>> {
52 child_opt(self)
53 }
54
55 fn where_clause(self) -> Option<WhereClause<'a>> {
56 child_opt(self)
57 }
58}
59
60pub trait AttrsOwner<'a>: AstNode<'a> {
61 fn attrs(self) -> AstChildren<'a, Attr<'a>> {
62 children(self)
63 }
64}
65
66impl<'a> FnDef<'a> {
67 pub fn has_atom_attr(&self, atom: &str) -> bool {
68 self.attrs()
69 .filter_map(|x| x.as_atom())
70 .any(|x| x == atom)
71 }
72}
73
74impl<'a> Attr<'a> {
75 pub fn as_atom(&self) -> Option<SmolStr> {
76 let tt = self.value()?;
77 let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?;
78 if attr.kind() == IDENT {
79 Some(attr.leaf_text().unwrap())
80 } else {
81 None
82 }
83 }
84
85 pub fn as_call(&self) -> Option<(SmolStr, TokenTree<'a>)> {
86 let tt = self.value()?;
87 let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?;
88 let args = TokenTree::cast(args)?;
89 if attr.kind() == IDENT {
90 Some((attr.leaf_text().unwrap(), args))
91 } else {
92 None
93 }
94 }
95}
96
97impl<'a> Lifetime<'a> {
98 pub fn text(&self) -> SmolStr {
99 self.syntax().leaf_text().unwrap()
100 }
101}
102
103impl<'a> Name<'a> {
104 pub fn text(&self) -> SmolStr {
105 let ident = self.syntax().first_child()
106 .unwrap();
107 ident.leaf_text().unwrap()
108 }
109}
110
111impl<'a> NameRef<'a> {
112 pub fn text(&self) -> SmolStr {
113 let ident = self.syntax().first_child()
114 .unwrap();
115 ident.leaf_text().unwrap()
116 }
117}
118
119impl<'a> ImplItem<'a> {
120 pub fn target_type(self) -> Option<TypeRef<'a>> {
121 match self.target() {
122 (Some(t), None) | (_, Some(t)) => Some(t),
123 _ => None,
124 }
125 }
126
127 pub fn target_trait(self) -> Option<TypeRef<'a>> {
128 match self.target() {
129 (Some(t), Some(_)) => Some(t),
130 _ => None,
131 }
132 }
133
134 fn target(self) -> (Option<TypeRef<'a>>, Option<TypeRef<'a>>) {
135 let mut types = children(self);
136 let first = types.next();
137 let second = types.next();
138 (first, second)
139 }
140}
141
142impl<'a> Module<'a> {
143 pub fn has_semi(self) -> bool {
144 match self.syntax().last_child() {
145 None => false,
146 Some(node) => node.kind() == SEMI,
147 }
148 }
149}
150
151impl<'a> LetStmt<'a> {
152 pub fn has_semi(self) -> bool {
153 match self.syntax().last_child() {
154 None => false,
155 Some(node) => node.kind() == SEMI,
156 }
157 }
158}
159
160impl<'a> IfExpr<'a> {
161 pub fn then_branch(self) -> Option<Block<'a>> {
162 self.blocks().nth(0)
163 }
164 pub fn else_branch(self) -> Option<Block<'a>> {
165 self.blocks().nth(1)
166 }
167 fn blocks(self) -> AstChildren<'a, Block<'a>> {
168 children(self)
169 }
170}
171
172fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> {
173 children(parent).next()
174}
175
176fn children<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> AstChildren<'a, C> {
177 AstChildren::new(parent.syntax())
178}
179
180
181#[derive(Debug)]
182pub struct AstChildren<'a, N> {
183 inner: SyntaxNodeChildren<RefRoot<'a>>,
184 ph: PhantomData<N>,
185}
186
187impl<'a, N> AstChildren<'a, N> {
188 fn new(parent: SyntaxNodeRef<'a>) -> Self {
189 AstChildren {
190 inner: parent.children(),
191 ph: PhantomData,
192 }
193 }
194}
195
196impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> {
197 type Item = N;
198 fn next(&mut self) -> Option<N> {
199 loop {
200 match N::cast(self.inner.next()?) {
201 Some(n) => return Some(n),
202 None => (),
203 }
204 }
205 }
206}