aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-10 09:07:09 +0100
committerAleksey Kladov <[email protected]>2020-04-10 15:10:28 +0100
commitf89f2e38855f5b47f68758e98139aa962cb7a01d (patch)
tree7065879c9b77c2843959abdf82356d75f36c500f
parentff5643c52445c516b8b32bc6062c66203ca13ee4 (diff)
More readable ast_src for keywords
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs146
-rw-r--r--xtask/src/ast_src.rs147
-rw-r--r--xtask/src/codegen/gen_syntax.rs90
3 files changed, 210 insertions, 173 deletions
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index 20f663046..3b014e312 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -4,7 +4,7 @@ use super::tokens::*;
4use crate::{ 4use crate::{
5 ast::{self, support, AstChildren, AstNode}, 5 ast::{self, support, AstChildren, AstNode},
6 SyntaxKind::{self, *}, 6 SyntaxKind::{self, *},
7 SyntaxNode, SyntaxToken, 7 SyntaxNode, SyntaxToken, T,
8}; 8};
9#[derive(Debug, Clone, PartialEq, Eq, Hash)] 9#[derive(Debug, Clone, PartialEq, Eq, Hash)]
10pub struct SourceFile { 10pub struct SourceFile {
@@ -48,11 +48,13 @@ impl ast::DocCommentsOwner for FnDef {}
48impl ast::AttrsOwner for FnDef {} 48impl ast::AttrsOwner for FnDef {}
49impl FnDef { 49impl FnDef {
50 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } 50 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) }
51 pub fn const_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, CONST_KW) } 51 pub fn const_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![const]) }
52 pub fn default_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, DEFAULT_KW) } 52 pub fn default_token(&self) -> Option<SyntaxToken> {
53 pub fn async_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, ASYNC_KW) } 53 support::token2(&self.syntax, T![default])
54 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, UNSAFE_KW) } 54 }
55 pub fn fn_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, FN_KW) } 55 pub fn async_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![async]) }
56 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![unsafe]) }
57 pub fn fn_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![fn]) }
56 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } 58 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
57 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } 59 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
58 pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) } 60 pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
@@ -98,7 +100,7 @@ impl ast::TypeParamsOwner for StructDef {}
98impl ast::AttrsOwner for StructDef {} 100impl ast::AttrsOwner for StructDef {}
99impl ast::DocCommentsOwner for StructDef {} 101impl ast::DocCommentsOwner for StructDef {}
100impl StructDef { 102impl StructDef {
101 pub fn struct_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, STRUCT_KW) } 103 pub fn struct_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![struct]) }
102 pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) } 104 pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) }
103 pub fn semi_token(&self) -> Option<Semi> { support::token(&self.syntax) } 105 pub fn semi_token(&self) -> Option<Semi> { support::token(&self.syntax) }
104} 106}
@@ -123,7 +125,7 @@ impl ast::TypeParamsOwner for UnionDef {}
123impl ast::AttrsOwner for UnionDef {} 125impl ast::AttrsOwner for UnionDef {}
124impl ast::DocCommentsOwner for UnionDef {} 126impl ast::DocCommentsOwner for UnionDef {}
125impl UnionDef { 127impl UnionDef {
126 pub fn union_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, UNION_KW) } 128 pub fn union_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![union]) }
127 pub fn record_field_def_list(&self) -> Option<RecordFieldDefList> { 129 pub fn record_field_def_list(&self) -> Option<RecordFieldDefList> {
128 support::child(&self.syntax) 130 support::child(&self.syntax)
129 } 131 }
@@ -230,7 +232,7 @@ impl ast::TypeParamsOwner for EnumDef {}
230impl ast::AttrsOwner for EnumDef {} 232impl ast::AttrsOwner for EnumDef {}
231impl ast::DocCommentsOwner for EnumDef {} 233impl ast::DocCommentsOwner for EnumDef {}
232impl EnumDef { 234impl EnumDef {
233 pub fn enum_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, ENUM_KW) } 235 pub fn enum_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![enum]) }
234 pub fn variant_list(&self) -> Option<EnumVariantList> { support::child(&self.syntax) } 236 pub fn variant_list(&self) -> Option<EnumVariantList> { support::child(&self.syntax) }
235} 237}
236#[derive(Debug, Clone, PartialEq, Eq, Hash)] 238#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -299,9 +301,9 @@ impl ast::DocCommentsOwner for TraitDef {}
299impl ast::TypeParamsOwner for TraitDef {} 301impl ast::TypeParamsOwner for TraitDef {}
300impl ast::TypeBoundsOwner for TraitDef {} 302impl ast::TypeBoundsOwner for TraitDef {}
301impl TraitDef { 303impl TraitDef {
302 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, UNSAFE_KW) } 304 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![unsafe]) }
303 pub fn auto_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, AUTO_KW) } 305 pub fn auto_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![auto]) }
304 pub fn trait_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, TRAIT_KW) } 306 pub fn trait_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![trait]) }
305 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } 307 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) }
306} 308}
307#[derive(Debug, Clone, PartialEq, Eq, Hash)] 309#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -324,7 +326,7 @@ impl ast::NameOwner for Module {}
324impl ast::AttrsOwner for Module {} 326impl ast::AttrsOwner for Module {}
325impl ast::DocCommentsOwner for Module {} 327impl ast::DocCommentsOwner for Module {}
326impl Module { 328impl Module {
327 pub fn mod_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, MOD_KW) } 329 pub fn mod_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![mod]) }
328 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } 330 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) }
329 pub fn semi_token(&self) -> Option<Semi> { support::token(&self.syntax) } 331 pub fn semi_token(&self) -> Option<Semi> { support::token(&self.syntax) }
330} 332}
@@ -371,8 +373,10 @@ impl ast::AttrsOwner for ConstDef {}
371impl ast::DocCommentsOwner for ConstDef {} 373impl ast::DocCommentsOwner for ConstDef {}
372impl ast::TypeAscriptionOwner for ConstDef {} 374impl ast::TypeAscriptionOwner for ConstDef {}
373impl ConstDef { 375impl ConstDef {
374 pub fn default_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, DEFAULT_KW) } 376 pub fn default_token(&self) -> Option<SyntaxToken> {
375 pub fn const_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, CONST_KW) } 377 support::token2(&self.syntax, T![default])
378 }
379 pub fn const_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![const]) }
376 pub fn eq_token(&self) -> Option<Eq> { support::token(&self.syntax) } 380 pub fn eq_token(&self) -> Option<Eq> { support::token(&self.syntax) }
377 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } 381 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
378 pub fn semi_token(&self) -> Option<Semi> { support::token(&self.syntax) } 382 pub fn semi_token(&self) -> Option<Semi> { support::token(&self.syntax) }
@@ -399,8 +403,8 @@ impl ast::AttrsOwner for StaticDef {}
399impl ast::DocCommentsOwner for StaticDef {} 403impl ast::DocCommentsOwner for StaticDef {}
400impl ast::TypeAscriptionOwner for StaticDef {} 404impl ast::TypeAscriptionOwner for StaticDef {}
401impl StaticDef { 405impl StaticDef {
402 pub fn static_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, STATIC_KW) } 406 pub fn static_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![static]) }
403 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, MUT_KW) } 407 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![mut]) }
404 pub fn eq_token(&self) -> Option<Eq> { support::token(&self.syntax) } 408 pub fn eq_token(&self) -> Option<Eq> { support::token(&self.syntax) }
405 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } 409 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
406 pub fn semi_token(&self) -> Option<Semi> { support::token(&self.syntax) } 410 pub fn semi_token(&self) -> Option<Semi> { support::token(&self.syntax) }
@@ -427,8 +431,10 @@ impl ast::AttrsOwner for TypeAliasDef {}
427impl ast::DocCommentsOwner for TypeAliasDef {} 431impl ast::DocCommentsOwner for TypeAliasDef {}
428impl ast::TypeBoundsOwner for TypeAliasDef {} 432impl ast::TypeBoundsOwner for TypeAliasDef {}
429impl TypeAliasDef { 433impl TypeAliasDef {
430 pub fn default_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, DEFAULT_KW) } 434 pub fn default_token(&self) -> Option<SyntaxToken> {
431 pub fn type_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, TYPE_KW) } 435 support::token2(&self.syntax, T![default])
436 }
437 pub fn type_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![type]) }
432 pub fn eq_token(&self) -> Option<Eq> { support::token(&self.syntax) } 438 pub fn eq_token(&self) -> Option<Eq> { support::token(&self.syntax) }
433 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 439 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
434 pub fn semi_token(&self) -> Option<Semi> { support::token(&self.syntax) } 440 pub fn semi_token(&self) -> Option<Semi> { support::token(&self.syntax) }
@@ -451,12 +457,14 @@ impl AstNode for ImplDef {
451impl ast::TypeParamsOwner for ImplDef {} 457impl ast::TypeParamsOwner for ImplDef {}
452impl ast::AttrsOwner for ImplDef {} 458impl ast::AttrsOwner for ImplDef {}
453impl ImplDef { 459impl ImplDef {
454 pub fn default_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, DEFAULT_KW) } 460 pub fn default_token(&self) -> Option<SyntaxToken> {
455 pub fn const_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, CONST_KW) } 461 support::token2(&self.syntax, T![default])
456 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, UNSAFE_KW) } 462 }
457 pub fn impl_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, IMPL_KW) } 463 pub fn const_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![const]) }
464 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![unsafe]) }
465 pub fn impl_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![impl]) }
458 pub fn excl_token(&self) -> Option<Excl> { support::token(&self.syntax) } 466 pub fn excl_token(&self) -> Option<Excl> { support::token(&self.syntax) }
459 pub fn for_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, FOR_KW) } 467 pub fn for_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![for]) }
460 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } 468 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) }
461} 469}
462#[derive(Debug, Clone, PartialEq, Eq, Hash)] 470#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -552,8 +560,8 @@ impl AstNode for PointerType {
552} 560}
553impl PointerType { 561impl PointerType {
554 pub fn star_token(&self) -> Option<Star> { support::token(&self.syntax) } 562 pub fn star_token(&self) -> Option<Star> { support::token(&self.syntax) }
555 pub fn const_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, CONST_KW) } 563 pub fn const_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![const]) }
556 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, MUT_KW) } 564 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![mut]) }
557 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 565 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
558} 566}
559#[derive(Debug, Clone, PartialEq, Eq, Hash)] 567#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -616,7 +624,7 @@ impl AstNode for ReferenceType {
616impl ReferenceType { 624impl ReferenceType {
617 pub fn amp_token(&self) -> Option<Amp> { support::token(&self.syntax) } 625 pub fn amp_token(&self) -> Option<Amp> { support::token(&self.syntax) }
618 pub fn lifetime_token(&self) -> Option<Lifetime> { support::token(&self.syntax) } 626 pub fn lifetime_token(&self) -> Option<Lifetime> { support::token(&self.syntax) }
619 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, MUT_KW) } 627 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![mut]) }
620 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 628 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
621} 629}
622#[derive(Debug, Clone, PartialEq, Eq, Hash)] 630#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -654,8 +662,8 @@ impl AstNode for FnPointerType {
654} 662}
655impl FnPointerType { 663impl FnPointerType {
656 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } 664 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) }
657 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, UNSAFE_KW) } 665 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![unsafe]) }
658 pub fn fn_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, FN_KW) } 666 pub fn fn_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![fn]) }
659 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } 667 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
660 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } 668 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
661} 669}
@@ -675,7 +683,7 @@ impl AstNode for ForType {
675 fn syntax(&self) -> &SyntaxNode { &self.syntax } 683 fn syntax(&self) -> &SyntaxNode { &self.syntax }
676} 684}
677impl ForType { 685impl ForType {
678 pub fn for_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, FOR_KW) } 686 pub fn for_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![for]) }
679 pub fn type_param_list(&self) -> Option<TypeParamList> { support::child(&self.syntax) } 687 pub fn type_param_list(&self) -> Option<TypeParamList> { support::child(&self.syntax) }
680 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 688 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
681} 689}
@@ -696,7 +704,7 @@ impl AstNode for ImplTraitType {
696} 704}
697impl ast::TypeBoundsOwner for ImplTraitType {} 705impl ast::TypeBoundsOwner for ImplTraitType {}
698impl ImplTraitType { 706impl ImplTraitType {
699 pub fn impl_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, IMPL_KW) } 707 pub fn impl_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![impl]) }
700} 708}
701#[derive(Debug, Clone, PartialEq, Eq, Hash)] 709#[derive(Debug, Clone, PartialEq, Eq, Hash)]
702pub struct DynTraitType { 710pub struct DynTraitType {
@@ -715,7 +723,7 @@ impl AstNode for DynTraitType {
715} 723}
716impl ast::TypeBoundsOwner for DynTraitType {} 724impl ast::TypeBoundsOwner for DynTraitType {}
717impl DynTraitType { 725impl DynTraitType {
718 pub fn dyn_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, DYN_KW) } 726 pub fn dyn_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![dyn]) }
719} 727}
720#[derive(Debug, Clone, PartialEq, Eq, Hash)] 728#[derive(Debug, Clone, PartialEq, Eq, Hash)]
721pub struct TupleExpr { 729pub struct TupleExpr {
@@ -816,9 +824,9 @@ impl AstNode for LambdaExpr {
816} 824}
817impl ast::AttrsOwner for LambdaExpr {} 825impl ast::AttrsOwner for LambdaExpr {}
818impl LambdaExpr { 826impl LambdaExpr {
819 pub fn static_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, STATIC_KW) } 827 pub fn static_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![static]) }
820 pub fn async_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, ASYNC_KW) } 828 pub fn async_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![async]) }
821 pub fn move_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, MOVE_KW) } 829 pub fn move_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![move]) }
822 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } 830 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
823 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } 831 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
824 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } 832 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
@@ -840,7 +848,7 @@ impl AstNode for IfExpr {
840} 848}
841impl ast::AttrsOwner for IfExpr {} 849impl ast::AttrsOwner for IfExpr {}
842impl IfExpr { 850impl IfExpr {
843 pub fn if_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, IF_KW) } 851 pub fn if_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![if]) }
844 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } 852 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) }
845} 853}
846#[derive(Debug, Clone, PartialEq, Eq, Hash)] 854#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -861,7 +869,7 @@ impl AstNode for LoopExpr {
861impl ast::AttrsOwner for LoopExpr {} 869impl ast::AttrsOwner for LoopExpr {}
862impl ast::LoopBodyOwner for LoopExpr {} 870impl ast::LoopBodyOwner for LoopExpr {}
863impl LoopExpr { 871impl LoopExpr {
864 pub fn loop_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, LOOP_KW) } 872 pub fn loop_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![loop]) }
865} 873}
866#[derive(Debug, Clone, PartialEq, Eq, Hash)] 874#[derive(Debug, Clone, PartialEq, Eq, Hash)]
867pub struct TryBlockExpr { 875pub struct TryBlockExpr {
@@ -880,7 +888,7 @@ impl AstNode for TryBlockExpr {
880} 888}
881impl ast::AttrsOwner for TryBlockExpr {} 889impl ast::AttrsOwner for TryBlockExpr {}
882impl TryBlockExpr { 890impl TryBlockExpr {
883 pub fn try_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, TRY_KW) } 891 pub fn try_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![try]) }
884 pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) } 892 pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
885} 893}
886#[derive(Debug, Clone, PartialEq, Eq, Hash)] 894#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -901,9 +909,9 @@ impl AstNode for ForExpr {
901impl ast::AttrsOwner for ForExpr {} 909impl ast::AttrsOwner for ForExpr {}
902impl ast::LoopBodyOwner for ForExpr {} 910impl ast::LoopBodyOwner for ForExpr {}
903impl ForExpr { 911impl ForExpr {
904 pub fn for_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, FOR_KW) } 912 pub fn for_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![for]) }
905 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 913 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
906 pub fn in_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, IN_KW) } 914 pub fn in_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![in]) }
907 pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) } 915 pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) }
908} 916}
909#[derive(Debug, Clone, PartialEq, Eq, Hash)] 917#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -924,7 +932,7 @@ impl AstNode for WhileExpr {
924impl ast::AttrsOwner for WhileExpr {} 932impl ast::AttrsOwner for WhileExpr {}
925impl ast::LoopBodyOwner for WhileExpr {} 933impl ast::LoopBodyOwner for WhileExpr {}
926impl WhileExpr { 934impl WhileExpr {
927 pub fn while_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, WHILE_KW) } 935 pub fn while_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![while]) }
928 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } 936 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) }
929} 937}
930#[derive(Debug, Clone, PartialEq, Eq, Hash)] 938#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -945,7 +953,7 @@ impl AstNode for ContinueExpr {
945impl ast::AttrsOwner for ContinueExpr {} 953impl ast::AttrsOwner for ContinueExpr {}
946impl ContinueExpr { 954impl ContinueExpr {
947 pub fn continue_token(&self) -> Option<SyntaxToken> { 955 pub fn continue_token(&self) -> Option<SyntaxToken> {
948 support::token2(&self.syntax, CONTINUE_KW) 956 support::token2(&self.syntax, T![continue])
949 } 957 }
950 pub fn lifetime_token(&self) -> Option<Lifetime> { support::token(&self.syntax) } 958 pub fn lifetime_token(&self) -> Option<Lifetime> { support::token(&self.syntax) }
951} 959}
@@ -966,7 +974,7 @@ impl AstNode for BreakExpr {
966} 974}
967impl ast::AttrsOwner for BreakExpr {} 975impl ast::AttrsOwner for BreakExpr {}
968impl BreakExpr { 976impl BreakExpr {
969 pub fn break_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, BREAK_KW) } 977 pub fn break_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![break]) }
970 pub fn lifetime_token(&self) -> Option<Lifetime> { support::token(&self.syntax) } 978 pub fn lifetime_token(&self) -> Option<Lifetime> { support::token(&self.syntax) }
971 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 979 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
972} 980}
@@ -1006,7 +1014,7 @@ impl AstNode for BlockExpr {
1006impl ast::AttrsOwner for BlockExpr {} 1014impl ast::AttrsOwner for BlockExpr {}
1007impl BlockExpr { 1015impl BlockExpr {
1008 pub fn label(&self) -> Option<Label> { support::child(&self.syntax) } 1016 pub fn label(&self) -> Option<Label> { support::child(&self.syntax) }
1009 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, UNSAFE_KW) } 1017 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![unsafe]) }
1010 pub fn block(&self) -> Option<Block> { support::child(&self.syntax) } 1018 pub fn block(&self) -> Option<Block> { support::child(&self.syntax) }
1011} 1019}
1012#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1020#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -1130,7 +1138,7 @@ impl ast::AttrsOwner for AwaitExpr {}
1130impl AwaitExpr { 1138impl AwaitExpr {
1131 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1139 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1132 pub fn dot_token(&self) -> Option<Dot> { support::token(&self.syntax) } 1140 pub fn dot_token(&self) -> Option<Dot> { support::token(&self.syntax) }
1133 pub fn await_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, AWAIT_KW) } 1141 pub fn await_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![await]) }
1134} 1142}
1135#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1143#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1136pub struct TryExpr { 1144pub struct TryExpr {
@@ -1149,7 +1157,7 @@ impl AstNode for TryExpr {
1149} 1157}
1150impl ast::AttrsOwner for TryExpr {} 1158impl ast::AttrsOwner for TryExpr {}
1151impl TryExpr { 1159impl TryExpr {
1152 pub fn try_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, TRY_KW) } 1160 pub fn try_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![try]) }
1153 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1161 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1154} 1162}
1155#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1163#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -1170,7 +1178,7 @@ impl AstNode for CastExpr {
1170impl ast::AttrsOwner for CastExpr {} 1178impl ast::AttrsOwner for CastExpr {}
1171impl CastExpr { 1179impl CastExpr {
1172 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1180 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1173 pub fn as_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, AS_KW) } 1181 pub fn as_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![as]) }
1174 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 1182 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
1175} 1183}
1176#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1184#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -1191,8 +1199,8 @@ impl AstNode for RefExpr {
1191impl ast::AttrsOwner for RefExpr {} 1199impl ast::AttrsOwner for RefExpr {}
1192impl RefExpr { 1200impl RefExpr {
1193 pub fn amp_token(&self) -> Option<Amp> { support::token(&self.syntax) } 1201 pub fn amp_token(&self) -> Option<Amp> { support::token(&self.syntax) }
1194 pub fn raw_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, RAW_KW) } 1202 pub fn raw_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![raw]) }
1195 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, MUT_KW) } 1203 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![mut]) }
1196 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1204 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1197} 1205}
1198#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1206#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -1232,7 +1240,7 @@ impl AstNode for BoxExpr {
1232} 1240}
1233impl ast::AttrsOwner for BoxExpr {} 1241impl ast::AttrsOwner for BoxExpr {}
1234impl BoxExpr { 1242impl BoxExpr {
1235 pub fn box_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, BOX_KW) } 1243 pub fn box_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![box]) }
1236 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1244 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1237} 1245}
1238#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1246#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -1308,7 +1316,7 @@ impl AstNode for MatchExpr {
1308} 1316}
1309impl ast::AttrsOwner for MatchExpr {} 1317impl ast::AttrsOwner for MatchExpr {}
1310impl MatchExpr { 1318impl MatchExpr {
1311 pub fn match_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, MATCH_KW) } 1319 pub fn match_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![match]) }
1312 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1320 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1313 pub fn match_arm_list(&self) -> Option<MatchArmList> { support::child(&self.syntax) } 1321 pub fn match_arm_list(&self) -> Option<MatchArmList> { support::child(&self.syntax) }
1314} 1322}
@@ -1371,7 +1379,7 @@ impl AstNode for MatchGuard {
1371 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1379 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1372} 1380}
1373impl MatchGuard { 1381impl MatchGuard {
1374 pub fn if_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, IF_KW) } 1382 pub fn if_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![if]) }
1375 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1383 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1376} 1384}
1377#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1385#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -1491,7 +1499,7 @@ impl AstNode for RefPat {
1491} 1499}
1492impl RefPat { 1500impl RefPat {
1493 pub fn amp_token(&self) -> Option<Amp> { support::token(&self.syntax) } 1501 pub fn amp_token(&self) -> Option<Amp> { support::token(&self.syntax) }
1494 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, MUT_KW) } 1502 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![mut]) }
1495 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 1503 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1496} 1504}
1497#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1505#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -1510,7 +1518,7 @@ impl AstNode for BoxPat {
1510 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1518 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1511} 1519}
1512impl BoxPat { 1520impl BoxPat {
1513 pub fn box_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, BOX_KW) } 1521 pub fn box_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![box]) }
1514 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 1522 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1515} 1523}
1516#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1524#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -1531,8 +1539,8 @@ impl AstNode for BindPat {
1531impl ast::AttrsOwner for BindPat {} 1539impl ast::AttrsOwner for BindPat {}
1532impl ast::NameOwner for BindPat {} 1540impl ast::NameOwner for BindPat {}
1533impl BindPat { 1541impl BindPat {
1534 pub fn ref_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, REF_KW) } 1542 pub fn ref_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![ref]) }
1535 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, MUT_KW) } 1543 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![mut]) }
1536 pub fn at_token(&self) -> Option<At> { support::token(&self.syntax) } 1544 pub fn at_token(&self) -> Option<At> { support::token(&self.syntax) }
1537 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 1545 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1538} 1546}
@@ -1788,10 +1796,10 @@ impl AstNode for Visibility {
1788 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1796 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1789} 1797}
1790impl Visibility { 1798impl Visibility {
1791 pub fn pub_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, PUB_KW) } 1799 pub fn pub_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![pub]) }
1792 pub fn super_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, SUPER_KW) } 1800 pub fn super_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![super]) }
1793 pub fn self_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, SELF_KW) } 1801 pub fn self_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![self]) }
1794 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, CRATE_KW) } 1802 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![crate]) }
1795} 1803}
1796#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1804#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1797pub struct Name { 1805pub struct Name {
@@ -1996,7 +2004,7 @@ impl AstNode for TypeBound {
1996} 2004}
1997impl TypeBound { 2005impl TypeBound {
1998 pub fn lifetime_token(&self) -> Option<Lifetime> { support::token(&self.syntax) } 2006 pub fn lifetime_token(&self) -> Option<Lifetime> { support::token(&self.syntax) }
1999 pub fn const_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, CONST_KW) } 2007 pub fn const_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![const]) }
2000 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 2008 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
2001} 2009}
2002#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2010#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -2053,7 +2061,7 @@ impl AstNode for WhereClause {
2053 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2061 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2054} 2062}
2055impl WhereClause { 2063impl WhereClause {
2056 pub fn where_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, WHERE_KW) } 2064 pub fn where_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![where]) }
2057 pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) } 2065 pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) }
2058} 2066}
2059#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2067#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -2112,7 +2120,7 @@ impl AstNode for LetStmt {
2112impl ast::AttrsOwner for LetStmt {} 2120impl ast::AttrsOwner for LetStmt {}
2113impl ast::TypeAscriptionOwner for LetStmt {} 2121impl ast::TypeAscriptionOwner for LetStmt {}
2114impl LetStmt { 2122impl LetStmt {
2115 pub fn let_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, LET_KW) } 2123 pub fn let_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![let]) }
2116 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 2124 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
2117 pub fn eq_token(&self) -> Option<Eq> { support::token(&self.syntax) } 2125 pub fn eq_token(&self) -> Option<Eq> { support::token(&self.syntax) }
2118 pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) } 2126 pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) }
@@ -2134,7 +2142,7 @@ impl AstNode for Condition {
2134 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2142 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2135} 2143}
2136impl Condition { 2144impl Condition {
2137 pub fn let_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, LET_KW) } 2145 pub fn let_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![let]) }
2138 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 2146 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
2139 pub fn eq_token(&self) -> Option<Eq> { support::token(&self.syntax) } 2147 pub fn eq_token(&self) -> Option<Eq> { support::token(&self.syntax) }
2140 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 2148 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
@@ -2203,7 +2211,7 @@ impl ast::AttrsOwner for SelfParam {}
2203impl SelfParam { 2211impl SelfParam {
2204 pub fn amp_token(&self) -> Option<Amp> { support::token(&self.syntax) } 2212 pub fn amp_token(&self) -> Option<Amp> { support::token(&self.syntax) }
2205 pub fn lifetime_token(&self) -> Option<Lifetime> { support::token(&self.syntax) } 2213 pub fn lifetime_token(&self) -> Option<Lifetime> { support::token(&self.syntax) }
2206 pub fn self_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, SELF_KW) } 2214 pub fn self_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![self]) }
2207} 2215}
2208#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2216#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2209pub struct Param { 2217pub struct Param {
@@ -2244,7 +2252,7 @@ impl AstNode for UseItem {
2244impl ast::AttrsOwner for UseItem {} 2252impl ast::AttrsOwner for UseItem {}
2245impl ast::VisibilityOwner for UseItem {} 2253impl ast::VisibilityOwner for UseItem {}
2246impl UseItem { 2254impl UseItem {
2247 pub fn use_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, USE_KW) } 2255 pub fn use_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![use]) }
2248 pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) } 2256 pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) }
2249} 2257}
2250#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2258#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -2285,7 +2293,7 @@ impl AstNode for Alias {
2285} 2293}
2286impl ast::NameOwner for Alias {} 2294impl ast::NameOwner for Alias {}
2287impl Alias { 2295impl Alias {
2288 pub fn as_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, AS_KW) } 2296 pub fn as_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![as]) }
2289} 2297}
2290#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2298#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2291pub struct UseTreeList { 2299pub struct UseTreeList {
@@ -2325,8 +2333,8 @@ impl AstNode for ExternCrateItem {
2325impl ast::AttrsOwner for ExternCrateItem {} 2333impl ast::AttrsOwner for ExternCrateItem {}
2326impl ast::VisibilityOwner for ExternCrateItem {} 2334impl ast::VisibilityOwner for ExternCrateItem {}
2327impl ExternCrateItem { 2335impl ExternCrateItem {
2328 pub fn extern_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, EXTERN_KW) } 2336 pub fn extern_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![extern]) }
2329 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, CRATE_KW) } 2337 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token2(&self.syntax, T![crate]) }
2330 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } 2338 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
2331 pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } 2339 pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) }
2332} 2340}
diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs
index 15bd8a2e4..3da280551 100644
--- a/xtask/src/ast_src.rs
+++ b/xtask/src/ast_src.rs
@@ -233,7 +233,12 @@ pub(crate) struct AstSrc<'a> {
233pub(crate) struct AstNodeSrc<'a> { 233pub(crate) struct AstNodeSrc<'a> {
234 pub(crate) name: &'a str, 234 pub(crate) name: &'a str,
235 pub(crate) traits: &'a [&'a str], 235 pub(crate) traits: &'a [&'a str],
236 pub(crate) fields: &'a [(&'a str, FieldSrc<'a>)], 236 pub(crate) fields: &'a [Field<'a>],
237}
238
239pub(crate) enum Field<'a> {
240 Token(&'a str),
241 Node { name: &'a str, src: FieldSrc<'a> },
237} 242}
238 243
239pub(crate) enum FieldSrc<'a> { 244pub(crate) enum FieldSrc<'a> {
@@ -251,31 +256,34 @@ pub(crate) struct AstEnumSrc<'a> {
251macro_rules! ast_nodes { 256macro_rules! ast_nodes {
252 ($( 257 ($(
253 struct $name:ident$(: $($trait:ident),*)? { 258 struct $name:ident$(: $($trait:ident),*)? {
254 $($field_name:ident $(: $ty:tt)?),*$(,)? 259 $($field_name:ident $(![$token:tt])? $(: $ty:tt)?),*$(,)?
255 } 260 }
256 )*) => { 261 )*) => {
257 [$( 262 [$(
258 AstNodeSrc { 263 AstNodeSrc {
259 name: stringify!($name), 264 name: stringify!($name),
260 traits: &[$($(stringify!($trait)),*)?], 265 traits: &[$($(stringify!($trait)),*)?],
261 fields: &[$( 266 fields: &[
262 (stringify!($field_name), field_ty!($field_name $($ty)?)) 267 $(field!($(T![$token])? $field_name $($ty)?)),*
263 ),*], 268 ],
264 269
265 } 270 }
266 ),*] 271 ),*]
267 }; 272 };
268} 273}
269 274
270macro_rules! field_ty { 275macro_rules! field {
276 (T![$token:tt] T) => {
277 Field::Token(stringify!($token))
278 };
271 ($field_name:ident) => { 279 ($field_name:ident) => {
272 FieldSrc::Shorthand 280 Field::Node { name: stringify!($field_name), src: FieldSrc::Shorthand }
273 }; 281 };
274 ($field_name:ident [$ty:ident]) => { 282 ($field_name:ident [$ty:ident]) => {
275 FieldSrc::Many(stringify!($ty)) 283 Field::Node { name: stringify!($field_name), src: FieldSrc::Many(stringify!($ty)) }
276 }; 284 };
277 ($field_name:ident $ty:ident) => { 285 ($field_name:ident $ty:ident) => {
278 FieldSrc::Optional(stringify!($ty)) 286 Field::Node { name: stringify!($field_name), src: FieldSrc::Optional(stringify!($ty)) }
279 }; 287 };
280} 288}
281 289
@@ -290,7 +298,6 @@ macro_rules! ast_enums {
290 name: stringify!($name), 298 name: stringify!($name),
291 traits: &[$($(stringify!($trait)),*)?], 299 traits: &[$($(stringify!($trait)),*)?],
292 variants: &[$(stringify!($variant)),*], 300 variants: &[$(stringify!($variant)),*],
293
294 } 301 }
295 ),*] 302 ),*]
296 }; 303 };
@@ -304,11 +311,11 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
304 311
305 struct FnDef: VisibilityOwner, NameOwner, TypeParamsOwner, DocCommentsOwner, AttrsOwner { 312 struct FnDef: VisibilityOwner, NameOwner, TypeParamsOwner, DocCommentsOwner, AttrsOwner {
306 Abi, 313 Abi,
307 ConstKw, 314 T![const],
308 DefaultKw, 315 T![default],
309 AsyncKw, 316 T![async],
310 UnsafeKw, 317 T![unsafe],
311 FnKw, 318 T![fn],
312 ParamList, 319 ParamList,
313 RetType, 320 RetType,
314 body: BlockExpr, 321 body: BlockExpr,
@@ -318,13 +325,13 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
318 struct RetType { ThinArrow, TypeRef } 325 struct RetType { ThinArrow, TypeRef }
319 326
320 struct StructDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner { 327 struct StructDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner {
321 StructKw, 328 T![struct],
322 FieldDefList, 329 FieldDefList,
323 Semi 330 Semi
324 } 331 }
325 332
326 struct UnionDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner { 333 struct UnionDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner {
327 UnionKw, 334 T![union],
328 RecordFieldDefList, 335 RecordFieldDefList,
329 } 336 }
330 337
@@ -337,7 +344,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
337 } 344 }
338 345
339 struct EnumDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner { 346 struct EnumDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner {
340 EnumKw, 347 T![enum],
341 variant_list: EnumVariantList, 348 variant_list: EnumVariantList,
342 } 349 }
343 struct EnumVariantList { 350 struct EnumVariantList {
@@ -352,14 +359,14 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
352 } 359 }
353 360
354 struct TraitDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeParamsOwner, TypeBoundsOwner { 361 struct TraitDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeParamsOwner, TypeBoundsOwner {
355 UnsafeKw, 362 T![unsafe],
356 AutoKw, 363 T![auto],
357 TraitKw, 364 T![trait],
358 ItemList, 365 ItemList,
359 } 366 }
360 367
361 struct Module: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner { 368 struct Module: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner {
362 ModKw, 369 T![mod],
363 ItemList, 370 ItemList,
364 Semi 371 Semi
365 } 372 }
@@ -371,36 +378,36 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
371 } 378 }
372 379
373 struct ConstDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { 380 struct ConstDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner {
374 DefaultKw, 381 T![default],
375 ConstKw, 382 T![const],
376 Eq, 383 Eq,
377 body: Expr, 384 body: Expr,
378 Semi 385 Semi
379 } 386 }
380 387
381 struct StaticDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { 388 struct StaticDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner {
382 StaticKw, 389 T![static],
383 MutKw, 390 T![mut],
384 Eq, 391 Eq,
385 body: Expr, 392 body: Expr,
386 Semi 393 Semi
387 } 394 }
388 395
389 struct TypeAliasDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeBoundsOwner { 396 struct TypeAliasDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeBoundsOwner {
390 DefaultKw, 397 T![default],
391 TypeKw, 398 T![type],
392 Eq, 399 Eq,
393 TypeRef, 400 TypeRef,
394 Semi 401 Semi
395 } 402 }
396 403
397 struct ImplDef: TypeParamsOwner, AttrsOwner { 404 struct ImplDef: TypeParamsOwner, AttrsOwner {
398 DefaultKw, 405 T![default],
399 ConstKw, 406 T![const],
400 UnsafeKw, 407 T![unsafe],
401 ImplKw, 408 T![impl],
402 Excl, 409 Excl,
403 ForKw, 410 T![for],
404 ItemList, 411 ItemList,
405 } 412 }
406 413
@@ -408,42 +415,42 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
408 struct TupleType { LParen, fields: [TypeRef], RParen } 415 struct TupleType { LParen, fields: [TypeRef], RParen }
409 struct NeverType { Excl } 416 struct NeverType { Excl }
410 struct PathType { Path } 417 struct PathType { Path }
411 struct PointerType { Star, ConstKw, MutKw, TypeRef } 418 struct PointerType { Star, T![const], T![mut], TypeRef }
412 struct ArrayType { LBrack, TypeRef, Semi, Expr, RBrack } 419 struct ArrayType { LBrack, TypeRef, Semi, Expr, RBrack }
413 struct SliceType { LBrack, TypeRef, RBrack } 420 struct SliceType { LBrack, TypeRef, RBrack }
414 struct ReferenceType { Amp, Lifetime, MutKw, TypeRef } 421 struct ReferenceType { Amp, Lifetime, T![mut], TypeRef }
415 struct PlaceholderType { Underscore } 422 struct PlaceholderType { Underscore }
416 struct FnPointerType { Abi, UnsafeKw, FnKw, ParamList, RetType } 423 struct FnPointerType { Abi, T![unsafe], T![fn], ParamList, RetType }
417 struct ForType { ForKw, TypeParamList, TypeRef } 424 struct ForType { T![for], TypeParamList, TypeRef }
418 struct ImplTraitType: TypeBoundsOwner { ImplKw } 425 struct ImplTraitType: TypeBoundsOwner { T![impl] }
419 struct DynTraitType: TypeBoundsOwner { DynKw } 426 struct DynTraitType: TypeBoundsOwner { T![dyn] }
420 427
421 struct TupleExpr: AttrsOwner { LParen, exprs: [Expr], RParen } 428 struct TupleExpr: AttrsOwner { LParen, exprs: [Expr], RParen }
422 struct ArrayExpr: AttrsOwner { LBrack, exprs: [Expr], Semi, RBrack } 429 struct ArrayExpr: AttrsOwner { LBrack, exprs: [Expr], Semi, RBrack }
423 struct ParenExpr: AttrsOwner { LParen, Expr, RParen } 430 struct ParenExpr: AttrsOwner { LParen, Expr, RParen }
424 struct PathExpr { Path } 431 struct PathExpr { Path }
425 struct LambdaExpr: AttrsOwner { 432 struct LambdaExpr: AttrsOwner {
426 StaticKw, 433 T![static],
427 AsyncKw, 434 T![async],
428 MoveKw, 435 T![move],
429 ParamList, 436 ParamList,
430 RetType, 437 RetType,
431 body: Expr, 438 body: Expr,
432 } 439 }
433 struct IfExpr: AttrsOwner { IfKw, Condition } 440 struct IfExpr: AttrsOwner { T![if], Condition }
434 struct LoopExpr: AttrsOwner, LoopBodyOwner { LoopKw } 441 struct LoopExpr: AttrsOwner, LoopBodyOwner { T![loop] }
435 struct TryBlockExpr: AttrsOwner { TryKw, body: BlockExpr } 442 struct TryBlockExpr: AttrsOwner { T![try], body: BlockExpr }
436 struct ForExpr: AttrsOwner, LoopBodyOwner { 443 struct ForExpr: AttrsOwner, LoopBodyOwner {
437 ForKw, 444 T![for],
438 Pat, 445 Pat,
439 InKw, 446 T![in],
440 iterable: Expr, 447 iterable: Expr,
441 } 448 }
442 struct WhileExpr: AttrsOwner, LoopBodyOwner { WhileKw, Condition } 449 struct WhileExpr: AttrsOwner, LoopBodyOwner { T![while], Condition }
443 struct ContinueExpr: AttrsOwner { ContinueKw, Lifetime } 450 struct ContinueExpr: AttrsOwner { T![continue], Lifetime }
444 struct BreakExpr: AttrsOwner { BreakKw, Lifetime, Expr } 451 struct BreakExpr: AttrsOwner { T![break], Lifetime, Expr }
445 struct Label { Lifetime } 452 struct Label { Lifetime }
446 struct BlockExpr: AttrsOwner { Label, UnsafeKw, Block } 453 struct BlockExpr: AttrsOwner { Label, T![unsafe], Block }
447 struct ReturnExpr: AttrsOwner { Expr } 454 struct ReturnExpr: AttrsOwner { Expr }
448 struct CallExpr: ArgListOwner { Expr } 455 struct CallExpr: ArgListOwner { Expr }
449 struct MethodCallExpr: AttrsOwner, ArgListOwner { 456 struct MethodCallExpr: AttrsOwner, ArgListOwner {
@@ -451,17 +458,17 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
451 } 458 }
452 struct IndexExpr: AttrsOwner { LBrack, RBrack } 459 struct IndexExpr: AttrsOwner { LBrack, RBrack }
453 struct FieldExpr: AttrsOwner { Expr, Dot, NameRef } 460 struct FieldExpr: AttrsOwner { Expr, Dot, NameRef }
454 struct AwaitExpr: AttrsOwner { Expr, Dot, AwaitKw } 461 struct AwaitExpr: AttrsOwner { Expr, Dot, T![await] }
455 struct TryExpr: AttrsOwner { TryKw, Expr } 462 struct TryExpr: AttrsOwner { T![try], Expr }
456 struct CastExpr: AttrsOwner { Expr, AsKw, TypeRef } 463 struct CastExpr: AttrsOwner { Expr, T![as], TypeRef }
457 struct RefExpr: AttrsOwner { Amp, RawKw, MutKw, Expr } 464 struct RefExpr: AttrsOwner { Amp, T![raw], T![mut], Expr }
458 struct PrefixExpr: AttrsOwner { PrefixOp, Expr } 465 struct PrefixExpr: AttrsOwner { PrefixOp, Expr }
459 struct BoxExpr: AttrsOwner { BoxKw, Expr } 466 struct BoxExpr: AttrsOwner { T![box], Expr }
460 struct RangeExpr: AttrsOwner { RangeOp } 467 struct RangeExpr: AttrsOwner { RangeOp }
461 struct BinExpr: AttrsOwner { BinOp } 468 struct BinExpr: AttrsOwner { BinOp }
462 struct Literal { LiteralToken } 469 struct Literal { LiteralToken }
463 470
464 struct MatchExpr: AttrsOwner { MatchKw, Expr, MatchArmList } 471 struct MatchExpr: AttrsOwner { T![match], Expr, MatchArmList }
465 struct MatchArmList: AttrsOwner { LCurly, arms: [MatchArm], RCurly } 472 struct MatchArmList: AttrsOwner { LCurly, arms: [MatchArm], RCurly }
466 struct MatchArm: AttrsOwner { 473 struct MatchArm: AttrsOwner {
467 pat: Pat, 474 pat: Pat,
@@ -469,7 +476,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
469 FatArrow, 476 FatArrow,
470 Expr, 477 Expr,
471 } 478 }
472 struct MatchGuard { IfKw, Expr } 479 struct MatchGuard { T![if], Expr }
473 480
474 struct RecordLit { Path, RecordFieldList} 481 struct RecordLit { Path, RecordFieldList}
475 struct RecordFieldList { 482 struct RecordFieldList {
@@ -483,9 +490,9 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
483 490
484 struct OrPat { pats: [Pat] } 491 struct OrPat { pats: [Pat] }
485 struct ParenPat { LParen, Pat, RParen } 492 struct ParenPat { LParen, Pat, RParen }
486 struct RefPat { Amp, MutKw, Pat } 493 struct RefPat { Amp, T![mut], Pat }
487 struct BoxPat { BoxKw, Pat } 494 struct BoxPat { T![box], Pat }
488 struct BindPat: AttrsOwner, NameOwner { RefKw, MutKw, At, Pat } 495 struct BindPat: AttrsOwner, NameOwner { T![ref], T![mut], At, Pat }
489 struct PlaceholderPat { Underscore } 496 struct PlaceholderPat { Underscore }
490 struct DotDotPat { Dotdot } 497 struct DotDotPat { Dotdot }
491 struct PathPat { Path } 498 struct PathPat { Path }
@@ -508,7 +515,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
508 struct TupleStructPat { Path, LParen, args: [Pat], RParen } 515 struct TupleStructPat { Path, LParen, args: [Pat], RParen }
509 struct TuplePat { LParen, args: [Pat], RParen } 516 struct TuplePat { LParen, args: [Pat], RParen }
510 517
511 struct Visibility { PubKw, SuperKw, SelfKw, CrateKw } 518 struct Visibility { T![pub], T![super], T![self], T![crate] }
512 struct Name { Ident } 519 struct Name { Ident }
513 struct NameRef { NameRefToken } 520 struct NameRef { NameRefToken }
514 521
@@ -534,20 +541,20 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
534 default_val: Expr, 541 default_val: Expr,
535 } 542 }
536 struct LifetimeParam: AttrsOwner { Lifetime} 543 struct LifetimeParam: AttrsOwner { Lifetime}
537 struct TypeBound { Lifetime, /* Question, */ ConstKw, /* Question, */ TypeRef} 544 struct TypeBound { Lifetime, /* Question, */ T![const], /* Question, */ TypeRef}
538 struct TypeBoundList { bounds: [TypeBound] } 545 struct TypeBoundList { bounds: [TypeBound] }
539 struct WherePred: TypeBoundsOwner { Lifetime, TypeRef } 546 struct WherePred: TypeBoundsOwner { Lifetime, TypeRef }
540 struct WhereClause { WhereKw, predicates: [WherePred] } 547 struct WhereClause { T![where], predicates: [WherePred] }
541 struct Abi { String } 548 struct Abi { String }
542 struct ExprStmt: AttrsOwner { Expr, Semi } 549 struct ExprStmt: AttrsOwner { Expr, Semi }
543 struct LetStmt: AttrsOwner, TypeAscriptionOwner { 550 struct LetStmt: AttrsOwner, TypeAscriptionOwner {
544 LetKw, 551 T![let],
545 Pat, 552 Pat,
546 Eq, 553 Eq,
547 initializer: Expr, 554 initializer: Expr,
548 Semi, 555 Semi,
549 } 556 }
550 struct Condition { LetKw, Pat, Eq, Expr } 557 struct Condition { T![let], Pat, Eq, Expr }
551 struct Block: AttrsOwner, ModuleItemOwner { 558 struct Block: AttrsOwner, ModuleItemOwner {
552 LCurly, 559 LCurly,
553 statements: [Stmt], 560 statements: [Stmt],
@@ -560,22 +567,22 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
560 params: [Param], 567 params: [Param],
561 RParen 568 RParen
562 } 569 }
563 struct SelfParam: TypeAscriptionOwner, AttrsOwner { Amp, Lifetime, SelfKw } 570 struct SelfParam: TypeAscriptionOwner, AttrsOwner { Amp, Lifetime, T![self] }
564 struct Param: TypeAscriptionOwner, AttrsOwner { 571 struct Param: TypeAscriptionOwner, AttrsOwner {
565 Pat, 572 Pat,
566 Dotdotdot 573 Dotdotdot
567 } 574 }
568 struct UseItem: AttrsOwner, VisibilityOwner { 575 struct UseItem: AttrsOwner, VisibilityOwner {
569 UseKw, 576 T![use],
570 UseTree, 577 UseTree,
571 } 578 }
572 struct UseTree { 579 struct UseTree {
573 Path, Star, UseTreeList, Alias 580 Path, Star, UseTreeList, Alias
574 } 581 }
575 struct Alias: NameOwner { AsKw } 582 struct Alias: NameOwner { T![as] }
576 struct UseTreeList { LCurly, use_trees: [UseTree], RCurly } 583 struct UseTreeList { LCurly, use_trees: [UseTree], RCurly }
577 struct ExternCrateItem: AttrsOwner, VisibilityOwner { 584 struct ExternCrateItem: AttrsOwner, VisibilityOwner {
578 ExternKw, CrateKw, NameRef, Alias, 585 T![extern], T![crate], NameRef, Alias,
579 } 586 }
580 struct ArgList { 587 struct ArgList {
581 LParen, 588 LParen,
diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs
index cc98802f6..c4fb29bbf 100644
--- a/xtask/src/codegen/gen_syntax.rs
+++ b/xtask/src/codegen/gen_syntax.rs
@@ -12,7 +12,7 @@ use proc_macro2::{Punct, Spacing};
12use quote::{format_ident, quote}; 12use quote::{format_ident, quote};
13 13
14use crate::{ 14use crate::{
15 ast_src::{AstSrc, FieldSrc, KindsSrc, AST_SRC, KINDS_SRC}, 15 ast_src::{AstSrc, Field, FieldSrc, KindsSrc, AST_SRC, KINDS_SRC},
16 codegen::{self, update, Mode}, 16 codegen::{self, update, Mode},
17 project_root, Result, 17 project_root, Result,
18}; 18};
@@ -189,46 +189,30 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
189 quote!(impl ast::#trait_name for #name {}) 189 quote!(impl ast::#trait_name for #name {})
190 }); 190 });
191 191
192 let methods = node.fields.iter().map(|(name, field)| { 192 let methods = node.fields.iter().map(|field| {
193 let is_kw = name.ends_with("Kw"); 193 let method_name = field.method_name();
194 let method_name = match field { 194 let ty = field.ty();
195 FieldSrc::Shorthand => {
196 let name = if is_kw { &name[..name.len() - 2] } else { &name };
197 format_ident!("{}", to_lower_snake_case(name))
198 }
199 _ => format_ident!("{}", name),
200 };
201 let ty = match field {
202 FieldSrc::Optional(ty) | FieldSrc::Many(ty) => ty,
203 FieldSrc::Shorthand => name,
204 };
205
206 let ty = format_ident!("{}", ty);
207 195
208 match field { 196 if field.is_many() {
209 FieldSrc::Many(_) => { 197 quote! {
198 pub fn #method_name(&self) -> AstChildren<#ty> {
199 support::children(&self.syntax)
200 }
201 }
202 } else {
203 if let Some(token_kind) = field.token_kind() {
210 quote! { 204 quote! {
211 pub fn #method_name(&self) -> AstChildren<#ty> { 205 pub fn #method_name(&self) -> Option<#ty> {
212 support::children(&self.syntax) 206 support::token2(&self.syntax, #token_kind)
213 } 207 }
214 } 208 }
215 } 209 } else {
216 FieldSrc::Optional(_) | FieldSrc::Shorthand => {
217 let is_token = token_kinds.contains(&ty.to_string()); 210 let is_token = token_kinds.contains(&ty.to_string());
218 if is_token { 211 if is_token {
219 let method_name = format_ident!("{}_token", method_name); 212 let method_name = format_ident!("{}_token", method_name);
220 if is_kw { 213 quote! {
221 let token_kind = format_ident!("{}", to_upper_snake_case(name)); 214 pub fn #method_name(&self) -> Option<#ty> {
222 quote! { 215 support::token(&self.syntax)
223 pub fn #method_name(&self) -> Option<SyntaxToken> {
224 support::token2(&self.syntax, #token_kind)
225 }
226 }
227 } else {
228 quote! {
229 pub fn #method_name(&self) -> Option<#ty> {
230 support::token(&self.syntax)
231 }
232 } 216 }
233 } 217 }
234 } else { 218 } else {
@@ -351,6 +335,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
351 use crate::{ 335 use crate::{
352 SyntaxNode, SyntaxToken, SyntaxKind::{self, *}, 336 SyntaxNode, SyntaxToken, SyntaxKind::{self, *},
353 ast::{self, AstNode, AstChildren, support}, 337 ast::{self, AstNode, AstChildren, support},
338 T,
354 }; 339 };
355 340
356 use super::tokens::*; 341 use super::tokens::*;
@@ -519,3 +504,40 @@ fn to_pascal_case(s: &str) -> String {
519 } 504 }
520 buf 505 buf
521} 506}
507
508impl Field<'_> {
509 fn is_many(&self) -> bool {
510 match self {
511 Field::Node { src: FieldSrc::Many(_), .. } => true,
512 _ => false,
513 }
514 }
515 fn token_kind(&self) -> Option<proc_macro2::TokenStream> {
516 let res = match self {
517 Field::Token(token) => {
518 let token = format_ident!("{}", token);
519 quote! { T![#token] }
520 }
521 _ => return None,
522 };
523 Some(res)
524 }
525 fn method_name(&self) -> proc_macro2::Ident {
526 match self {
527 Field::Token(name) => format_ident!("{}_token", name),
528 Field::Node { name, src } => match src {
529 FieldSrc::Shorthand => format_ident!("{}", to_lower_snake_case(name)),
530 _ => format_ident!("{}", name),
531 },
532 }
533 }
534 fn ty(&self) -> proc_macro2::Ident {
535 match self {
536 Field::Token(_) => format_ident!("SyntaxToken"),
537 Field::Node { name, src } => match src {
538 FieldSrc::Optional(ty) | FieldSrc::Many(ty) => format_ident!("{}", ty),
539 FieldSrc::Shorthand => format_ident!("{}", name),
540 },
541 }
542 }
543}