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.ungram529
1 files changed, 529 insertions, 0 deletions
diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram
new file mode 100644
index 000000000..b6ec5d5e7
--- /dev/null
+++ b/xtask/src/codegen/rust.ungram
@@ -0,0 +1,529 @@
1SourceFile =
2 Attr*
3 items:ModuleItem*
4
5FnDef =
6 Attr* Visibility? Abi? 'const' 'default' 'async' 'unsafe' 'fn' Name TypeParamList?
7 ParamList RetType?
8 WhereClause?
9 (body:BlockExpr | ';')
10
11RetType =
12 '->' TypeRef
13
14StructDef =
15 Attr* Visibility? 'struct' Name TypeParamList? (
16 WhereClause? (RecordFieldDefList | ';')
17 | TupleFieldDefList WhereClause? ';'
18 )
19
20UnionDef =
21 Attr* Visibility? 'union' Name TypeParamList? WhereClause?
22 RecordFieldDefList
23
24RecordFieldDefList =
25 '{' fields:RecordFieldDef* '}'
26
27RecordFieldDef =
28 Attr* Visibility? Name ':' ascribed_type:TypeRef
29
30TupleFieldDefList =
31 '(' fields:TupleFieldDef* ')'
32
33TupleFieldDef =
34 Attr* Visibility? Name TypeRef
35
36FieldDefList =
37 RecordFieldDefList
38| TupleFieldDefList
39
40EnumDef =
41 Attr* Visibility? 'enum' Name TypeParamList? WhereClause?
42 variant_list:EnumVariantList
43
44EnumVariantList =
45 '{' variants:EnumVariant* '}'
46
47EnumVariant =
48 Attr* Visibility? Name FieldDefList ('=' Expr)?
49
50TraitDef =
51 Attr* Visibility? 'unsafe'? 'auto'? 'trait' Name TypeParamList
52 (':' TypeBoundList?)? WhereClause
53 ItemList
54
55Module =
56 Attr* Visibility? 'mod' Name
57 (ItemList | ';')
58
59ItemList =
60 '{'
61 AssocItem*
62 items:ModuleItem*
63 '}'
64
65ConstDef =
66 Attr* Visibility? 'default'? 'const' Name ':' ascribed_type:TypeRef
67 '=' body:Expr ';'
68
69StaticDef =
70 Attr* Visibility? 'static'? 'mut'? 'static' Name ':' ascribed_type:TypeRef
71 '=' body:Expr ';'
72
73TypeAliasDef =
74 Attr* Visibility? 'default'? 'type' Name TypeParamList? WhereClause? (':' TypeBoundList?)?
75 '=' TypeRef ';'
76
77ImplDef =
78 Attr* Visibility? 'const'? 'default'? 'unsafe'? 'impl' TypeParamList? '!'? 'for'
79 WhereClause?
80 ItemList
81
82ParenType =
83 '(' TypeRef ')'
84
85TupleType =
86 '(' fields:TypeRef* ')'
87
88NeverType =
89 '!'
90
91PathType =
92 Path
93
94PointerType =
95 '*' ('const' | 'mut') TypeRef
96
97ArrayType =
98 '[' TypeRef ';' Expr ']'
99
100SliceType =
101 '[' TypeRef ']'
102
103ReferenceType =
104 '&' 'lifetime'? 'mut'? TypeRef
105
106PlaceholderType =
107 '_'
108
109FnPointerType =
110 Abi 'unsafe'? 'fn' ParamList RetType?
111
112ForType =
113 'for' TypeParamList TypeRef
114
115ImplTraitType =
116 'impl' TypeBoundList
117
118DynTraitType =
119 'dyn' TypeBoundList
120
121TupleExpr =
122 Attr* '(' Expr* ')'
123
124ArrayExpr =
125 Attr* '[' (Expr* | Expr ';' Expr) ']'
126
127ParenExpr =
128 Attr* '(' Expr ')'
129
130PathExpr =
131 Path
132
133LambdaExpr =
134 Attr* 'static'? 'async'? 'move'? ParamList RetType?
135 body:Expr
136
137IfExpr =
138 Attr* 'if' Condition
139
140Condition =
141 'let' Pat '=' Expr
142| Expr
143
144EffectExpr =
145 Attr* Label? ('try' | 'unsafe' | 'async') BlockExpr
146
147LoopExpr =
148 Attr* Label? 'loop'
149 loop_body:BlockExpr?
150
151ForExpr =
152 Attr* Label? 'for' Pat 'in' iterable:Expr
153 loop_body:BlockExpr?
154
155WhileExpr =
156 Attr* Label? 'while' Condition
157 loop_body:BlockExpr?
158
159ContinueExpr =
160 Attr* 'continue' 'lifetime'?
161
162BreakExpr =
163 Attr* 'break' 'lifetime'? Expr?
164
165Label =
166 'lifetime'
167
168BlockExpr =
169 Attr* Label
170 '{'
171 items:ModuleItem*
172 statements:Stmt*
173 Expr?
174 '}'
175
176ReturnExpr =
177 Attr* 'return' Expr
178
179CallExpr =
180 Attr* Expr ArgList
181
182MethodCallExpr =
183 Attr* Expr '.' NameRef TypeArgList? ArgList
184
185ArgList =
186 '(' args:Expr* ')'
187
188FieldExpr =
189 Attr* Expr '.' NameRef
190
191IndexExpr =
192 Attr* '[' ']'
193
194AwaitExpr =
195 Attr* Expr '.' 'await'
196
197TryExpr =
198 Attr* Expr '?'
199
200CastExpr =
201 Attr* Expr 'as' TypeRef
202
203RefExpr =
204 Attr* '&' ('raw' | 'mut' | 'const') Expr
205
206PrefixExpr =
207 Attr* Expr
208
209BoxExpr =
210 Attr* 'box' Expr
211
212RangeExpr =
213 Attr*
214
215BinExpr =
216 Attr*
217
218Literal =
219 'int_number'
220
221MatchExpr =
222 Attr* 'match' Expr MatchArmList
223
224MatchArmList =
225 '{' arms:MatchArm* '}'
226
227MatchArm =
228 Attr* Pat guard:MatchGuard? '=>' Expr
229
230MatchGuard =
231 'if' Expr
232
233RecordLit =
234 Path RecordFieldList
235
236RecordFieldList =
237 '{'
238 fields:RecordField*
239 ('..' spread:Expr)?
240 '}'
241
242RecordField =
243 Attr* NameRef (':' Expr)?
244
245OrPat =
246 Pat*
247
248ParenPat =
249 '(' Pat ')'
250
251RefPat =
252 '&' 'mut'? Pat
253
254BoxPat =
255 'box' Path
256
257BindPat =
258 Attr* 'ref'? 'mut'? Name ('@' Pat)?
259
260PlaceholderPat =
261 '_'
262
263DotDotPat =
264 '..'
265
266PathPat =
267 Path
268
269SlicePat =
270 '[' args:Pat* ']'
271
272RangePat =
273 '..' | '..='
274
275LiteralPat =
276 Literal
277
278MacroPat =
279 MacroCall
280
281RecordPat =
282 Path RecordFieldPatList
283
284RecordFieldPatList =
285 '{'
286 record_field_pats:RecordFieldPat*
287 BindPat*
288 '..'?
289 '}'
290
291RecordFieldPat =
292 Attr* NameRef ':' Pat
293
294TupleStructPat =
295 Path '(' args:Pat* ')'
296
297TuplePat =
298 '(' args:Pat* ')'
299
300Visibility =
301 'pub' ('(' 'super' | 'self' | 'crate' | 'in' Path ')')?
302
303Name =
304 'ident'
305
306NameRef =
307 'ident' | 'int_number'
308
309MacroCall =
310 Attr* Path '!' Name? TokenTree ';'?
311
312MacroDef =
313 Name TokenTree
314
315TokenTree =
316 '(' ')' | '{' '}' | '[' ']'
317
318MacroItems =
319 items:ModuleItem*
320
321MacroStmts =
322 statements:Stmt*
323 Expr?
324
325Attr =
326 '#' '!'? '[' Path ('=' input:AttrInput)? ']'
327
328TypeParamList =
329 '<'
330 TypeParam*
331 LifetimeParam*
332 ConstParam*
333 '>'
334
335TypeParam =
336 Attr* Name (':' TypeBoundList?)?
337 ('=' default_type:TypeRef)?
338
339ConstParam =
340 Attr* 'const' Name ':' ascribed_type:TypeRef
341 ('=' default_val:Expr)?
342
343LifetimeParam =
344 Attr* 'lifetime'
345
346TypeBound =
347 'lifetime' | 'const'? TypeRef
348
349TypeBoundList =
350 bounds:TypeBound*
351
352WherePred =
353 ('for' TypeParamList)? ('lifetime' | TypeRef) ':' TypeBoundList
354
355WhereClause =
356 'where' predicates:WherePred*
357
358Abi =
359 'string'
360
361ExprStmt =
362 Attr* Expr ';'
363
364LetStmt =
365 Attr* 'let' Pat (':' ascribed_type:TypeRef)
366 '=' initializer:Expr ';'
367
368ParamList =
369 '(' SelfParam Param* ')'
370
371SelfParam =
372 Attr* ('&' 'lifetime'?)? 'mut'? 'self' (':' ascribed_type:TypeRef)
373
374Param =
375 Attr* Pat (':' ascribed_type:TypeRef)
376| '...'
377
378UseItem =
379 Attr* Visibility? 'use' UseTree ';'
380
381UseTree =
382 Path ('::' ('*' | UseTreeList)) Alias?
383
384UseTreeList =
385 '{' UseTree* '}'
386
387Alias =
388 'as' Name
389
390ExternCrateItem =
391 Attr* Visibility? 'extern' 'crate' (NameRef | 'self') Alias? ';'
392
393Path =
394 (qualifier:Path '::')? segment:PathSegment
395
396PathSegment =
397 '::' | 'crate' | 'self' | 'super'
398| '<' NameRef TypeArgList ParamList RetType PathType '>'
399
400TypeArgList =
401 '::'? '<'
402 TypeArg*
403 LifetimeArg*
404 AssocTypeArg*
405 ConstArg*
406 '>'
407
408TypeArg =
409 TypeRef
410
411AssocTypeArg =
412 NameRef (':' TypeBoundList | '=' TypeRef)
413
414LifetimeArg =
415 'lifetime'
416
417ConstArg =
418 Literal | BlockExpr BlockExpr
419
420ExternBlock =
421 Attr* Abi ExternItemList
422
423ExternItemList =
424 '{' extern_items:ExternItem* '}'
425
426MetaItem =
427 Path '=' AttrInput nested_meta_items:MetaItem*
428
429AdtDef =
430 StructDef
431| EnumDef
432| UnionDef
433
434TypeRef =
435 ParenType
436| TupleType
437| NeverType
438| PathType
439| PointerType
440| ArrayType
441| SliceType
442| ReferenceType
443| PlaceholderType
444| FnPointerType
445| ForType
446| ImplTraitType
447| DynTraitType
448
449AssocItem =
450 FnDef
451| TypeAliasDef
452| ConstDef
453
454ExternItem =
455 FnDef | StaticDef
456
457ModuleItem =
458 StructDef
459| UnionDef
460| EnumDef
461| FnDef
462| TraitDef
463| TypeAliasDef
464| ImplDef
465| UseItem
466| ExternCrateItem
467| ConstDef
468| StaticDef
469| Module
470| MacroCall
471| ExternBlock
472
473AttrInput =
474 Literal
475| TokenTree
476
477Stmt =
478 LetStmt
479| ExprStmt
480
481Pat =
482 OrPat
483| ParenPat
484| RefPat
485| BoxPat
486| BindPat
487| PlaceholderPat
488| DotDotPat
489| PathPat
490| RecordPat
491| TupleStructPat
492| TuplePat
493| SlicePat
494| RangePat
495| LiteralPat
496| MacroPat
497
498Expr =
499 TupleExpr
500| ArrayExpr
501| ParenExpr
502| PathExpr
503| LambdaExpr
504| IfExpr
505| LoopExpr
506| ForExpr
507| WhileExpr
508| ContinueExpr
509| BreakExpr
510| Label
511| BlockExpr
512| ReturnExpr
513| MatchExpr
514| RecordLit
515| CallExpr
516| IndexExpr
517| MethodCallExpr
518| FieldExpr
519| AwaitExpr
520| TryExpr
521| EffectExpr
522| CastExpr
523| RefExpr
524| PrefixExpr
525| RangeExpr
526| BinExpr
527| Literal
528| MacroCall
529| BoxExpr