@@ -253,7 +253,7 @@ The two values of the boolean type are written `true` and `false`.
253
253
### Symbols
254
254
255
255
``` antlr
256
- symbol : "::" "->"
256
+ symbol : "::" | "->"
257
257
| '#' | '[' | ']' | '(' | ')' | '{' | '}'
258
258
| ',' | ';' ;
259
259
```
@@ -304,7 +304,7 @@ transcriber : '(' transcriber * ')' | '[' transcriber * ']'
304
304
## Items
305
305
306
306
``` antlr
307
- item : mod_item | fn_item | type_item | struct_item | enum_item
307
+ item : vis ? mod_item | fn_item | type_item | struct_item | enum_item
308
308
| const_item | static_item | trait_item | impl_item | extern_block ;
309
309
```
310
310
@@ -322,7 +322,7 @@ mod : [ view_item | item ] * ;
322
322
#### View items
323
323
324
324
``` antlr
325
- view_item : extern_crate_decl | use_decl ;
325
+ view_item : extern_crate_decl | use_decl ';' ;
326
326
```
327
327
328
328
##### Extern crate declarations
@@ -335,14 +335,14 @@ crate_name: ident | ( ident "as" ident )
335
335
##### Use declarations
336
336
337
337
``` antlr
338
- use_decl : "pub" ? "use" [ path "as" ident
339
- | path_glob ] ;
338
+ use_decl : vis ? "use" [ path "as" ident
339
+ | path_glob ] ;
340
340
341
341
path_glob : ident [ "::" [ path_glob
342
342
| '*' ] ] ?
343
343
| '{' path_item [ ',' path_item ] * '}' ;
344
344
345
- path_item : ident | "mod " ;
345
+ path_item : ident | "self " ;
346
346
```
347
347
348
348
### Functions
@@ -414,16 +414,17 @@ extern_block : [ foreign_fn ] * ;
414
414
415
415
## Visibility and Privacy
416
416
417
- ** FIXME:** grammar?
418
-
417
+ ``` antlr
418
+ vis : "pub" ;
419
+ ```
419
420
### Re-exporting and Visibility
420
421
421
- ** FIXME: ** grammar?
422
+ See [ Use declarations ] ( #use-declarations ) .
422
423
423
424
## Attributes
424
425
425
426
``` antlr
426
- attribute : "#!" ? '[' meta_item ']' ;
427
+ attribute : '#' '!' ? '[' meta_item ']' ;
427
428
meta_item : ident [ '=' literal
428
429
| '(' meta_seq ')' ] ? ;
429
430
meta_seq : meta_item [ ',' meta_seq ] ? ;
@@ -433,26 +434,19 @@ meta_seq : meta_item [ ',' meta_seq ] ? ;
433
434
434
435
## Statements
435
436
436
- ** FIXME:** grammar?
437
+ ``` antlr
438
+ stmt : decl_stmt | expr_stmt ;
439
+ ```
437
440
438
441
### Declaration statements
439
442
440
- ** FIXME:** grammar?
441
-
442
- A _ declaration statement_ is one that introduces one or more * names* into the
443
- enclosing statement block. The declared names may denote new variables or new
444
- items.
443
+ ``` antlr
444
+ decl_stmt : item | let_decl ;
445
+ ```
445
446
446
447
#### Item declarations
447
448
448
- ** FIXME:** grammar?
449
-
450
- An _ item declaration statement_ has a syntactic form identical to an
451
- [ item] ( #items ) declaration within a module. Declaring an item &mdash ; a
452
- function, enumeration, structure, type, static, trait, implementation or module
453
- &mdash ; locally within a statement block is simply a way of restricting its
454
- scope to a narrow region containing all of its uses; it is otherwise identical
455
- in meaning to declaring the item outside the statement block.
449
+ See [ Items] ( #items ) .
456
450
457
451
#### Variable declarations
458
452
@@ -463,11 +457,21 @@ init : [ '=' ] expr ;
463
457
464
458
### Expression statements
465
459
466
- ** FIXME:** grammar?
460
+ ``` antlr
461
+ expr_stmt : expr ';' ;
462
+ ```
467
463
468
464
## Expressions
469
465
470
- ** FIXME:** grammar?
466
+ ``` antlr
467
+ expr : literal | path | tuple_expr | unit_expr | struct_expr
468
+ | block_expr | method_call_expr | field_expr | array_expr
469
+ | idx_expr | range_expr | unop_expr | binop_expr
470
+ | paren_expr | call_expr | lambda_expr | while_expr
471
+ | loop_expr | break_expr | continue_expr | for_expr
472
+ | if_expr | match_expr | if_let_expr | while_let_expr
473
+ | return_expr ;
474
+ ```
471
475
472
476
#### Lvalues, rvalues and temporaries
473
477
@@ -479,19 +483,23 @@ init : [ '=' ] expr ;
479
483
480
484
### Literal expressions
481
485
482
- ** FIXME: ** grammar?
486
+ See [ Literals ] ( #literals ) .
483
487
484
488
### Path expressions
485
489
486
- ** FIXME: ** grammar?
490
+ See [ Paths ] ( #paths ) .
487
491
488
492
### Tuple expressions
489
493
490
- ** FIXME:** grammar?
494
+ ``` antlr
495
+ tuple_expr : '(' [ expr [ ',' expr ] * | expr ',' ] ? ')' ;
496
+ ```
491
497
492
498
### Unit expressions
493
499
494
- ** FIXME:** grammar?
500
+ ``` antlr
501
+ unit_expr : "()" ;
502
+ ```
495
503
496
504
### Structure expressions
497
505
@@ -507,8 +515,7 @@ struct_expr : expr_path '{' ident ':' expr
507
515
### Block expressions
508
516
509
517
``` antlr
510
- block_expr : '{' [ view_item ] *
511
- [ stmt ';' | item ] *
518
+ block_expr : '{' [ stmt ';' | item ] *
512
519
[ expr ] '}' ;
513
520
```
514
521
@@ -529,7 +536,7 @@ field_expr : expr '.' ident ;
529
536
``` antlr
530
537
array_expr : '[' "mut" ? array_elems? ']' ;
531
538
532
- array_elems : [expr [',' expr]*] | [expr ',' ".." expr] ;
539
+ array_elems : [expr [',' expr]*] | [expr ';' expr] ;
533
540
```
534
541
535
542
### Index expressions
@@ -549,65 +556,60 @@ range_expr : expr ".." expr |
549
556
550
557
### Unary operator expressions
551
558
552
- ** FIXME:** grammar?
559
+ ``` antlr
560
+ unop_expr : unop expr ;
561
+ unop : '-' | '*' | '!' ;
562
+ ```
553
563
554
564
### Binary operator expressions
555
565
556
566
``` antlr
557
- binop_expr : expr binop expr ;
567
+ binop_expr : expr binop expr | type_cast_expr
568
+ | assignment_expr | compound_assignment_expr ;
569
+ binop : arith_op | bitwise_op | lazy_bool_op | comp_op
558
570
```
559
571
560
572
#### Arithmetic operators
561
573
562
- ** FIXME:** grammar?
574
+ ``` antlr
575
+ arith_op : '+' | '-' | '*' | '/' | '%' ;
576
+ ```
563
577
564
578
#### Bitwise operators
565
579
566
- ** FIXME:** grammar?
580
+ ``` antlr
581
+ bitwise_op : '&' | '|' | '^' | "<<" | ">>" ;
582
+ ```
567
583
568
584
#### Lazy boolean operators
569
585
570
- ** FIXME:** grammar?
586
+ ``` antlr
587
+ lazy_bool_op : "&&" | "||" ;
588
+ ```
571
589
572
590
#### Comparison operators
573
591
574
- ** FIXME:** grammar?
592
+ ``` antlr
593
+ comp_op : "==" | "!=" | '<' | '>' | "<=" | ">=" ;
594
+ ```
575
595
576
596
#### Type cast expressions
577
597
578
- ** FIXME:** grammar?
598
+ ``` antlr
599
+ type_cast_expr : value "as" type ;
600
+ ```
579
601
580
602
#### Assignment expressions
581
603
582
- ** FIXME:** grammar?
604
+ ``` antlr
605
+ assignment_expr : expr '=' expr ;
606
+ ```
583
607
584
608
#### Compound assignment expressions
585
609
586
- ** FIXME:** grammar?
587
-
588
- #### Operator precedence
589
-
590
- The precedence of Rust binary operators is ordered as follows, going from
591
- strong to weak:
592
-
593
- ``` text
594
- * / %
595
- as
596
- + -
597
- << >>
598
- &
599
- ^
600
- |
601
- < > <= >=
602
- == !=
603
- &&
604
- ||
605
- =
606
- ```
607
-
608
- Operators at the same precedence level are evaluated left-to-right. [ Unary
609
- operators] ( #unary-operator-expressions ) have the same precedence level and it
610
- is stronger than any of the binary operators'.
610
+ ``` antlr
611
+ compound_assignment_expr : expr [ arith_op | bitwise_op ] '=' expr ;
612
+ ```
611
613
612
614
### Grouped expressions
613
615
0 commit comments