diff options
author | Jonas Schievink <[email protected]> | 2020-08-24 21:02:55 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-08-24 21:02:55 +0100 |
commit | f3ac19e8cd8be78f1eb96893482edac038739bb1 (patch) | |
tree | 8a2cdf4db86466eca026b32a52822092248e95ba /xtask | |
parent | ed09bd3cc6a37d7d22038adf7ff815f0188a9949 (diff) |
Support extern types
Diffstat (limited to 'xtask')
-rw-r--r-- | xtask/Cargo.toml | 2 | ||||
-rw-r--r-- | xtask/src/codegen/rust.ungram | 587 |
2 files changed, 1 insertions, 588 deletions
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index e9edbdd10..0750b5657 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml | |||
@@ -15,7 +15,7 @@ flate2 = "1.0" | |||
15 | pico-args = "0.3.1" | 15 | pico-args = "0.3.1" |
16 | proc-macro2 = "1.0.8" | 16 | proc-macro2 = "1.0.8" |
17 | quote = "1.0.2" | 17 | quote = "1.0.2" |
18 | ungrammar = "1.1.1" | 18 | ungrammar = "1.1.3" |
19 | walkdir = "2.3.1" | 19 | walkdir = "2.3.1" |
20 | write-json = "0.1.0" | 20 | write-json = "0.1.0" |
21 | # Avoid adding more dependencies to this crate | 21 | # Avoid adding more dependencies to this crate |
diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram deleted file mode 100644 index aca23890c..000000000 --- a/xtask/src/codegen/rust.ungram +++ /dev/null | |||
@@ -1,587 +0,0 @@ | |||
1 | //*************************// | ||
2 | // Names, Paths and Macros // | ||
3 | //*************************// | ||
4 | |||
5 | Name = | ||
6 | 'ident' | ||
7 | |||
8 | NameRef = | ||
9 | 'ident' | 'int_number' | ||
10 | |||
11 | Path = | ||
12 | (qualifier:Path '::')? segment:PathSegment | ||
13 | |||
14 | PathSegment = | ||
15 | 'crate' | 'self' | 'super' | ||
16 | | '::' NameRef | ||
17 | | NameRef GenericArgList? | ||
18 | | NameRef ParamList RetType? | ||
19 | | '<' PathType ('as' PathType)? '>' | ||
20 | |||
21 | GenericArgList = | ||
22 | '::'? '<' (GenericArg (',' GenericArg)* ','?)? '>' | ||
23 | |||
24 | GenericArg = | ||
25 | TypeArg | ||
26 | | AssocTypeArg | ||
27 | | LifetimeArg | ||
28 | | ConstArg | ||
29 | |||
30 | TypeArg = | ||
31 | Type | ||
32 | |||
33 | AssocTypeArg = | ||
34 | NameRef (':' TypeBoundList | '=' Type) | ||
35 | |||
36 | LifetimeArg = | ||
37 | 'lifetime' | ||
38 | |||
39 | ConstArg = | ||
40 | Expr | ||
41 | |||
42 | MacroCall = | ||
43 | Attr* Path '!' Name? TokenTree ';'? | ||
44 | |||
45 | TokenTree = | ||
46 | '(' ')' | ||
47 | | '{' '}' | ||
48 | | '[' ']' | ||
49 | |||
50 | MacroItems = | ||
51 | Item* | ||
52 | |||
53 | MacroStmts = | ||
54 | statements:Stmt* | ||
55 | Expr? | ||
56 | |||
57 | //*************************// | ||
58 | // Items // | ||
59 | //*************************// | ||
60 | |||
61 | SourceFile = | ||
62 | 'shebang'? | ||
63 | Attr* | ||
64 | Item* | ||
65 | |||
66 | Item = | ||
67 | Const | ||
68 | | Enum | ||
69 | | ExternBlock | ||
70 | | ExternCrate | ||
71 | | Fn | ||
72 | | Impl | ||
73 | | MacroCall | ||
74 | | Module | ||
75 | | Static | ||
76 | | Struct | ||
77 | | Trait | ||
78 | | TypeAlias | ||
79 | | Union | ||
80 | | Use | ||
81 | |||
82 | Module = | ||
83 | Attr* Visibility? 'mod' Name | ||
84 | (ItemList | ';') | ||
85 | |||
86 | ItemList = | ||
87 | '{' Attr* Item* '}' | ||
88 | |||
89 | ExternCrate = | ||
90 | Attr* Visibility? 'extern' 'crate' (NameRef | 'self') Rename? ';' | ||
91 | |||
92 | Rename = | ||
93 | 'as' (Name | '_') | ||
94 | |||
95 | Use = | ||
96 | Attr* Visibility? 'use' UseTree ';' | ||
97 | |||
98 | UseTree = | ||
99 | (Path? '::')? ('*' | UseTreeList ) | ||
100 | | Path Rename? | ||
101 | |||
102 | UseTreeList = | ||
103 | '{' (UseTree (',' UseTree)* ','?)? '}' | ||
104 | |||
105 | Fn = | ||
106 | Attr* Visibility? | ||
107 | 'default'? ('async' | 'const')? 'unsafe'? Abi? | ||
108 | 'fn' Name GenericParamList? ParamList RetType? | ||
109 | WhereClause? | ||
110 | (body:BlockExpr | ';') | ||
111 | |||
112 | Abi = | ||
113 | 'extern' 'string'? | ||
114 | |||
115 | ParamList = | ||
116 | '('( | ||
117 | SelfParam | ||
118 | | (SelfParam ',')? (Param (',' Param)* ','?)? | ||
119 | )')' | ||
120 | |||
121 | SelfParam = | ||
122 | Attr* ( | ||
123 | ('&' 'lifetime'?)? 'mut'? 'self' | ||
124 | | 'mut'? 'self' ':' Type | ||
125 | ) | ||
126 | |||
127 | Param = | ||
128 | Attr* ( | ||
129 | Pat (':' Type) | ||
130 | | Type | ||
131 | | '...' | ||
132 | ) | ||
133 | |||
134 | RetType = | ||
135 | '->' Type | ||
136 | |||
137 | TypeAlias = | ||
138 | Attr* Visibility? 'default'? 'type' Name GenericParamList? (':' TypeBoundList?)? WhereClause? | ||
139 | '=' Type ';' | ||
140 | |||
141 | Struct = | ||
142 | Attr* Visibility? 'struct' Name GenericParamList? ( | ||
143 | WhereClause? (RecordFieldList | ';') | ||
144 | | TupleFieldList WhereClause? ';' | ||
145 | ) | ||
146 | |||
147 | RecordFieldList = | ||
148 | '{' fields:(RecordField (',' RecordField)* ','?)? '}' | ||
149 | |||
150 | RecordField = | ||
151 | Attr* Visibility? Name ':' Type | ||
152 | |||
153 | TupleFieldList = | ||
154 | '(' fields:(TupleField (',' TupleField)* ','?)? ')' | ||
155 | |||
156 | TupleField = | ||
157 | Attr* Visibility? Type | ||
158 | |||
159 | FieldList = | ||
160 | RecordFieldList | ||
161 | | TupleFieldList | ||
162 | |||
163 | Enum = | ||
164 | Attr* Visibility? 'enum' Name GenericParamList? WhereClause? | ||
165 | VariantList | ||
166 | |||
167 | VariantList = | ||
168 | '{' (Variant (',' Variant)* ','?)? '}' | ||
169 | |||
170 | Variant = | ||
171 | Attr* Visibility? Name FieldList ('=' Expr)? | ||
172 | |||
173 | Union = | ||
174 | Attr* Visibility? 'union' Name GenericParamList? WhereClause? | ||
175 | RecordFieldList | ||
176 | |||
177 | AdtDef = | ||
178 | Enum | ||
179 | | Struct | ||
180 | | Union | ||
181 | |||
182 | Const = | ||
183 | Attr* Visibility? 'default'? 'const' (Name | '_') ':' Type | ||
184 | '=' body:Expr ';' | ||
185 | |||
186 | Static = | ||
187 | Attr* Visibility? 'static'? 'mut'? Name ':' Type | ||
188 | '=' body:Expr ';' | ||
189 | |||
190 | Trait = | ||
191 | Attr* Visibility? 'unsafe'? 'auto'? 'trait' Name GenericParamList | ||
192 | (':' TypeBoundList?)? WhereClause | ||
193 | AssocItemList | ||
194 | |||
195 | AssocItemList = | ||
196 | '{' Attr* AssocItem* '}' | ||
197 | |||
198 | AssocItem = | ||
199 | Const | ||
200 | | Fn | ||
201 | | MacroCall | ||
202 | | TypeAlias | ||
203 | |||
204 | Impl = | ||
205 | Attr* Visibility? | ||
206 | 'default'? 'unsafe'? 'impl' 'const'? GenericParamList? | ||
207 | ('!'? target_trait:Type 'for')? target_type:Type | ||
208 | WhereClause? | ||
209 | AssocItemList | ||
210 | |||
211 | ExternBlock = | ||
212 | Attr* Abi ExternItemList | ||
213 | |||
214 | ExternItemList = | ||
215 | '{' Attr* ExternItem* '}' | ||
216 | |||
217 | ExternItem = | ||
218 | Fn | Static | MacroCall | ||
219 | |||
220 | GenericParamList = | ||
221 | '<' (GenericParam (',' GenericParam)* ','?)? '>' | ||
222 | |||
223 | GenericParam = | ||
224 | ConstParam | ||
225 | | LifetimeParam | ||
226 | | TypeParam | ||
227 | |||
228 | TypeParam = | ||
229 | Attr* Name (':' TypeBoundList?)? | ||
230 | ('=' default_type:Type)? | ||
231 | |||
232 | ConstParam = | ||
233 | Attr* 'const' Name ':' Type | ||
234 | ('=' default_val:Expr)? | ||
235 | |||
236 | LifetimeParam = | ||
237 | Attr* 'lifetime' (':' TypeBoundList?)? | ||
238 | |||
239 | WhereClause = | ||
240 | 'where' predicates:(WherePred (',' WherePred)* ','?) | ||
241 | |||
242 | WherePred = | ||
243 | ('for' GenericParamList)? ('lifetime' | Type) ':' TypeBoundList | ||
244 | |||
245 | Visibility = | ||
246 | 'pub' ('(' | ||
247 | 'super' | ||
248 | | 'self' | ||
249 | | 'crate' | ||
250 | | 'in' Path | ||
251 | ')')? | ||
252 | |||
253 | Attr = | ||
254 | '#' '!'? '[' Path ('=' Literal | TokenTree)? ']' | ||
255 | |||
256 | //****************************// | ||
257 | // Statements and Expressions // | ||
258 | //****************************// | ||
259 | |||
260 | Stmt = | ||
261 | ExprStmt | ||
262 | | Item | ||
263 | | LetStmt | ||
264 | |||
265 | LetStmt = | ||
266 | Attr* 'let' Pat (':' Type)? | ||
267 | '=' initializer:Expr ';' | ||
268 | |||
269 | ExprStmt = | ||
270 | Attr* Expr ';'? | ||
271 | |||
272 | Expr = | ||
273 | ArrayExpr | ||
274 | | AwaitExpr | ||
275 | | BinExpr | ||
276 | | BlockExpr | ||
277 | | BoxExpr | ||
278 | | BreakExpr | ||
279 | | CallExpr | ||
280 | | CastExpr | ||
281 | | ClosureExpr | ||
282 | | ContinueExpr | ||
283 | | EffectExpr | ||
284 | | FieldExpr | ||
285 | | ForExpr | ||
286 | | IfExpr | ||
287 | | IndexExpr | ||
288 | | Literal | ||
289 | | LoopExpr | ||
290 | | MacroCall | ||
291 | | MatchExpr | ||
292 | | MethodCallExpr | ||
293 | | ParenExpr | ||
294 | | PathExpr | ||
295 | | PrefixExpr | ||
296 | | RangeExpr | ||
297 | | RecordExpr | ||
298 | | RefExpr | ||
299 | | ReturnExpr | ||
300 | | TryExpr | ||
301 | | TupleExpr | ||
302 | | WhileExpr | ||
303 | |||
304 | Literal = | ||
305 | Attr* value:( | ||
306 | 'int_number' | 'float_number' | ||
307 | | 'string' | 'raw_string' | ||
308 | | 'byte_string' | 'raw_byte_string' | ||
309 | | 'true' | 'false' | ||
310 | | 'char' | 'byte' | ||
311 | ) | ||
312 | |||
313 | PathExpr = | ||
314 | Attr* Path | ||
315 | |||
316 | BlockExpr = | ||
317 | '{' | ||
318 | Attr* | ||
319 | statements:Stmt* | ||
320 | Expr? | ||
321 | '}' | ||
322 | |||
323 | RefExpr = | ||
324 | Attr* '&' ('raw' |'mut' | 'const') Expr | ||
325 | |||
326 | TryExpr = | ||
327 | Attr* Expr '?' | ||
328 | |||
329 | EffectExpr = | ||
330 | Attr* Label? ('try' | 'unsafe' | 'async') BlockExpr | ||
331 | |||
332 | PrefixExpr = | ||
333 | Attr* op:('-' | '!' | '*') Expr | ||
334 | |||
335 | BinExpr = | ||
336 | Attr* | ||
337 | lhs:Expr | ||
338 | op:( | ||
339 | '||' | '&&' | ||
340 | | '==' | '!=' | '<=' | '>=' | '<' | '>' | ||
341 | | '+' | '*' | '-' | '/' | '%' | '<<' | '>>' | '^' | '|' | '&' | ||
342 | | '=' | '+=' | '/=' | '*=' | '%=' | '>>=' | '<<=' | '-=' | '|=' | '&=' | '^=' | ||
343 | ) | ||
344 | rhs:Expr | ||
345 | |||
346 | CastExpr = | ||
347 | Attr* Expr 'as' Type | ||
348 | |||
349 | ParenExpr = | ||
350 | Attr* '(' Attr* Expr ')' | ||
351 | |||
352 | ArrayExpr = | ||
353 | Attr* '[' Attr* ( | ||
354 | (Expr (',' Expr)* ','?)? | ||
355 | | Expr ';' Expr | ||
356 | ) ']' | ||
357 | |||
358 | IndexExpr = | ||
359 | Attr* base:Expr '[' index:Expr ']' | ||
360 | |||
361 | TupleExpr = | ||
362 | Attr* '(' Attr* fields:(Expr (',' Expr)* ','?)? ')' | ||
363 | |||
364 | RecordExpr = | ||
365 | Path RecordExprFieldList | ||
366 | |||
367 | RecordExprFieldList = | ||
368 | '{' | ||
369 | Attr* | ||
370 | fields:(RecordExprField (',' RecordExprField)* ','?) | ||
371 | ('..' spread:Expr)? | ||
372 | '}' | ||
373 | |||
374 | RecordExprField = | ||
375 | Attr* NameRef (':' Expr)? | ||
376 | |||
377 | CallExpr = | ||
378 | Attr* Expr ArgList | ||
379 | |||
380 | ArgList = | ||
381 | '(' args:(Expr (',' Expr)* ','?)? ')' | ||
382 | |||
383 | MethodCallExpr = | ||
384 | Attr* Expr '.' NameRef GenericArgList? ArgList | ||
385 | |||
386 | FieldExpr = | ||
387 | Attr* Expr '.' NameRef | ||
388 | |||
389 | ClosureExpr = | ||
390 | Attr* 'static'? 'async'? 'move'? ParamList RetType? | ||
391 | body:Expr | ||
392 | |||
393 | IfExpr = | ||
394 | Attr* 'if' Condition then_branch:BlockExpr | ||
395 | ('else' else_branch:(IfExpr | BlockExpr))? | ||
396 | |||
397 | Condition = | ||
398 | 'let' Pat '=' Expr | ||
399 | | Expr | ||
400 | |||
401 | LoopExpr = | ||
402 | Attr* Label? 'loop' | ||
403 | loop_body:BlockExpr | ||
404 | |||
405 | ForExpr = | ||
406 | Attr* Label? 'for' Pat 'in' iterable:Expr | ||
407 | loop_body:BlockExpr | ||
408 | |||
409 | WhileExpr = | ||
410 | Attr* Label? 'while' Condition | ||
411 | loop_body:BlockExpr | ||
412 | |||
413 | Label = | ||
414 | 'lifetime' | ||
415 | |||
416 | BreakExpr = | ||
417 | Attr* 'break' 'lifetime'? Expr? | ||
418 | |||
419 | ContinueExpr = | ||
420 | Attr* 'continue' 'lifetime'? | ||
421 | |||
422 | RangeExpr = | ||
423 | Attr* start:Expr? op:('..' | '..=') end:Expr? | ||
424 | |||
425 | MatchExpr = | ||
426 | Attr* 'match' Expr MatchArmList | ||
427 | |||
428 | MatchArmList = | ||
429 | '{' | ||
430 | Attr* | ||
431 | arms:MatchArm* | ||
432 | '}' | ||
433 | |||
434 | MatchArm = | ||
435 | Attr* Pat guard:MatchGuard? '=>' Expr ','? | ||
436 | |||
437 | MatchGuard = | ||
438 | 'if' Expr | ||
439 | |||
440 | ReturnExpr = | ||
441 | Attr* 'return' Expr? | ||
442 | |||
443 | AwaitExpr = | ||
444 | Attr* Expr '.' 'await' | ||
445 | |||
446 | BoxExpr = | ||
447 | Attr* 'box' Expr | ||
448 | |||
449 | //*************************// | ||
450 | // Types // | ||
451 | //*************************// | ||
452 | |||
453 | Type = | ||
454 | ArrayType | ||
455 | | DynTraitType | ||
456 | | FnPointerType | ||
457 | | ForType | ||
458 | | ImplTraitType | ||
459 | | InferType | ||
460 | | NeverType | ||
461 | | ParenType | ||
462 | | PathType | ||
463 | | PointerType | ||
464 | | ReferenceType | ||
465 | | SliceType | ||
466 | | TupleType | ||
467 | |||
468 | ParenType = | ||
469 | '(' Type ')' | ||
470 | |||
471 | NeverType = | ||
472 | '!' | ||
473 | |||
474 | PathType = | ||
475 | Path | ||
476 | |||
477 | TupleType = | ||
478 | '(' fields:(Type (',' Type)* ','?)? ')' | ||
479 | |||
480 | PointerType = | ||
481 | '*' ('const' | 'mut') Type | ||
482 | |||
483 | ReferenceType = | ||
484 | '&' 'lifetime'? 'mut'? Type | ||
485 | |||
486 | ArrayType = | ||
487 | '[' Type ';' Expr ']' | ||
488 | |||
489 | SliceType = | ||
490 | '[' Type ']' | ||
491 | |||
492 | InferType = | ||
493 | '_' | ||
494 | |||
495 | FnPointerType = | ||
496 | 'const'? 'async'? 'unsafe'? Abi? 'fn' ParamList RetType? | ||
497 | |||
498 | ForType = | ||
499 | 'for' GenericParamList Type | ||
500 | |||
501 | ImplTraitType = | ||
502 | 'impl' TypeBoundList | ||
503 | |||
504 | DynTraitType = | ||
505 | 'dyn' TypeBoundList | ||
506 | |||
507 | TypeBoundList = | ||
508 | bounds:(TypeBound ('+' TypeBound)* '+'?) | ||
509 | |||
510 | TypeBound = | ||
511 | 'lifetime' | ||
512 | | '?'? Type | ||
513 | |||
514 | //************************// | ||
515 | // Patterns // | ||
516 | //************************// | ||
517 | |||
518 | Pat = | ||
519 | IdentPat | ||
520 | | BoxPat | ||
521 | | RestPat | ||
522 | | LiteralPat | ||
523 | | MacroPat | ||
524 | | OrPat | ||
525 | | ParenPat | ||
526 | | PathPat | ||
527 | | WildcardPat | ||
528 | | RangePat | ||
529 | | RecordPat | ||
530 | | RefPat | ||
531 | | SlicePat | ||
532 | | TuplePat | ||
533 | | TupleStructPat | ||
534 | |||
535 | LiteralPat = | ||
536 | Literal | ||
537 | |||
538 | IdentPat = | ||
539 | Attr* 'ref'? 'mut'? Name ('@' Pat)? | ||
540 | |||
541 | WildcardPat = | ||
542 | '_' | ||
543 | |||
544 | RangePat = | ||
545 | start:Pat op:('..' | '..=') end:Pat | ||
546 | |||
547 | RefPat = | ||
548 | '&' 'mut'? Pat | ||
549 | |||
550 | RecordPat = | ||
551 | Path RecordPatFieldList | ||
552 | |||
553 | RecordPatFieldList = | ||
554 | '{' | ||
555 | fields:(RecordPatField (',' RecordPatField)* ','?) | ||
556 | '..'? | ||
557 | '}' | ||
558 | |||
559 | RecordPatField = | ||
560 | Attr* (NameRef ':')? Pat | ||
561 | |||
562 | TupleStructPat = | ||
563 | Path '(' fields:(Pat (',' Pat)* ','?)? ')' | ||
564 | |||
565 | TuplePat = | ||
566 | '(' fields:(Pat (',' Pat)* ','?)? ')' | ||
567 | |||
568 | ParenPat = | ||
569 | '(' Pat ')' | ||
570 | |||
571 | SlicePat = | ||
572 | '[' (Pat (',' Pat)* ','?)? ']' | ||
573 | |||
574 | PathPat = | ||
575 | Path | ||
576 | |||
577 | OrPat = | ||
578 | (Pat ('|' Pat)* '|'?) | ||
579 | |||
580 | BoxPat = | ||
581 | 'box' Pat | ||
582 | |||
583 | RestPat = | ||
584 | '..' | ||
585 | |||
586 | MacroPat = | ||
587 | MacroCall | ||