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