diff options
Diffstat (limited to 'xtask/src/codegen/rust.ungram')
-rw-r--r-- | xtask/src/codegen/rust.ungram | 274 |
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 | ||
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 |