diff options
Diffstat (limited to 'xtask/src')
-rw-r--r-- | xtask/src/ast_src.rs | 48 | ||||
-rw-r--r-- | xtask/src/codegen/gen_syntax.rs | 84 | ||||
-rw-r--r-- | xtask/src/codegen/rust.ungram | 274 |
3 files changed, 202 insertions, 204 deletions
diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs index 3a58217c4..114898e38 100644 --- a/xtask/src/ast_src.rs +++ b/xtask/src/ast_src.rs | |||
@@ -93,19 +93,19 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc { | |||
93 | ], | 93 | ], |
94 | nodes: &[ | 94 | nodes: &[ |
95 | "SOURCE_FILE", | 95 | "SOURCE_FILE", |
96 | "STRUCT_DEF", | 96 | "STRUCT", |
97 | "UNION_DEF", | 97 | "UNION", |
98 | "ENUM_DEF", | 98 | "ENUM", |
99 | "FN_DEF", | 99 | "FN", |
100 | "RET_TYPE", | 100 | "RET_TYPE", |
101 | "EXTERN_CRATE", | 101 | "EXTERN_CRATE", |
102 | "MODULE", | 102 | "MODULE", |
103 | "USE", | 103 | "USE", |
104 | "STATIC_DEF", | 104 | "STATIC", |
105 | "CONST_DEF", | 105 | "CONST", |
106 | "TRAIT_DEF", | 106 | "TRAIT", |
107 | "IMPL_DEF", | 107 | "IMPL", |
108 | "TYPE_ALIAS_DEF", | 108 | "TYPE_ALIAS", |
109 | "MACRO_CALL", | 109 | "MACRO_CALL", |
110 | "TOKEN_TREE", | 110 | "TOKEN_TREE", |
111 | "MACRO_DEF", | 111 | "MACRO_DEF", |
@@ -159,9 +159,9 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc { | |||
159 | "MATCH_ARM_LIST", | 159 | "MATCH_ARM_LIST", |
160 | "MATCH_ARM", | 160 | "MATCH_ARM", |
161 | "MATCH_GUARD", | 161 | "MATCH_GUARD", |
162 | "RECORD_LIT", | 162 | "RECORD_EXPR", |
163 | "RECORD_FIELD_LIST", | 163 | "RECORD_EXPR_FIELD_LIST", |
164 | "RECORD_FIELD", | 164 | "RECORD_EXPR_FIELD", |
165 | "EFFECT_EXPR", | 165 | "EFFECT_EXPR", |
166 | "BOX_EXPR", | 166 | "BOX_EXPR", |
167 | // postfix | 167 | // postfix |
@@ -179,12 +179,12 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc { | |||
179 | "BIN_EXPR", | 179 | "BIN_EXPR", |
180 | "EXTERN_BLOCK", | 180 | "EXTERN_BLOCK", |
181 | "EXTERN_ITEM_LIST", | 181 | "EXTERN_ITEM_LIST", |
182 | "ENUM_VARIANT", | 182 | "VARIANT", |
183 | "RECORD_FIELD_DEF_LIST", | 183 | "RECORD_FIELD_LIST", |
184 | "RECORD_FIELD_DEF", | 184 | "RECORD_FIELD", |
185 | "TUPLE_FIELD_DEF_LIST", | 185 | "TUPLE_FIELD_LIST", |
186 | "TUPLE_FIELD_DEF", | 186 | "TUPLE_FIELD", |
187 | "ENUM_VARIANT_LIST", | 187 | "VARIANT_LIST", |
188 | "ITEM_LIST", | 188 | "ITEM_LIST", |
189 | "ASSOC_ITEM_LIST", | 189 | "ASSOC_ITEM_LIST", |
190 | "ATTR", | 190 | "ATTR", |
@@ -203,7 +203,8 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc { | |||
203 | "NAME_REF", | 203 | "NAME_REF", |
204 | "LET_STMT", | 204 | "LET_STMT", |
205 | "EXPR_STMT", | 205 | "EXPR_STMT", |
206 | "TYPE_PARAM_LIST", | 206 | "GENERIC_PARAM_LIST", |
207 | "GENERIC_PARAM", | ||
207 | "LIFETIME_PARAM", | 208 | "LIFETIME_PARAM", |
208 | "TYPE_PARAM", | 209 | "TYPE_PARAM", |
209 | "CONST_PARAM", | 210 | "CONST_PARAM", |
@@ -242,14 +243,13 @@ pub(crate) struct AstNodeSrc { | |||
242 | #[derive(Debug, Eq, PartialEq)] | 243 | #[derive(Debug, Eq, PartialEq)] |
243 | pub(crate) enum Field { | 244 | pub(crate) enum Field { |
244 | Token(String), | 245 | Token(String), |
245 | Node { name: String, src: FieldSrc }, | 246 | Node { name: String, ty: String, cardinality: Cardinality }, |
246 | } | 247 | } |
247 | 248 | ||
248 | #[derive(Debug, Eq, PartialEq)] | 249 | #[derive(Debug, Eq, PartialEq)] |
249 | pub(crate) enum FieldSrc { | 250 | pub(crate) enum Cardinality { |
250 | Shorthand, | 251 | Optional, |
251 | Optional(String), | 252 | Many, |
252 | Many(String), | ||
253 | } | 253 | } |
254 | 254 | ||
255 | #[derive(Debug)] | 255 | #[derive(Debug)] |
diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index c77fc8a8d..45b788bdb 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs | |||
@@ -13,7 +13,7 @@ use quote::{format_ident, quote}; | |||
13 | use ungrammar::{Grammar, Rule}; | 13 | use ungrammar::{Grammar, Rule}; |
14 | 14 | ||
15 | use crate::{ | 15 | use crate::{ |
16 | ast_src::{AstEnumSrc, AstNodeSrc, AstSrc, Field, FieldSrc, KindsSrc, KINDS_SRC}, | 16 | ast_src::{AstEnumSrc, AstNodeSrc, AstSrc, Cardinality, Field, KindsSrc, KINDS_SRC}, |
17 | codegen::{self, update, Mode}, | 17 | codegen::{self, update, Mode}, |
18 | project_root, Result, | 18 | project_root, Result, |
19 | }; | 19 | }; |
@@ -307,7 +307,7 @@ fn generate_syntax_kinds(grammar: KindsSrc<'_>) -> Result<String> { | |||
307 | 307 | ||
308 | let ast = quote! { | 308 | let ast = quote! { |
309 | #![allow(bad_style, missing_docs, unreachable_pub)] | 309 | #![allow(bad_style, missing_docs, unreachable_pub)] |
310 | /// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`. | 310 | /// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT`. |
311 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] | 311 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] |
312 | #[repr(u16)] | 312 | #[repr(u16)] |
313 | pub enum SyntaxKind { | 313 | pub enum SyntaxKind { |
@@ -431,7 +431,7 @@ fn pluralize(s: &str) -> String { | |||
431 | 431 | ||
432 | impl Field { | 432 | impl Field { |
433 | fn is_many(&self) -> bool { | 433 | fn is_many(&self) -> bool { |
434 | matches!(self, Field::Node { src: FieldSrc::Many(_), .. }) | 434 | matches!(self, Field::Node { cardinality: Cardinality::Many, .. }) |
435 | } | 435 | } |
436 | fn token_kind(&self) -> Option<proc_macro2::TokenStream> { | 436 | fn token_kind(&self) -> Option<proc_macro2::TokenStream> { |
437 | match self { | 437 | match self { |
@@ -471,23 +471,18 @@ impl Field { | |||
471 | "::" => "coloncolon", | 471 | "::" => "coloncolon", |
472 | "#" => "pound", | 472 | "#" => "pound", |
473 | "?" => "question_mark", | 473 | "?" => "question_mark", |
474 | "," => "comma", | ||
474 | _ => name, | 475 | _ => name, |
475 | }; | 476 | }; |
476 | format_ident!("{}_token", name) | 477 | format_ident!("{}_token", name) |
477 | } | 478 | } |
478 | Field::Node { name, src } => match src { | 479 | Field::Node { name, .. } => format_ident!("{}", name), |
479 | FieldSrc::Shorthand => format_ident!("{}", to_lower_snake_case(name)), | ||
480 | _ => format_ident!("{}", name), | ||
481 | }, | ||
482 | } | 480 | } |
483 | } | 481 | } |
484 | fn ty(&self) -> proc_macro2::Ident { | 482 | fn ty(&self) -> proc_macro2::Ident { |
485 | match self { | 483 | match self { |
486 | Field::Token(_) => format_ident!("SyntaxToken"), | 484 | Field::Token(_) => format_ident!("SyntaxToken"), |
487 | Field::Node { name, src } => match src { | 485 | Field::Node { ty, .. } => format_ident!("{}", ty), |
488 | FieldSrc::Optional(ty) | FieldSrc::Many(ty) => format_ident!("{}", ty), | ||
489 | FieldSrc::Shorthand => format_ident!("{}", name), | ||
490 | }, | ||
491 | } | 486 | } |
492 | } | 487 | } |
493 | } | 488 | } |
@@ -514,7 +509,7 @@ fn lower(grammar: &Grammar) -> AstSrc { | |||
514 | } | 509 | } |
515 | None => { | 510 | None => { |
516 | let mut fields = Vec::new(); | 511 | let mut fields = Vec::new(); |
517 | lower_rule(&mut fields, grammar, rule); | 512 | lower_rule(&mut fields, grammar, None, rule); |
518 | res.nodes.push(AstNodeSrc { doc: Vec::new(), name, traits: Vec::new(), fields }); | 513 | res.nodes.push(AstNodeSrc { doc: Vec::new(), name, traits: Vec::new(), fields }); |
519 | } | 514 | } |
520 | } | 515 | } |
@@ -542,17 +537,20 @@ fn lower_enum(grammar: &Grammar, rule: &Rule) -> Option<Vec<String>> { | |||
542 | Some(variants) | 537 | Some(variants) |
543 | } | 538 | } |
544 | 539 | ||
545 | fn lower_rule(acc: &mut Vec<Field>, grammar: &Grammar, rule: &Rule) { | 540 | fn lower_rule(acc: &mut Vec<Field>, grammar: &Grammar, label: Option<&String>, rule: &Rule) { |
546 | if lower_comma_list(acc, grammar, rule) { | 541 | if lower_comma_list(acc, grammar, label, rule) { |
547 | return; | 542 | return; |
548 | } | 543 | } |
549 | 544 | ||
550 | match rule { | 545 | match rule { |
551 | Rule::Node(node) => { | 546 | Rule::Node(node) => { |
552 | let field = Field::Node { name: grammar[*node].name.clone(), src: FieldSrc::Shorthand }; | 547 | let ty = grammar[*node].name.clone(); |
548 | let name = label.cloned().unwrap_or_else(|| to_lower_snake_case(&ty)); | ||
549 | let field = Field::Node { name, ty, cardinality: Cardinality::Optional }; | ||
553 | acc.push(field); | 550 | acc.push(field); |
554 | } | 551 | } |
555 | Rule::Token(token) => { | 552 | Rule::Token(token) => { |
553 | assert!(label.is_none()); | ||
556 | let mut name = grammar[*token].name.clone(); | 554 | let mut name = grammar[*token].name.clone(); |
557 | if name != "int_number" && name != "string" { | 555 | if name != "int_number" && name != "string" { |
558 | if "[]{}()".contains(&name) { | 556 | if "[]{}()".contains(&name) { |
@@ -564,48 +562,35 @@ fn lower_rule(acc: &mut Vec<Field>, grammar: &Grammar, rule: &Rule) { | |||
564 | } | 562 | } |
565 | Rule::Rep(inner) => { | 563 | Rule::Rep(inner) => { |
566 | if let Rule::Node(node) = &**inner { | 564 | if let Rule::Node(node) = &**inner { |
567 | let name = grammar[*node].name.clone(); | 565 | let ty = grammar[*node].name.clone(); |
568 | let label = pluralize(&to_lower_snake_case(&name)); | 566 | let name = label.cloned().unwrap_or_else(|| pluralize(&to_lower_snake_case(&ty))); |
569 | let field = Field::Node { name: label.clone(), src: FieldSrc::Many(name) }; | 567 | let field = Field::Node { name, ty, cardinality: Cardinality::Many }; |
570 | acc.push(field); | 568 | acc.push(field); |
571 | return; | 569 | return; |
572 | } | 570 | } |
573 | todo!("{:?}", rule) | 571 | todo!("{:?}", rule) |
574 | } | 572 | } |
575 | Rule::Labeled { label, rule } => { | 573 | Rule::Labeled { label: l, rule } => { |
576 | let node = match &**rule { | 574 | assert!(label.is_none()); |
577 | Rule::Rep(inner) | Rule::Opt(inner) => match &**inner { | 575 | lower_rule(acc, grammar, Some(l), rule); |
578 | Rule::Node(node) => node, | ||
579 | _ => todo!("{:?}", rule), | ||
580 | }, | ||
581 | Rule::Node(node) => node, | ||
582 | _ => todo!("{:?}", rule), | ||
583 | }; | ||
584 | let field = Field::Node { | ||
585 | name: label.clone(), | ||
586 | src: match &**rule { | ||
587 | Rule::Rep(_) => FieldSrc::Many(grammar[*node].name.clone()), | ||
588 | _ => FieldSrc::Optional(grammar[*node].name.clone()), | ||
589 | }, | ||
590 | }; | ||
591 | acc.push(field); | ||
592 | } | 576 | } |
593 | Rule::Seq(rules) | Rule::Alt(rules) => { | 577 | Rule::Seq(rules) | Rule::Alt(rules) => { |
594 | for rule in rules { | 578 | for rule in rules { |
595 | lower_rule(acc, grammar, rule) | 579 | lower_rule(acc, grammar, label, rule) |
596 | } | 580 | } |
597 | } | 581 | } |
598 | Rule::Opt(rule) => lower_rule(acc, grammar, rule), | 582 | Rule::Opt(rule) => lower_rule(acc, grammar, label, rule), |
599 | } | 583 | } |
600 | } | 584 | } |
601 | 585 | ||
602 | // (T (',' T)* ','?)? | 586 | // (T (',' T)* ','?) |
603 | fn lower_comma_list(acc: &mut Vec<Field>, grammar: &Grammar, rule: &Rule) -> bool { | 587 | fn lower_comma_list( |
588 | acc: &mut Vec<Field>, | ||
589 | grammar: &Grammar, | ||
590 | label: Option<&String>, | ||
591 | rule: &Rule, | ||
592 | ) -> bool { | ||
604 | let rule = match rule { | 593 | let rule = match rule { |
605 | Rule::Opt(it) => it, | ||
606 | _ => return false, | ||
607 | }; | ||
608 | let rule = match &**rule { | ||
609 | Rule::Seq(it) => it, | 594 | Rule::Seq(it) => it, |
610 | _ => return false, | 595 | _ => return false, |
611 | }; | 596 | }; |
@@ -623,9 +608,9 @@ fn lower_comma_list(acc: &mut Vec<Field>, grammar: &Grammar, rule: &Rule) -> boo | |||
623 | [comma, Rule::Node(n)] if comma == &**trailing_comma && n == node => (), | 608 | [comma, Rule::Node(n)] if comma == &**trailing_comma && n == node => (), |
624 | _ => return false, | 609 | _ => return false, |
625 | } | 610 | } |
626 | let name = grammar[*node].name.clone(); | 611 | let ty = grammar[*node].name.clone(); |
627 | let label = pluralize(&to_lower_snake_case(&name)); | 612 | let name = label.cloned().unwrap_or_else(|| pluralize(&to_lower_snake_case(&ty))); |
628 | let field = Field::Node { name: label.clone(), src: FieldSrc::Many(name) }; | 613 | let field = Field::Node { name, ty, cardinality: Cardinality::Many }; |
629 | acc.push(field); | 614 | acc.push(field); |
630 | true | 615 | true |
631 | } | 616 | } |
@@ -659,7 +644,9 @@ fn extract_enums(ast: &mut AstSrc) { | |||
659 | } | 644 | } |
660 | if to_remove.len() == enm.variants.len() { | 645 | if to_remove.len() == enm.variants.len() { |
661 | node.remove_field(to_remove); | 646 | node.remove_field(to_remove); |
662 | node.fields.push(Field::Node { name: enm.name.clone(), src: FieldSrc::Shorthand }); | 647 | let ty = enm.name.clone(); |
648 | let name = to_lower_snake_case(&ty); | ||
649 | node.fields.push(Field::Node { name, ty, cardinality: Cardinality::Optional }); | ||
663 | } | 650 | } |
664 | } | 651 | } |
665 | } | 652 | } |
@@ -670,10 +657,9 @@ fn extract_struct_traits(ast: &mut AstSrc) { | |||
670 | ("AttrsOwner", &["attrs"]), | 657 | ("AttrsOwner", &["attrs"]), |
671 | ("NameOwner", &["name"]), | 658 | ("NameOwner", &["name"]), |
672 | ("VisibilityOwner", &["visibility"]), | 659 | ("VisibilityOwner", &["visibility"]), |
673 | ("TypeParamsOwner", &["type_param_list", "where_clause"]), | 660 | ("GenericParamsOwner", &["generic_param_list", "where_clause"]), |
674 | ("TypeBoundsOwner", &["type_bound_list", "colon_token"]), | 661 | ("TypeBoundsOwner", &["type_bound_list", "colon_token"]), |
675 | ("ModuleItemOwner", &["items"]), | 662 | ("ModuleItemOwner", &["items"]), |
676 | ("TypeAscriptionOwner", &["ascribed_type"]), | ||
677 | ("LoopBodyOwner", &["label", "loop_body"]), | 663 | ("LoopBodyOwner", &["label", "loop_body"]), |
678 | ("ArgListOwner", &["arg_list"]), | 664 | ("ArgListOwner", &["arg_list"]), |
679 | ]; | 665 | ]; |
diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram index 449b0242f..375df301f 100644 --- a/xtask/src/codegen/rust.ungram +++ b/xtask/src/codegen/rust.ungram | |||
@@ -4,19 +4,19 @@ SourceFile = | |||
4 | Item* | 4 | Item* |
5 | 5 | ||
6 | Item = | 6 | Item = |
7 | ConstDef | 7 | Const |
8 | | EnumDef | 8 | | Enum |
9 | | ExternBlock | 9 | | ExternBlock |
10 | | ExternCrate | 10 | | ExternCrate |
11 | | FnDef | 11 | | Fn |
12 | | ImplDef | 12 | | Impl |
13 | | MacroCall | 13 | | MacroCall |
14 | | Module | 14 | | Module |
15 | | StaticDef | 15 | | Static |
16 | | StructDef | 16 | | Struct |
17 | | TraitDef | 17 | | Trait |
18 | | TypeAliasDef | 18 | | TypeAlias |
19 | | UnionDef | 19 | | Union |
20 | | Use | 20 | | Use |
21 | 21 | ||
22 | Module = | 22 | Module = |
@@ -42,78 +42,149 @@ UseTree = | |||
42 | UseTreeList = | 42 | UseTreeList = |
43 | '{' (UseTree (',' UseTree)* ','?)? '}' | 43 | '{' (UseTree (',' UseTree)* ','?)? '}' |
44 | 44 | ||
45 | FnDef = | 45 | Fn = |
46 | Attr* Visibility? Abi? 'const' 'default' 'async' 'unsafe' 'fn' Name TypeParamList? | 46 | Attr* Visibility? |
47 | ParamList RetType? | 47 | 'default'? ('async' | 'const')? 'unsafe'? Abi? |
48 | 'fn' Name GenericParamList? ParamList RetType? | ||
48 | WhereClause? | 49 | WhereClause? |
49 | (body:BlockExpr | ';') | 50 | (body:BlockExpr | ';') |
50 | 51 | ||
52 | Abi = | ||
53 | 'extern' 'string'? | ||
54 | |||
55 | ParamList = | ||
56 | '('( | ||
57 | SelfParam | ||
58 | | (SelfParam ',')? (Param (',' Param)* ','?)? | ||
59 | )')' | ||
60 | |||
61 | SelfParam = | ||
62 | Attr* ( | ||
63 | ('&' 'lifetime'?)? 'mut'? 'self' | ||
64 | | 'mut'? 'self' ':' ty:TypeRef | ||
65 | ) | ||
66 | |||
67 | Param = | ||
68 | Attr* ( | ||
69 | Pat (':' ty:TypeRef) | ||
70 | | ty:TypeRef | ||
71 | | '...' | ||
72 | ) | ||
73 | |||
51 | RetType = | 74 | RetType = |
52 | '->' TypeRef | 75 | '->' ty:TypeRef |
76 | |||
77 | TypeAlias = | ||
78 | Attr* Visibility? 'default'? 'type' Name GenericParamList? (':' TypeBoundList?)? WhereClause? | ||
79 | '=' ty:TypeRef ';' | ||
53 | 80 | ||
54 | StructDef = | 81 | Struct = |
55 | Attr* Visibility? 'struct' Name TypeParamList? ( | 82 | Attr* Visibility? 'struct' Name GenericParamList? ( |
56 | WhereClause? (RecordFieldDefList | ';') | 83 | WhereClause? (RecordFieldList | ';') |
57 | | TupleFieldDefList WhereClause? ';' | 84 | | TupleFieldList WhereClause? ';' |
58 | ) | 85 | ) |
59 | 86 | ||
60 | UnionDef = | 87 | RecordFieldList = |
61 | Attr* Visibility? 'union' Name TypeParamList? WhereClause? | 88 | '{' fields:(RecordField (',' RecordField)* ','?)? '}' |
62 | RecordFieldDefList | 89 | |
90 | RecordField = | ||
91 | Attr* Visibility? Name ':' ty:TypeRef | ||
63 | 92 | ||
64 | RecordFieldDefList = | 93 | TupleFieldList = |
65 | '{' fields:RecordFieldDef* '}' | 94 | '(' fields:(TupleField (',' TupleField)* ','?)? ')' |
66 | 95 | ||
67 | RecordFieldDef = | 96 | TupleField = |
68 | Attr* Visibility? Name ':' ascribed_type:TypeRef | 97 | Attr* Visibility? ty:TypeRef |
69 | 98 | ||
70 | TupleFieldDefList = | 99 | FieldList = |
71 | '(' fields:TupleFieldDef* ')' | 100 | RecordFieldList |
101 | | TupleFieldList | ||
72 | 102 | ||
73 | TupleFieldDef = | 103 | Enum = |
74 | Attr* Visibility? Name TypeRef | 104 | Attr* Visibility? 'enum' Name GenericParamList? WhereClause? |
105 | VariantList | ||
75 | 106 | ||
76 | FieldDefList = | 107 | VariantList = |
77 | RecordFieldDefList | 108 | '{' (Variant (',' Variant)* ','?)? '}' |
78 | | TupleFieldDefList | ||
79 | 109 | ||
80 | EnumDef = | 110 | Variant = |
81 | Attr* Visibility? 'enum' Name TypeParamList? WhereClause? | 111 | Attr* Visibility? Name FieldList ('=' Expr)? |
82 | variant_list:EnumVariantList | ||
83 | 112 | ||
84 | EnumVariantList = | 113 | Union = |
85 | '{' variants:EnumVariant* '}' | 114 | Attr* Visibility? 'union' Name GenericParamList? WhereClause? |
115 | RecordFieldList | ||
116 | |||
117 | Const = | ||
118 | Attr* Visibility? 'default'? 'const' (Name | '_') ':' ty:TypeRef | ||
119 | '=' body:Expr ';' | ||
86 | 120 | ||
87 | EnumVariant = | 121 | Static = |
88 | Attr* Visibility? Name FieldDefList ('=' Expr)? | 122 | Attr* Visibility? 'static'? 'mut'? Name ':' ty:TypeRef |
123 | '=' body:Expr ';' | ||
89 | 124 | ||
90 | TraitDef = | 125 | Trait = |
91 | Attr* Visibility? 'unsafe'? 'auto'? 'trait' Name TypeParamList | 126 | Attr* Visibility? 'unsafe'? 'auto'? 'trait' Name GenericParamList |
92 | (':' TypeBoundList?)? WhereClause | 127 | (':' TypeBoundList?)? WhereClause |
93 | AssocItemList | 128 | AssocItemList |
94 | 129 | ||
95 | AssocItemList = | 130 | AssocItemList = |
96 | '{' AssocItem* '}' | 131 | '{' Attr* AssocItem* '}' |
97 | 132 | ||
98 | ConstDef = | 133 | AssocItem = |
99 | Attr* Visibility? 'default'? 'const' Name ':' ascribed_type:TypeRef | 134 | Fn |
100 | '=' body:Expr ';' | 135 | | TypeAlias |
136 | | Const | ||
137 | | MacroCall | ||
101 | 138 | ||
102 | StaticDef = | 139 | Impl = |
103 | Attr* Visibility? 'static'? 'mut'? 'static' Name ':' ascribed_type:TypeRef | 140 | Attr* Visibility? |
104 | '=' body:Expr ';' | 141 | 'default'? 'unsafe'? 'impl' 'const'? GenericParamList? ( |
142 | TypeRef | ||
143 | | '!'? TypeRef 'for' TypeRef | ||
144 | ) WhereClause? | ||
145 | AssocItemList | ||
105 | 146 | ||
106 | TypeAliasDef = | 147 | ExternBlock = |
107 | Attr* Visibility? 'default'? 'type' Name TypeParamList? WhereClause? (':' TypeBoundList?)? | 148 | Attr* Abi ExternItemList |
108 | '=' TypeRef ';' | ||
109 | 149 | ||
110 | ImplDef = | 150 | ExternItemList = |
111 | Attr* Visibility? 'const'? 'default'? 'unsafe'? 'impl' TypeParamList? '!'? 'for' | 151 | '{' Attr* ExternItem* '}' |
112 | WhereClause? | 152 | |
113 | AssocItemList | 153 | ExternItem = |
154 | Fn | Static | MacroCall | ||
155 | |||
156 | GenericParamList = | ||
157 | '<' (GenericParam (',' GenericParam)* ','?)? '>' | ||
158 | |||
159 | GenericParam = | ||
160 | LifetimeParam | ||
161 | | TypeParam | ||
162 | | ConstParam | ||
163 | |||
164 | TypeParam = | ||
165 | Attr* Name (':' TypeBoundList?)? | ||
166 | ('=' default_type:TypeRef)? | ||
167 | |||
168 | ConstParam = | ||
169 | Attr* 'const' Name ':' ty:TypeRef | ||
170 | ('=' default_val:Expr)? | ||
171 | |||
172 | LifetimeParam = | ||
173 | Attr* 'lifetime' | ||
174 | |||
175 | Visibility = | ||
176 | 'pub' ('(' | ||
177 | 'super' | ||
178 | | 'self' | ||
179 | | 'crate' | ||
180 | | 'in' Path | ||
181 | ')')? | ||
182 | |||
183 | Attr = | ||
184 | '#' '!'? '[' Path ('=' Literal | TokenTree)? ']' | ||
114 | 185 | ||
115 | ParenType = | 186 | ParenType = |
116 | '(' TypeRef ')' | 187 | '(' ty:TypeRef ')' |
117 | 188 | ||
118 | TupleType = | 189 | TupleType = |
119 | '(' fields:TypeRef* ')' | 190 | '(' fields:TypeRef* ')' |
@@ -125,16 +196,16 @@ PathType = | |||
125 | Path | 196 | Path |
126 | 197 | ||
127 | PointerType = | 198 | PointerType = |
128 | '*' ('const' | 'mut') TypeRef | 199 | '*' ('const' | 'mut') ty:TypeRef |
129 | 200 | ||
130 | ArrayType = | 201 | ArrayType = |
131 | '[' TypeRef ';' Expr ']' | 202 | '[' ty:TypeRef ';' Expr ']' |
132 | 203 | ||
133 | SliceType = | 204 | SliceType = |
134 | '[' TypeRef ']' | 205 | '[' ty:TypeRef ']' |
135 | 206 | ||
136 | ReferenceType = | 207 | ReferenceType = |
137 | '&' 'lifetime'? 'mut'? TypeRef | 208 | '&' 'lifetime'? 'mut'? ty:TypeRef |
138 | 209 | ||
139 | PlaceholderType = | 210 | PlaceholderType = |
140 | '_' | 211 | '_' |
@@ -143,7 +214,7 @@ FnPointerType = | |||
143 | Abi 'unsafe'? 'fn' ParamList RetType? | 214 | Abi 'unsafe'? 'fn' ParamList RetType? |
144 | 215 | ||
145 | ForType = | 216 | ForType = |
146 | 'for' TypeParamList TypeRef | 217 | 'for' GenericParamList ty:TypeRef |
147 | 218 | ||
148 | ImplTraitType = | 219 | ImplTraitType = |
149 | 'impl' TypeBoundList | 220 | 'impl' TypeBoundList |
@@ -231,7 +302,7 @@ TryExpr = | |||
231 | Attr* Expr '?' | 302 | Attr* Expr '?' |
232 | 303 | ||
233 | CastExpr = | 304 | CastExpr = |
234 | Attr* Expr 'as' TypeRef | 305 | Attr* Expr 'as' ty:TypeRef |
235 | 306 | ||
236 | RefExpr = | 307 | RefExpr = |
237 | Attr* '&' ('raw' | 'mut' | 'const') Expr | 308 | Attr* '&' ('raw' | 'mut' | 'const') Expr |
@@ -263,16 +334,16 @@ MatchArm = | |||
263 | MatchGuard = | 334 | MatchGuard = |
264 | 'if' Expr | 335 | 'if' Expr |
265 | 336 | ||
266 | RecordLit = | 337 | RecordExpr = |
267 | Path RecordFieldList | 338 | Path RecordExprFieldList |
268 | 339 | ||
269 | RecordFieldList = | 340 | RecordExprFieldList = |
270 | '{' | 341 | '{' |
271 | fields:RecordField* | 342 | fields:RecordExprField* |
272 | ('..' spread:Expr)? | 343 | ('..' spread:Expr)? |
273 | '}' | 344 | '}' |
274 | 345 | ||
275 | RecordField = | 346 | RecordExprField = |
276 | Attr* NameRef (':' Expr)? | 347 | Attr* NameRef (':' Expr)? |
277 | 348 | ||
278 | OrPat = | 349 | OrPat = |
@@ -330,9 +401,6 @@ TupleStructPat = | |||
330 | TuplePat = | 401 | TuplePat = |
331 | '(' args:Pat* ')' | 402 | '(' args:Pat* ')' |
332 | 403 | ||
333 | Visibility = | ||
334 | 'pub' ('(' 'super' | 'self' | 'crate' | 'in' Path ')')? | ||
335 | |||
336 | Name = | 404 | Name = |
337 | 'ident' | 405 | 'ident' |
338 | 406 | ||
@@ -355,27 +423,6 @@ MacroStmts = | |||
355 | statements:Stmt* | 423 | statements:Stmt* |
356 | Expr? | 424 | Expr? |
357 | 425 | ||
358 | Attr = | ||
359 | '#' '!'? '[' Path ('=' input:AttrInput)? ']' | ||
360 | |||
361 | TypeParamList = | ||
362 | '<' | ||
363 | TypeParam* | ||
364 | LifetimeParam* | ||
365 | ConstParam* | ||
366 | '>' | ||
367 | |||
368 | TypeParam = | ||
369 | Attr* Name (':' TypeBoundList?)? | ||
370 | ('=' default_type:TypeRef)? | ||
371 | |||
372 | ConstParam = | ||
373 | Attr* 'const' Name ':' ascribed_type:TypeRef | ||
374 | ('=' default_val:Expr)? | ||
375 | |||
376 | LifetimeParam = | ||
377 | Attr* 'lifetime' | ||
378 | |||
379 | TypeBound = | 426 | TypeBound = |
380 | 'lifetime' | 'const'? TypeRef | 427 | 'lifetime' | 'const'? TypeRef |
381 | 428 | ||
@@ -383,31 +430,18 @@ TypeBoundList = | |||
383 | bounds:TypeBound* | 430 | bounds:TypeBound* |
384 | 431 | ||
385 | WherePred = | 432 | WherePred = |
386 | ('for' TypeParamList)? ('lifetime' | TypeRef) ':' TypeBoundList | 433 | ('for' GenericParamList)? ('lifetime' | TypeRef) ':' TypeBoundList |
387 | 434 | ||
388 | WhereClause = | 435 | WhereClause = |
389 | 'where' predicates:WherePred* | 436 | 'where' predicates:WherePred* |
390 | 437 | ||
391 | Abi = | ||
392 | 'string' | ||
393 | |||
394 | ExprStmt = | 438 | ExprStmt = |
395 | Attr* Expr ';' | 439 | Attr* Expr ';' |
396 | 440 | ||
397 | LetStmt = | 441 | LetStmt = |
398 | Attr* 'let' Pat (':' ascribed_type:TypeRef) | 442 | Attr* 'let' Pat (':' ty:TypeRef) |
399 | '=' initializer:Expr ';' | 443 | '=' initializer:Expr ';' |
400 | 444 | ||
401 | ParamList = | ||
402 | '(' SelfParam Param* ')' | ||
403 | |||
404 | SelfParam = | ||
405 | Attr* ('&' 'lifetime'?)? 'mut'? 'self' (':' ascribed_type:TypeRef) | ||
406 | |||
407 | Param = | ||
408 | Attr* Pat (':' ascribed_type:TypeRef) | ||
409 | | '...' | ||
410 | |||
411 | Path = | 445 | Path = |
412 | (qualifier:Path '::')? segment:PathSegment | 446 | (qualifier:Path '::')? segment:PathSegment |
413 | 447 | ||
@@ -435,19 +469,10 @@ LifetimeArg = | |||
435 | ConstArg = | 469 | ConstArg = |
436 | Literal | BlockExpr BlockExpr | 470 | Literal | BlockExpr BlockExpr |
437 | 471 | ||
438 | ExternBlock = | ||
439 | Attr* Abi ExternItemList | ||
440 | |||
441 | ExternItemList = | ||
442 | '{' extern_items:ExternItem* '}' | ||
443 | |||
444 | MetaItem = | ||
445 | Path '=' AttrInput nested_meta_items:MetaItem* | ||
446 | |||
447 | AdtDef = | 472 | AdtDef = |
448 | StructDef | 473 | Struct |
449 | | EnumDef | 474 | | Enum |
450 | | UnionDef | 475 | | Union |
451 | 476 | ||
452 | TypeRef = | 477 | TypeRef = |
453 | ParenType | 478 | ParenType |
@@ -464,19 +489,6 @@ TypeRef = | |||
464 | | ImplTraitType | 489 | | ImplTraitType |
465 | | DynTraitType | 490 | | DynTraitType |
466 | 491 | ||
467 | AssocItem = | ||
468 | FnDef | ||
469 | | TypeAliasDef | ||
470 | | ConstDef | ||
471 | | MacroCall | ||
472 | |||
473 | ExternItem = | ||
474 | FnDef | StaticDef | ||
475 | |||
476 | AttrInput = | ||
477 | Literal | ||
478 | | TokenTree | ||
479 | |||
480 | Stmt = | 492 | Stmt = |
481 | LetStmt | 493 | LetStmt |
482 | | ExprStmt | 494 | | ExprStmt |
@@ -514,7 +526,7 @@ Expr = | |||
514 | | BlockExpr | 526 | | BlockExpr |
515 | | ReturnExpr | 527 | | ReturnExpr |
516 | | MatchExpr | 528 | | MatchExpr |
517 | | RecordLit | 529 | | RecordExpr |
518 | | CallExpr | 530 | | CallExpr |
519 | | IndexExpr | 531 | | IndexExpr |
520 | | MethodCallExpr | 532 | | MethodCallExpr |