aboutsummaryrefslogtreecommitdiff
path: root/xtask/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-31 15:52:08 +0100
committerAleksey Kladov <[email protected]>2020-07-31 15:52:08 +0100
commitbfcee63e75d6feb21cafbdf3887e0efd508b6b2e (patch)
treef581a142abd56ff49c84f1b0c3f0b32ef8be5639 /xtask/src
parentd4d986c7f850e1f535bb4c22e3a7f7fba5483628 (diff)
Work on expressions grammar
Diffstat (limited to 'xtask/src')
-rw-r--r--xtask/src/codegen/gen_syntax.rs3
-rw-r--r--xtask/src/codegen/rust.ungram330
2 files changed, 176 insertions, 157 deletions
diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs
index d9f358513..90f746e96 100644
--- a/xtask/src/codegen/gen_syntax.rs
+++ b/xtask/src/codegen/gen_syntax.rs
@@ -579,6 +579,9 @@ 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 if l == "op" {
583 return;
584 }
582 lower_rule(acc, grammar, Some(l), rule); 585 lower_rule(acc, grammar, Some(l), rule);
583 } 586 }
584 Rule::Seq(rules) | Rule::Alt(rules) => { 587 Rule::Seq(rules) | Rule::Alt(rules) => {
diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram
index 17de36d7a..93195befe 100644
--- a/xtask/src/codegen/rust.ungram
+++ b/xtask/src/codegen/rust.ungram
@@ -115,8 +115,8 @@ Union =
115 RecordFieldList 115 RecordFieldList
116 116
117AdtDef = 117AdtDef =
118 Struct 118 Enum
119| Enum 119| Struct
120| Union 120| Union
121 121
122Const = 122Const =
@@ -136,10 +136,10 @@ AssocItemList =
136 '{' Attr* AssocItem* '}' 136 '{' Attr* AssocItem* '}'
137 137
138AssocItem = 138AssocItem =
139 Fn 139 Const
140| TypeAlias 140| Fn
141| Const
142| MacroCall 141| MacroCall
142| TypeAlias
143 143
144Impl = 144Impl =
145 Attr* Visibility? 145 Attr* Visibility?
@@ -162,9 +162,9 @@ GenericParamList =
162 '<' (GenericParam (',' GenericParam)* ','?)? '>' 162 '<' (GenericParam (',' GenericParam)* ','?)? '>'
163 163
164GenericParam = 164GenericParam =
165 LifetimeParam 165 ConstParam
166| LifetimeParam
166| TypeParam 167| TypeParam
167| ConstParam
168 168
169TypeParam = 169TypeParam =
170 Attr* Name (':' TypeBoundList?)? 170 Attr* Name (':' TypeBoundList?)?
@@ -195,9 +195,9 @@ Attr =
195 '#' '!'? '[' Path ('=' Literal | TokenTree)? ']' 195 '#' '!'? '[' Path ('=' Literal | TokenTree)? ']'
196 196
197Stmt = 197Stmt =
198 LetStmt 198 ExprStmt
199| ExprStmt
200| Item 199| Item
200| LetStmt
201 201
202LetStmt = 202LetStmt =
203 Attr* 'let' Pat (':' Type)? 203 Attr* 'let' Pat (':' Type)?
@@ -206,189 +206,238 @@ LetStmt =
206ExprStmt = 206ExprStmt =
207 Attr* Expr ';'? 207 Attr* Expr ';'?
208 208
209Type = 209Expr =
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| LambdaExpr
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
224ParenType = 242Literal =
225 '(' Type ')' 243 Attr* 'int_number'
226 244
227NeverType = 245PathExpr =
228 '!' 246 Attr* Path
229 247
230PathType = 248BlockExpr =
231 Path 249 '{'
250 Attr*
251 statements:Stmt*
252 Expr?
253 '}'
232 254
233TupleType = 255RefExpr =
234 '(' fields:(Type (',' Type)* ','?)? ')' 256 Attr* '&' ('raw' |'mut' | 'const') Expr
235 257
236PointerType = 258TryExpr =
237 '*' ('const' | 'mut') Type 259 Attr* Expr '?'
238 260
239ReferenceType = 261EffectExpr =
240 '&' 'lifetime'? 'mut'? Type 262 Attr* Label? ('try' | 'unsafe' | 'async') BlockExpr
241 263
242ArrayType = 264PrefixExpr =
243 '[' Type ';' Expr ']' 265 Attr* op:('-' | '!' | '*') Expr
244 266
245SliceType = 267BinExpr =
246 '[' Type ']' 268 Attr*
269 Expr
270 op:(
271 '||' | '&&'
272 | '==' | '!=' | '<=' | '>=' | '<' | '>'
273 | '+' | '*' | '-' | '/' | '%' | '<<' | '>>' | '^' | '|' | '&'
274 | '=' | '+=' | '/=' | '*=' | '%=' | '>>=' | '<<=' | '-=' | '|=' | '&=' | '^='
275 )
276 Expr
247 277
248InferType = 278CastExpr =
249 '_' 279 Attr* Expr 'as' Type
250 280
251FnPointerType = 281ParenExpr =
252 'const'? 'async'? 'unsafe'? Abi? 'fn' ParamList RetType? 282 Attr* '(' Attr* Expr ')'
253 283
254ForType = 284ArrayExpr =
255 'for' GenericParamList Type 285 Attr* '[' Attr* (
286 (Expr (',' Expr)* ','?)?
287 | Expr ';' Expr
288 ) ']'
256 289
257ImplTraitType = 290IndexExpr =
258 'impl' TypeBoundList 291 Attr* Expr '[' Expr ']'
259 292
260DynTraitType = 293TupleExpr =
261 'dyn' TypeBoundList 294 Attr* '(' Attr* (Expr (',' Expr)* ','?)? ')'
262 295
263TypeBoundList = 296RecordExpr =
264 bounds:(TypeBound ('+' TypeBound)* '+'?) 297 Path RecordExprFieldList
265 298
266TypeBound = 299RecordExprFieldList =
267 'lifetime' 300 '{'
268| '?'? Type 301 Attr*
302 fields:(RecordExprField (',' RecordExprField)* ','?)
303 ('..' spread:Expr)?
304 '}'
269 305
270TupleExpr = 306RecordExprField =
271 Attr* '(' Expr* ')' 307 Attr* NameRef (':' Expr)?
272 308
273ArrayExpr = 309CallExpr =
274 Attr* '[' (Expr* | Expr ';' Expr) ']' 310 Attr* Expr ArgList
275 311
276ParenExpr = 312ArgList =
277 Attr* '(' Expr ')' 313 '(' args:(Expr (',' Expr)* ','?)? ')'
278 314
279PathExpr = 315MethodCallExpr =
280 Path 316 Attr* Expr '.' NameRef TypeArgList? ArgList
317
318FieldExpr =
319 Attr* Expr '.' NameRef
281 320
282LambdaExpr = 321LambdaExpr =
283 Attr* 'static'? 'async'? 'move'? ParamList RetType? 322 Attr* 'static'? 'async'? 'move'? ParamList RetType?
284 body:Expr 323 body:Expr
285 324
286IfExpr = 325IfExpr =
287 Attr* 'if' Condition 326 Attr* 'if' Condition BlockExpr
327 ('else' (IfExpr | BlockExpr))?
288 328
289Condition = 329Condition =
290 'let' Pat '=' Expr 330 'let' Pat '=' Expr
291| Expr 331| Expr
292 332
293EffectExpr =
294 Attr* Label? ('try' | 'unsafe' | 'async') BlockExpr
295
296LoopExpr = 333LoopExpr =
297 Attr* Label? 'loop' 334 Attr* Label? 'loop'
298 loop_body:BlockExpr? 335 loop_body:BlockExpr
299 336
300ForExpr = 337ForExpr =
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
304WhileExpr = 341WhileExpr =
305 Attr* Label? 'while' Condition 342 Attr* Label? 'while' Condition
306 loop_body:BlockExpr? 343 loop_body:BlockExpr?
307 344
308ContinueExpr = 345Label =
309 Attr* 'continue' 'lifetime'? 346 'lifetime'
310 347
311BreakExpr = 348BreakExpr =
312 Attr* 'break' 'lifetime'? Expr? 349 Attr* 'break' 'lifetime'? Expr?
313 350
314Label = 351ContinueExpr =
315 'lifetime' 352 Attr* 'continue' 'lifetime'?
316
317BlockExpr =
318 Attr* Label
319 '{'
320 statements:Stmt*
321 Expr?
322 '}'
323 353
324ReturnExpr = 354RangeExpr =
325 Attr* 'return' Expr 355 Attr* Expr? op:('..' | '..=') Expr?
326 356
327CallExpr = 357MatchExpr =
328 Attr* Expr ArgList 358 Attr* 'match' Expr MatchArmList
329 359
330MethodCallExpr = 360MatchArmList =
331 Attr* Expr '.' NameRef TypeArgList? ArgList 361 '{'
362 Attr*
363 arms:MatchArm*
364 '}'
332 365
333ArgList = 366MatchArm =
334 '(' args:Expr* ')' 367 Attr* Pat guard:MatchGuard? '=>' Expr ','?
335 368
336FieldExpr = 369MatchGuard =
337 Attr* Expr '.' NameRef 370 'if' Expr
338 371
339IndexExpr = 372ReturnExpr =
340 Attr* '[' ']' 373 Attr* 'return' Expr?
341 374
342AwaitExpr = 375AwaitExpr =
343 Attr* Expr '.' 'await' 376 Attr* Expr '.' 'await'
344 377
345TryExpr = 378BoxExpr =
346 Attr* Expr '?' 379 Attr* 'box' Expr
347 380
348CastExpr = 381Type =
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
351RefExpr = 396ParenType =
352 Attr* '&' ('raw' | 'mut' | 'const') Expr 397 '(' Type ')'
353 398
354PrefixExpr = 399NeverType =
355 Attr* Expr 400 '!'
356 401
357BoxExpr = 402PathType =
358 Attr* 'box' Expr 403 Path
359 404
360RangeExpr = 405TupleType =
361 Attr* 406 '(' fields:(Type (',' Type)* ','?)? ')'
362 407
363BinExpr = 408PointerType =
364 Attr* 409 '*' ('const' | 'mut') Type
365 410
366Literal = 411ReferenceType =
367 'int_number' 412 '&' 'lifetime'? 'mut'? Type
368 413
369MatchExpr = 414ArrayType =
370 Attr* 'match' Expr MatchArmList 415 '[' Type ';' Expr ']'
371 416
372MatchArmList = 417SliceType =
373 '{' arms:MatchArm* '}' 418 '[' Type ']'
374 419
375MatchArm = 420InferType =
376 Attr* Pat guard:MatchGuard? '=>' Expr 421 '_'
377 422
378MatchGuard = 423FnPointerType =
379 'if' Expr 424 'const'? 'async'? 'unsafe'? Abi? 'fn' ParamList RetType?
380 425
381RecordExpr = 426ForType =
382 Path RecordExprFieldList 427 'for' GenericParamList Type
383 428
384RecordExprFieldList = 429ImplTraitType =
385 '{' 430 'impl' TypeBoundList
386 fields:RecordExprField*
387 ('..' spread:Expr)?
388 '}'
389 431
390RecordExprField = 432DynTraitType =
391 Attr* NameRef (':' Expr)? 433 'dyn' TypeBoundList
434
435TypeBoundList =
436 bounds:(TypeBound ('+' TypeBound)* '+'?)
437
438TypeBound =
439 'lifetime'
440| '?'? Type
392 441
393OrPat = 442OrPat =
394 Pat* 443 Pat*
@@ -510,36 +559,3 @@ Pat =
510| RangePat 559| RangePat
511| LiteralPat 560| LiteralPat
512| MacroPat 561| MacroPat
513
514Expr =
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