diff options
Diffstat (limited to 'xtask')
-rw-r--r-- | xtask/src/ast_src.rs | 2 | ||||
-rw-r--r-- | xtask/src/codegen/gen_syntax.rs | 15 | ||||
-rw-r--r-- | xtask/src/codegen/rust.ungram | 332 |
3 files changed, 190 insertions, 159 deletions
diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs index 38b60b2a5..427406249 100644 --- a/xtask/src/ast_src.rs +++ b/xtask/src/ast_src.rs | |||
@@ -144,7 +144,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc { | |||
144 | "ARRAY_EXPR", | 144 | "ARRAY_EXPR", |
145 | "PAREN_EXPR", | 145 | "PAREN_EXPR", |
146 | "PATH_EXPR", | 146 | "PATH_EXPR", |
147 | "LAMBDA_EXPR", | 147 | "CLOSURE_EXPR", |
148 | "IF_EXPR", | 148 | "IF_EXPR", |
149 | "WHILE_EXPR", | 149 | "WHILE_EXPR", |
150 | "CONDITION", | 150 | "CONDITION", |
diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index d9f358513..059538696 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs | |||
@@ -579,6 +579,21 @@ fn lower_rule(acc: &mut Vec<Field>, grammar: &Grammar, label: Option<&String>, r | |||
579 | } | 579 | } |
580 | Rule::Labeled { label: l, rule } => { | 580 | Rule::Labeled { label: l, rule } => { |
581 | assert!(label.is_none()); | 581 | assert!(label.is_none()); |
582 | let manually_implemented = matches!( | ||
583 | l.as_str(), | ||
584 | "lhs" | ||
585 | | "rhs" | ||
586 | | "then_branch" | ||
587 | | "else_branch" | ||
588 | | "start" | ||
589 | | "end" | ||
590 | | "op" | ||
591 | | "index" | ||
592 | | "base" | ||
593 | ); | ||
594 | if manually_implemented { | ||
595 | return; | ||
596 | } | ||
582 | lower_rule(acc, grammar, Some(l), rule); | 597 | lower_rule(acc, grammar, Some(l), rule); |
583 | } | 598 | } |
584 | Rule::Seq(rules) | Rule::Alt(rules) => { | 599 | Rule::Seq(rules) | Rule::Alt(rules) => { |
diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram index 17de36d7a..aef07cb1e 100644 --- a/xtask/src/codegen/rust.ungram +++ b/xtask/src/codegen/rust.ungram | |||
@@ -115,8 +115,8 @@ Union = | |||
115 | RecordFieldList | 115 | RecordFieldList |
116 | 116 | ||
117 | AdtDef = | 117 | AdtDef = |
118 | Struct | 118 | Enum |
119 | | Enum | 119 | | Struct |
120 | | Union | 120 | | Union |
121 | 121 | ||
122 | Const = | 122 | Const = |
@@ -136,10 +136,10 @@ AssocItemList = | |||
136 | '{' Attr* AssocItem* '}' | 136 | '{' Attr* AssocItem* '}' |
137 | 137 | ||
138 | AssocItem = | 138 | AssocItem = |
139 | Fn | 139 | Const |
140 | | TypeAlias | 140 | | Fn |
141 | | Const | ||
142 | | MacroCall | 141 | | MacroCall |
142 | | TypeAlias | ||
143 | 143 | ||
144 | Impl = | 144 | Impl = |
145 | Attr* Visibility? | 145 | Attr* Visibility? |
@@ -162,9 +162,9 @@ GenericParamList = | |||
162 | '<' (GenericParam (',' GenericParam)* ','?)? '>' | 162 | '<' (GenericParam (',' GenericParam)* ','?)? '>' |
163 | 163 | ||
164 | GenericParam = | 164 | GenericParam = |
165 | LifetimeParam | 165 | ConstParam |
166 | | LifetimeParam | ||
166 | | TypeParam | 167 | | TypeParam |
167 | | ConstParam | ||
168 | 168 | ||
169 | TypeParam = | 169 | TypeParam = |
170 | Attr* Name (':' TypeBoundList?)? | 170 | Attr* Name (':' TypeBoundList?)? |
@@ -195,9 +195,9 @@ Attr = | |||
195 | '#' '!'? '[' Path ('=' Literal | TokenTree)? ']' | 195 | '#' '!'? '[' Path ('=' Literal | TokenTree)? ']' |
196 | 196 | ||
197 | Stmt = | 197 | Stmt = |
198 | LetStmt | 198 | ExprStmt |
199 | | ExprStmt | ||
200 | | Item | 199 | | Item |
200 | | LetStmt | ||
201 | 201 | ||
202 | LetStmt = | 202 | LetStmt = |
203 | Attr* 'let' Pat (':' Type)? | 203 | Attr* 'let' Pat (':' Type)? |
@@ -206,189 +206,238 @@ LetStmt = | |||
206 | ExprStmt = | 206 | ExprStmt = |
207 | Attr* Expr ';'? | 207 | Attr* Expr ';'? |
208 | 208 | ||
209 | Type = | 209 | Expr = |
210 | ParenType | 210 | ArrayExpr |
211 | | TupleType | 211 | | AwaitExpr |
212 | | NeverType | 212 | | BinExpr |
213 | | PathType | 213 | | BlockExpr |
214 | | PointerType | 214 | | BoxExpr |
215 | | ArrayType | 215 | | BreakExpr |
216 | | SliceType | 216 | | CallExpr |
217 | | ReferenceType | 217 | | CastExpr |
218 | | InferType | 218 | | ContinueExpr |
219 | | FnPointerType | 219 | | EffectExpr |
220 | | ForType | 220 | | FieldExpr |
221 | | ImplTraitType | 221 | | ForExpr |
222 | | DynTraitType | 222 | | IfExpr |
223 | | IndexExpr | ||
224 | | Label | ||
225 | | ClosureExpr | ||
226 | | Literal | ||
227 | | LoopExpr | ||
228 | | MacroCall | ||
229 | | MatchExpr | ||
230 | | MethodCallExpr | ||
231 | | ParenExpr | ||
232 | | PathExpr | ||
233 | | PrefixExpr | ||
234 | | RangeExpr | ||
235 | | RecordExpr | ||
236 | | RefExpr | ||
237 | | ReturnExpr | ||
238 | | TryExpr | ||
239 | | TupleExpr | ||
240 | | WhileExpr | ||
223 | 241 | ||
224 | ParenType = | 242 | Literal = |
225 | '(' Type ')' | 243 | Attr* 'int_number' |
226 | 244 | ||
227 | NeverType = | 245 | PathExpr = |
228 | '!' | 246 | Attr* Path |
229 | 247 | ||
230 | PathType = | 248 | BlockExpr = |
231 | Path | 249 | '{' |
250 | Attr* | ||
251 | statements:Stmt* | ||
252 | Expr? | ||
253 | '}' | ||
232 | 254 | ||
233 | TupleType = | 255 | RefExpr = |
234 | '(' fields:(Type (',' Type)* ','?)? ')' | 256 | Attr* '&' ('raw' |'mut' | 'const') Expr |
235 | 257 | ||
236 | PointerType = | 258 | TryExpr = |
237 | '*' ('const' | 'mut') Type | 259 | Attr* Expr '?' |
238 | 260 | ||
239 | ReferenceType = | 261 | EffectExpr = |
240 | '&' 'lifetime'? 'mut'? Type | 262 | Attr* Label? ('try' | 'unsafe' | 'async') BlockExpr |
241 | 263 | ||
242 | ArrayType = | 264 | PrefixExpr = |
243 | '[' Type ';' Expr ']' | 265 | Attr* op:('-' | '!' | '*') Expr |
244 | 266 | ||
245 | SliceType = | 267 | BinExpr = |
246 | '[' Type ']' | 268 | Attr* |
269 | lhs:Expr | ||
270 | op:( | ||
271 | '||' | '&&' | ||
272 | | '==' | '!=' | '<=' | '>=' | '<' | '>' | ||
273 | | '+' | '*' | '-' | '/' | '%' | '<<' | '>>' | '^' | '|' | '&' | ||
274 | | '=' | '+=' | '/=' | '*=' | '%=' | '>>=' | '<<=' | '-=' | '|=' | '&=' | '^=' | ||
275 | ) | ||
276 | rhs:Expr | ||
247 | 277 | ||
248 | InferType = | 278 | CastExpr = |
249 | '_' | 279 | Attr* Expr 'as' Type |
250 | 280 | ||
251 | FnPointerType = | 281 | ParenExpr = |
252 | 'const'? 'async'? 'unsafe'? Abi? 'fn' ParamList RetType? | 282 | Attr* '(' Attr* Expr ')' |
253 | 283 | ||
254 | ForType = | 284 | ArrayExpr = |
255 | 'for' GenericParamList Type | 285 | Attr* '[' Attr* ( |
286 | (Expr (',' Expr)* ','?)? | ||
287 | | Expr ';' Expr | ||
288 | ) ']' | ||
256 | 289 | ||
257 | ImplTraitType = | 290 | IndexExpr = |
258 | 'impl' TypeBoundList | 291 | Attr* base:Expr '[' index:Expr ']' |
259 | 292 | ||
260 | DynTraitType = | 293 | TupleExpr = |
261 | 'dyn' TypeBoundList | 294 | Attr* '(' Attr* (Expr (',' Expr)* ','?)? ')' |
262 | 295 | ||
263 | TypeBoundList = | 296 | RecordExpr = |
264 | bounds:(TypeBound ('+' TypeBound)* '+'?) | 297 | Path RecordExprFieldList |
265 | 298 | ||
266 | TypeBound = | 299 | RecordExprFieldList = |
267 | 'lifetime' | 300 | '{' |
268 | | '?'? Type | 301 | Attr* |
302 | fields:(RecordExprField (',' RecordExprField)* ','?) | ||
303 | ('..' spread:Expr)? | ||
304 | '}' | ||
269 | 305 | ||
270 | TupleExpr = | 306 | RecordExprField = |
271 | Attr* '(' Expr* ')' | 307 | Attr* NameRef (':' Expr)? |
272 | 308 | ||
273 | ArrayExpr = | 309 | CallExpr = |
274 | Attr* '[' (Expr* | Expr ';' Expr) ']' | 310 | Attr* Expr ArgList |
275 | 311 | ||
276 | ParenExpr = | 312 | ArgList = |
277 | Attr* '(' Expr ')' | 313 | '(' args:(Expr (',' Expr)* ','?)? ')' |
278 | 314 | ||
279 | PathExpr = | 315 | MethodCallExpr = |
280 | Path | 316 | Attr* Expr '.' NameRef TypeArgList? ArgList |
317 | |||
318 | FieldExpr = | ||
319 | Attr* Expr '.' NameRef | ||
281 | 320 | ||
282 | LambdaExpr = | 321 | ClosureExpr = |
283 | Attr* 'static'? 'async'? 'move'? ParamList RetType? | 322 | Attr* 'static'? 'async'? 'move'? ParamList RetType? |
284 | body:Expr | 323 | body:Expr |
285 | 324 | ||
286 | IfExpr = | 325 | IfExpr = |
287 | Attr* 'if' Condition | 326 | Attr* 'if' Condition then_branch:BlockExpr |
327 | ('else' else_branch:(IfExpr | BlockExpr))? | ||
288 | 328 | ||
289 | Condition = | 329 | Condition = |
290 | 'let' Pat '=' Expr | 330 | 'let' Pat '=' Expr |
291 | | Expr | 331 | | Expr |
292 | 332 | ||
293 | EffectExpr = | ||
294 | Attr* Label? ('try' | 'unsafe' | 'async') BlockExpr | ||
295 | |||
296 | LoopExpr = | 333 | LoopExpr = |
297 | Attr* Label? 'loop' | 334 | Attr* Label? 'loop' |
298 | loop_body:BlockExpr? | 335 | loop_body:BlockExpr |
299 | 336 | ||
300 | ForExpr = | 337 | ForExpr = |
301 | Attr* Label? 'for' Pat 'in' iterable:Expr | 338 | Attr* Label? 'for' Pat 'in' iterable:Expr |
302 | loop_body:BlockExpr? | 339 | loop_body:BlockExpr |
303 | 340 | ||
304 | WhileExpr = | 341 | WhileExpr = |
305 | Attr* Label? 'while' Condition | 342 | Attr* Label? 'while' Condition |
306 | loop_body:BlockExpr? | 343 | loop_body:BlockExpr? |
307 | 344 | ||
308 | ContinueExpr = | 345 | Label = |
309 | Attr* 'continue' 'lifetime'? | 346 | 'lifetime' |
310 | 347 | ||
311 | BreakExpr = | 348 | BreakExpr = |
312 | Attr* 'break' 'lifetime'? Expr? | 349 | Attr* 'break' 'lifetime'? Expr? |
313 | 350 | ||
314 | Label = | 351 | ContinueExpr = |
315 | 'lifetime' | 352 | Attr* 'continue' 'lifetime'? |
316 | |||
317 | BlockExpr = | ||
318 | Attr* Label | ||
319 | '{' | ||
320 | statements:Stmt* | ||
321 | Expr? | ||
322 | '}' | ||
323 | 353 | ||
324 | ReturnExpr = | 354 | RangeExpr = |
325 | Attr* 'return' Expr | 355 | Attr* start:Expr? op:('..' | '..=') end:Expr? |
326 | 356 | ||
327 | CallExpr = | 357 | MatchExpr = |
328 | Attr* Expr ArgList | 358 | Attr* 'match' Expr MatchArmList |
329 | 359 | ||
330 | MethodCallExpr = | 360 | MatchArmList = |
331 | Attr* Expr '.' NameRef TypeArgList? ArgList | 361 | '{' |
362 | Attr* | ||
363 | arms:MatchArm* | ||
364 | '}' | ||
332 | 365 | ||
333 | ArgList = | 366 | MatchArm = |
334 | '(' args:Expr* ')' | 367 | Attr* Pat guard:MatchGuard? '=>' Expr ','? |
335 | 368 | ||
336 | FieldExpr = | 369 | MatchGuard = |
337 | Attr* Expr '.' NameRef | 370 | 'if' Expr |
338 | 371 | ||
339 | IndexExpr = | 372 | ReturnExpr = |
340 | Attr* '[' ']' | 373 | Attr* 'return' Expr? |
341 | 374 | ||
342 | AwaitExpr = | 375 | AwaitExpr = |
343 | Attr* Expr '.' 'await' | 376 | Attr* Expr '.' 'await' |
344 | 377 | ||
345 | TryExpr = | 378 | BoxExpr = |
346 | Attr* Expr '?' | 379 | Attr* 'box' Expr |
347 | 380 | ||
348 | CastExpr = | 381 | Type = |
349 | Attr* Expr 'as' Type | 382 | ArrayType |
383 | | DynTraitType | ||
384 | | FnPointerType | ||
385 | | ForType | ||
386 | | ImplTraitType | ||
387 | | InferType | ||
388 | | NeverType | ||
389 | | ParenType | ||
390 | | PathType | ||
391 | | PointerType | ||
392 | | ReferenceType | ||
393 | | SliceType | ||
394 | | TupleType | ||
350 | 395 | ||
351 | RefExpr = | 396 | ParenType = |
352 | Attr* '&' ('raw' | 'mut' | 'const') Expr | 397 | '(' Type ')' |
353 | 398 | ||
354 | PrefixExpr = | 399 | NeverType = |
355 | Attr* Expr | 400 | '!' |
356 | 401 | ||
357 | BoxExpr = | 402 | PathType = |
358 | Attr* 'box' Expr | 403 | Path |
359 | 404 | ||
360 | RangeExpr = | 405 | TupleType = |
361 | Attr* | 406 | '(' fields:(Type (',' Type)* ','?)? ')' |
362 | 407 | ||
363 | BinExpr = | 408 | PointerType = |
364 | Attr* | 409 | '*' ('const' | 'mut') Type |
365 | 410 | ||
366 | Literal = | 411 | ReferenceType = |
367 | 'int_number' | 412 | '&' 'lifetime'? 'mut'? Type |
368 | 413 | ||
369 | MatchExpr = | 414 | ArrayType = |
370 | Attr* 'match' Expr MatchArmList | 415 | '[' Type ';' Expr ']' |
371 | 416 | ||
372 | MatchArmList = | 417 | SliceType = |
373 | '{' arms:MatchArm* '}' | 418 | '[' Type ']' |
374 | 419 | ||
375 | MatchArm = | 420 | InferType = |
376 | Attr* Pat guard:MatchGuard? '=>' Expr | 421 | '_' |
377 | 422 | ||
378 | MatchGuard = | 423 | FnPointerType = |
379 | 'if' Expr | 424 | 'const'? 'async'? 'unsafe'? Abi? 'fn' ParamList RetType? |
380 | 425 | ||
381 | RecordExpr = | 426 | ForType = |
382 | Path RecordExprFieldList | 427 | 'for' GenericParamList Type |
383 | 428 | ||
384 | RecordExprFieldList = | 429 | ImplTraitType = |
385 | '{' | 430 | 'impl' TypeBoundList |
386 | fields:RecordExprField* | ||
387 | ('..' spread:Expr)? | ||
388 | '}' | ||
389 | 431 | ||
390 | RecordExprField = | 432 | DynTraitType = |
391 | Attr* NameRef (':' Expr)? | 433 | 'dyn' TypeBoundList |
434 | |||
435 | TypeBoundList = | ||
436 | bounds:(TypeBound ('+' TypeBound)* '+'?) | ||
437 | |||
438 | TypeBound = | ||
439 | 'lifetime' | ||
440 | | '?'? Type | ||
392 | 441 | ||
393 | OrPat = | 442 | OrPat = |
394 | Pat* | 443 | Pat* |
@@ -510,36 +559,3 @@ Pat = | |||
510 | | RangePat | 559 | | RangePat |
511 | | LiteralPat | 560 | | LiteralPat |
512 | | MacroPat | 561 | | MacroPat |
513 | |||
514 | Expr = | ||
515 | TupleExpr | ||
516 | | ArrayExpr | ||
517 | | ParenExpr | ||
518 | | PathExpr | ||
519 | | LambdaExpr | ||
520 | | IfExpr | ||
521 | | LoopExpr | ||
522 | | ForExpr | ||
523 | | WhileExpr | ||
524 | | ContinueExpr | ||
525 | | BreakExpr | ||
526 | | Label | ||
527 | | BlockExpr | ||
528 | | ReturnExpr | ||
529 | | MatchExpr | ||
530 | | RecordExpr | ||
531 | | CallExpr | ||
532 | | IndexExpr | ||
533 | | MethodCallExpr | ||
534 | | FieldExpr | ||
535 | | AwaitExpr | ||
536 | | TryExpr | ||
537 | | EffectExpr | ||
538 | | CastExpr | ||
539 | | RefExpr | ||
540 | | PrefixExpr | ||
541 | | RangeExpr | ||
542 | | BinExpr | ||
543 | | Literal | ||
544 | | MacroCall | ||
545 | | BoxExpr | ||