aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/codegen/rust.ungram
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src/codegen/rust.ungram')
-rw-r--r--xtask/src/codegen/rust.ungram274
1 files changed, 143 insertions, 131 deletions
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
6Item = 6Item =
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
22Module = 22Module =
@@ -42,78 +42,149 @@ UseTree =
42UseTreeList = 42UseTreeList =
43 '{' (UseTree (',' UseTree)* ','?)? '}' 43 '{' (UseTree (',' UseTree)* ','?)? '}'
44 44
45FnDef = 45Fn =
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
52Abi =
53 'extern' 'string'?
54
55ParamList =
56 '('(
57 SelfParam
58 | (SelfParam ',')? (Param (',' Param)* ','?)?
59 )')'
60
61SelfParam =
62 Attr* (
63 ('&' 'lifetime'?)? 'mut'? 'self'
64 | 'mut'? 'self' ':' ty:TypeRef
65 )
66
67Param =
68 Attr* (
69 Pat (':' ty:TypeRef)
70 | ty:TypeRef
71 | '...'
72 )
73
51RetType = 74RetType =
52 '->' TypeRef 75 '->' ty:TypeRef
76
77TypeAlias =
78 Attr* Visibility? 'default'? 'type' Name GenericParamList? (':' TypeBoundList?)? WhereClause?
79 '=' ty:TypeRef ';'
53 80
54StructDef = 81Struct =
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
60UnionDef = 87RecordFieldList =
61 Attr* Visibility? 'union' Name TypeParamList? WhereClause? 88 '{' fields:(RecordField (',' RecordField)* ','?)? '}'
62 RecordFieldDefList 89
90RecordField =
91 Attr* Visibility? Name ':' ty:TypeRef
63 92
64RecordFieldDefList = 93TupleFieldList =
65 '{' fields:RecordFieldDef* '}' 94 '(' fields:(TupleField (',' TupleField)* ','?)? ')'
66 95
67RecordFieldDef = 96TupleField =
68 Attr* Visibility? Name ':' ascribed_type:TypeRef 97 Attr* Visibility? ty:TypeRef
69 98
70TupleFieldDefList = 99FieldList =
71 '(' fields:TupleFieldDef* ')' 100 RecordFieldList
101| TupleFieldList
72 102
73TupleFieldDef = 103Enum =
74 Attr* Visibility? Name TypeRef 104 Attr* Visibility? 'enum' Name GenericParamList? WhereClause?
105 VariantList
75 106
76FieldDefList = 107VariantList =
77 RecordFieldDefList 108 '{' (Variant (',' Variant)* ','?)? '}'
78| TupleFieldDefList
79 109
80EnumDef = 110Variant =
81 Attr* Visibility? 'enum' Name TypeParamList? WhereClause? 111 Attr* Visibility? Name FieldList ('=' Expr)?
82 variant_list:EnumVariantList
83 112
84EnumVariantList = 113Union =
85 '{' variants:EnumVariant* '}' 114 Attr* Visibility? 'union' Name GenericParamList? WhereClause?
115 RecordFieldList
116
117Const =
118 Attr* Visibility? 'default'? 'const' (Name | '_') ':' ty:TypeRef
119 '=' body:Expr ';'
86 120
87EnumVariant = 121Static =
88 Attr* Visibility? Name FieldDefList ('=' Expr)? 122 Attr* Visibility? 'static'? 'mut'? Name ':' ty:TypeRef
123 '=' body:Expr ';'
89 124
90TraitDef = 125Trait =
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
95AssocItemList = 130AssocItemList =
96 '{' AssocItem* '}' 131 '{' Attr* AssocItem* '}'
97 132
98ConstDef = 133AssocItem =
99 Attr* Visibility? 'default'? 'const' Name ':' ascribed_type:TypeRef 134 Fn
100 '=' body:Expr ';' 135| TypeAlias
136| Const
137| MacroCall
101 138
102StaticDef = 139Impl =
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
106TypeAliasDef = 147ExternBlock =
107 Attr* Visibility? 'default'? 'type' Name TypeParamList? WhereClause? (':' TypeBoundList?)? 148 Attr* Abi ExternItemList
108 '=' TypeRef ';'
109 149
110ImplDef = 150ExternItemList =
111 Attr* Visibility? 'const'? 'default'? 'unsafe'? 'impl' TypeParamList? '!'? 'for' 151 '{' Attr* ExternItem* '}'
112 WhereClause? 152
113 AssocItemList 153ExternItem =
154 Fn | Static | MacroCall
155
156GenericParamList =
157 '<' (GenericParam (',' GenericParam)* ','?)? '>'
158
159GenericParam =
160 LifetimeParam
161| TypeParam
162| ConstParam
163
164TypeParam =
165 Attr* Name (':' TypeBoundList?)?
166 ('=' default_type:TypeRef)?
167
168ConstParam =
169 Attr* 'const' Name ':' ty:TypeRef
170 ('=' default_val:Expr)?
171
172LifetimeParam =
173 Attr* 'lifetime'
174
175Visibility =
176 'pub' ('('
177 'super'
178 | 'self'
179 | 'crate'
180 | 'in' Path
181 ')')?
182
183Attr =
184 '#' '!'? '[' Path ('=' Literal | TokenTree)? ']'
114 185
115ParenType = 186ParenType =
116 '(' TypeRef ')' 187 '(' ty:TypeRef ')'
117 188
118TupleType = 189TupleType =
119 '(' fields:TypeRef* ')' 190 '(' fields:TypeRef* ')'
@@ -125,16 +196,16 @@ PathType =
125 Path 196 Path
126 197
127PointerType = 198PointerType =
128 '*' ('const' | 'mut') TypeRef 199 '*' ('const' | 'mut') ty:TypeRef
129 200
130ArrayType = 201ArrayType =
131 '[' TypeRef ';' Expr ']' 202 '[' ty:TypeRef ';' Expr ']'
132 203
133SliceType = 204SliceType =
134 '[' TypeRef ']' 205 '[' ty:TypeRef ']'
135 206
136ReferenceType = 207ReferenceType =
137 '&' 'lifetime'? 'mut'? TypeRef 208 '&' 'lifetime'? 'mut'? ty:TypeRef
138 209
139PlaceholderType = 210PlaceholderType =
140 '_' 211 '_'
@@ -143,7 +214,7 @@ FnPointerType =
143 Abi 'unsafe'? 'fn' ParamList RetType? 214 Abi 'unsafe'? 'fn' ParamList RetType?
144 215
145ForType = 216ForType =
146 'for' TypeParamList TypeRef 217 'for' GenericParamList ty:TypeRef
147 218
148ImplTraitType = 219ImplTraitType =
149 'impl' TypeBoundList 220 'impl' TypeBoundList
@@ -231,7 +302,7 @@ TryExpr =
231 Attr* Expr '?' 302 Attr* Expr '?'
232 303
233CastExpr = 304CastExpr =
234 Attr* Expr 'as' TypeRef 305 Attr* Expr 'as' ty:TypeRef
235 306
236RefExpr = 307RefExpr =
237 Attr* '&' ('raw' | 'mut' | 'const') Expr 308 Attr* '&' ('raw' | 'mut' | 'const') Expr
@@ -263,16 +334,16 @@ MatchArm =
263MatchGuard = 334MatchGuard =
264 'if' Expr 335 'if' Expr
265 336
266RecordLit = 337RecordExpr =
267 Path RecordFieldList 338 Path RecordExprFieldList
268 339
269RecordFieldList = 340RecordExprFieldList =
270 '{' 341 '{'
271 fields:RecordField* 342 fields:RecordExprField*
272 ('..' spread:Expr)? 343 ('..' spread:Expr)?
273 '}' 344 '}'
274 345
275RecordField = 346RecordExprField =
276 Attr* NameRef (':' Expr)? 347 Attr* NameRef (':' Expr)?
277 348
278OrPat = 349OrPat =
@@ -330,9 +401,6 @@ TupleStructPat =
330TuplePat = 401TuplePat =
331 '(' args:Pat* ')' 402 '(' args:Pat* ')'
332 403
333Visibility =
334 'pub' ('(' 'super' | 'self' | 'crate' | 'in' Path ')')?
335
336Name = 404Name =
337 'ident' 405 'ident'
338 406
@@ -355,27 +423,6 @@ MacroStmts =
355 statements:Stmt* 423 statements:Stmt*
356 Expr? 424 Expr?
357 425
358Attr =
359 '#' '!'? '[' Path ('=' input:AttrInput)? ']'
360
361TypeParamList =
362 '<'
363 TypeParam*
364 LifetimeParam*
365 ConstParam*
366 '>'
367
368TypeParam =
369 Attr* Name (':' TypeBoundList?)?
370 ('=' default_type:TypeRef)?
371
372ConstParam =
373 Attr* 'const' Name ':' ascribed_type:TypeRef
374 ('=' default_val:Expr)?
375
376LifetimeParam =
377 Attr* 'lifetime'
378
379TypeBound = 426TypeBound =
380 'lifetime' | 'const'? TypeRef 427 'lifetime' | 'const'? TypeRef
381 428
@@ -383,31 +430,18 @@ TypeBoundList =
383 bounds:TypeBound* 430 bounds:TypeBound*
384 431
385WherePred = 432WherePred =
386 ('for' TypeParamList)? ('lifetime' | TypeRef) ':' TypeBoundList 433 ('for' GenericParamList)? ('lifetime' | TypeRef) ':' TypeBoundList
387 434
388WhereClause = 435WhereClause =
389 'where' predicates:WherePred* 436 'where' predicates:WherePred*
390 437
391Abi =
392 'string'
393
394ExprStmt = 438ExprStmt =
395 Attr* Expr ';' 439 Attr* Expr ';'
396 440
397LetStmt = 441LetStmt =
398 Attr* 'let' Pat (':' ascribed_type:TypeRef) 442 Attr* 'let' Pat (':' ty:TypeRef)
399 '=' initializer:Expr ';' 443 '=' initializer:Expr ';'
400 444
401ParamList =
402 '(' SelfParam Param* ')'
403
404SelfParam =
405 Attr* ('&' 'lifetime'?)? 'mut'? 'self' (':' ascribed_type:TypeRef)
406
407Param =
408 Attr* Pat (':' ascribed_type:TypeRef)
409| '...'
410
411Path = 445Path =
412 (qualifier:Path '::')? segment:PathSegment 446 (qualifier:Path '::')? segment:PathSegment
413 447
@@ -435,19 +469,10 @@ LifetimeArg =
435ConstArg = 469ConstArg =
436 Literal | BlockExpr BlockExpr 470 Literal | BlockExpr BlockExpr
437 471
438ExternBlock =
439 Attr* Abi ExternItemList
440
441ExternItemList =
442 '{' extern_items:ExternItem* '}'
443
444MetaItem =
445 Path '=' AttrInput nested_meta_items:MetaItem*
446
447AdtDef = 472AdtDef =
448 StructDef 473 Struct
449| EnumDef 474| Enum
450| UnionDef 475| Union
451 476
452TypeRef = 477TypeRef =
453 ParenType 478 ParenType
@@ -464,19 +489,6 @@ TypeRef =
464| ImplTraitType 489| ImplTraitType
465| DynTraitType 490| DynTraitType
466 491
467AssocItem =
468 FnDef
469| TypeAliasDef
470| ConstDef
471| MacroCall
472
473ExternItem =
474 FnDef | StaticDef
475
476AttrInput =
477 Literal
478| TokenTree
479
480Stmt = 492Stmt =
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