Skip to content

Commit 54c50dd

Browse files
committed
Rollup merge of #25297 - carols10cents:grammar-todos, r=steveklabnik
Hiiii, I've got another chunk of updates to the grammar documentation! ⭐ 🌟 🌠 Chipping away at #22445, still have some more to go. I'm learning so much!!!
2 parents 40bb7fc + 218d38f commit 54c50dd

File tree

1 file changed

+68
-66
lines changed

1 file changed

+68
-66
lines changed

src/doc/grammar.md

+68-66
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ The two values of the boolean type are written `true` and `false`.
253253
### Symbols
254254

255255
```antlr
256-
symbol : "::" "->"
256+
symbol : "::" | "->"
257257
| '#' | '[' | ']' | '(' | ')' | '{' | '}'
258258
| ',' | ';' ;
259259
```
@@ -304,7 +304,7 @@ transcriber : '(' transcriber * ')' | '[' transcriber * ']'
304304
## Items
305305

306306
```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
308308
| const_item | static_item | trait_item | impl_item | extern_block ;
309309
```
310310

@@ -322,7 +322,7 @@ mod : [ view_item | item ] * ;
322322
#### View items
323323

324324
```antlr
325-
view_item : extern_crate_decl | use_decl ;
325+
view_item : extern_crate_decl | use_decl ';' ;
326326
```
327327

328328
##### Extern crate declarations
@@ -335,14 +335,14 @@ crate_name: ident | ( ident "as" ident )
335335
##### Use declarations
336336

337337
```antlr
338-
use_decl : "pub" ? "use" [ path "as" ident
339-
| path_glob ] ;
338+
use_decl : vis ? "use" [ path "as" ident
339+
| path_glob ] ;
340340
341341
path_glob : ident [ "::" [ path_glob
342342
| '*' ] ] ?
343343
| '{' path_item [ ',' path_item ] * '}' ;
344344
345-
path_item : ident | "mod" ;
345+
path_item : ident | "self" ;
346346
```
347347

348348
### Functions
@@ -414,16 +414,17 @@ extern_block : [ foreign_fn ] * ;
414414

415415
## Visibility and Privacy
416416

417-
**FIXME:** grammar?
418-
417+
```antlr
418+
vis : "pub" ;
419+
```
419420
### Re-exporting and Visibility
420421

421-
**FIXME:** grammar?
422+
See [Use declarations](#use-declarations).
422423

423424
## Attributes
424425

425426
```antlr
426-
attribute : "#!" ? '[' meta_item ']' ;
427+
attribute : '#' '!' ? '[' meta_item ']' ;
427428
meta_item : ident [ '=' literal
428429
| '(' meta_seq ')' ] ? ;
429430
meta_seq : meta_item [ ',' meta_seq ] ? ;
@@ -433,26 +434,19 @@ meta_seq : meta_item [ ',' meta_seq ] ? ;
433434

434435
## Statements
435436

436-
**FIXME:** grammar?
437+
```antlr
438+
stmt : decl_stmt | expr_stmt ;
439+
```
437440

438441
### Declaration statements
439442

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+
```
445446

446447
#### Item declarations
447448

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 — a
452-
function, enumeration, structure, type, static, trait, implementation or module
453-
— 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).
456450

457451
#### Variable declarations
458452

@@ -463,11 +457,21 @@ init : [ '=' ] expr ;
463457

464458
### Expression statements
465459

466-
**FIXME:** grammar?
460+
```antlr
461+
expr_stmt : expr ';' ;
462+
```
467463

468464
## Expressions
469465

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+
```
471475

472476
#### Lvalues, rvalues and temporaries
473477

@@ -479,19 +483,23 @@ init : [ '=' ] expr ;
479483

480484
### Literal expressions
481485

482-
**FIXME:** grammar?
486+
See [Literals](#literals).
483487

484488
### Path expressions
485489

486-
**FIXME:** grammar?
490+
See [Paths](#paths).
487491

488492
### Tuple expressions
489493

490-
**FIXME:** grammar?
494+
```antlr
495+
tuple_expr : '(' [ expr [ ',' expr ] * | expr ',' ] ? ')' ;
496+
```
491497

492498
### Unit expressions
493499

494-
**FIXME:** grammar?
500+
```antlr
501+
unit_expr : "()" ;
502+
```
495503

496504
### Structure expressions
497505

@@ -507,8 +515,7 @@ struct_expr : expr_path '{' ident ':' expr
507515
### Block expressions
508516

509517
```antlr
510-
block_expr : '{' [ view_item ] *
511-
[ stmt ';' | item ] *
518+
block_expr : '{' [ stmt ';' | item ] *
512519
[ expr ] '}' ;
513520
```
514521

@@ -529,7 +536,7 @@ field_expr : expr '.' ident ;
529536
```antlr
530537
array_expr : '[' "mut" ? array_elems? ']' ;
531538
532-
array_elems : [expr [',' expr]*] | [expr ',' ".." expr] ;
539+
array_elems : [expr [',' expr]*] | [expr ';' expr] ;
533540
```
534541

535542
### Index expressions
@@ -549,65 +556,60 @@ range_expr : expr ".." expr |
549556

550557
### Unary operator expressions
551558

552-
**FIXME:** grammar?
559+
```antlr
560+
unop_expr : unop expr ;
561+
unop : '-' | '*' | '!' ;
562+
```
553563

554564
### Binary operator expressions
555565

556566
```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
558570
```
559571

560572
#### Arithmetic operators
561573

562-
**FIXME:** grammar?
574+
```antlr
575+
arith_op : '+' | '-' | '*' | '/' | '%' ;
576+
```
563577

564578
#### Bitwise operators
565579

566-
**FIXME:** grammar?
580+
```antlr
581+
bitwise_op : '&' | '|' | '^' | "<<" | ">>" ;
582+
```
567583

568584
#### Lazy boolean operators
569585

570-
**FIXME:** grammar?
586+
```antlr
587+
lazy_bool_op : "&&" | "||" ;
588+
```
571589

572590
#### Comparison operators
573591

574-
**FIXME:** grammar?
592+
```antlr
593+
comp_op : "==" | "!=" | '<' | '>' | "<=" | ">=" ;
594+
```
575595

576596
#### Type cast expressions
577597

578-
**FIXME:** grammar?
598+
```antlr
599+
type_cast_expr : value "as" type ;
600+
```
579601

580602
#### Assignment expressions
581603

582-
**FIXME:** grammar?
604+
```antlr
605+
assignment_expr : expr '=' expr ;
606+
```
583607

584608
#### Compound assignment expressions
585609

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+
```
611613

612614
### Grouped expressions
613615

0 commit comments

Comments
 (0)