Skip to content

Commit 20c0b33

Browse files
committed
Grammar: Statements.
Cleans up "Statement" definition. Adds "let" statement.
1 parent 5e296d2 commit 20c0b33

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

src/expressions.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
> **<sup>Syntax</sup>**\
44
> _Expression_ :\
5+
> &nbsp;&nbsp; &nbsp;&nbsp; _ExpressionWithoutBlock_\
6+
> &nbsp;&nbsp; | _ExpressionWithBlock_
7+
>
8+
> _ExpressionWithoutBlock_ :\
59
> &nbsp;&nbsp; &nbsp;&nbsp; [_LiteralExpression_]\
610
> &nbsp;&nbsp; | [_PathExpression_]\
7-
> &nbsp;&nbsp; | [_BlockExpression_]\
811
> &nbsp;&nbsp; | [_OperatorExpression_]\
912
> &nbsp;&nbsp; | [_GroupedExpression_]\
1013
> &nbsp;&nbsp; | [_ArrayExpression_]\
@@ -17,14 +20,18 @@
1720
> &nbsp;&nbsp; | [_MethodCallExpression_]\
1821
> &nbsp;&nbsp; | [_FieldExpression_]\
1922
> &nbsp;&nbsp; | [_ClosureExpression_]\
20-
> &nbsp;&nbsp; | [_LoopExpression_]\
2123
> &nbsp;&nbsp; | [_ContinueExpression_]\
2224
> &nbsp;&nbsp; | [_BreakExpression_]\
2325
> &nbsp;&nbsp; | [_RangeExpression_]\
26+
> &nbsp;&nbsp; | [_ReturnExpression_]
27+
>
28+
> _ExpressionWithBlock_ :\
29+
> &nbsp;&nbsp; &nbsp;&nbsp; [_BlockExpression_]\
30+
> &nbsp;&nbsp; | [_UnsafeBlockExpression_]\
31+
> &nbsp;&nbsp; | [_LoopExpression_]\
2432
> &nbsp;&nbsp; | [_IfExpression_]\
2533
> &nbsp;&nbsp; | [_IfLetExpression_]\
26-
> &nbsp;&nbsp; | [_MatchExpression_]\
27-
> &nbsp;&nbsp; | [_ReturnExpression_]
34+
> &nbsp;&nbsp; | [_MatchExpression_]
2835
2936
An expression may have two roles: it always produces a *value*, and it may have
3037
*effects* (otherwise known as "side effects"). An expression *evaluates to* a
@@ -341,3 +348,4 @@ exist in `core::ops` and `core::cmp` with the same names.
341348
[_StructExpression_]: expressions/struct-expr.html
342349
[_TupleExpression_]: expressions/tuple-expr.html
343350
[_TupleIndexingExpression_]: expressions/tuple-expr.html#tuple-indexing-expressions
351+
[_UnsafeBlockExpression_]: expressions/block-expr.html#unsafe-blocks

src/expressions/block-expr.md

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,11 @@
44
> _BlockExpression_ :\
55
> &nbsp;&nbsp; `{`\
66
> &nbsp;&nbsp; &nbsp;&nbsp; [_InnerAttribute_]<sup>\*</sup>\
7-
> &nbsp;&nbsp; &nbsp;&nbsp; _Statements_<sup>\*</sup>\
7+
> &nbsp;&nbsp; &nbsp;&nbsp; [_Statement_]<sup>\*</sup>\
88
> &nbsp;&nbsp; &nbsp;&nbsp; [_Expression_]<sup>?</sup>\
99
> &nbsp;&nbsp; `}`
10-
>
11-
> _Statements_ :\
12-
> &nbsp;&nbsp; ( `;`\
13-
> &nbsp;&nbsp; | [_ItemDeclaration_]\
14-
> &nbsp;&nbsp; | [_LetStatement_] ;\
15-
> &nbsp;&nbsp; | [_NonControlFlowExpressionStatement_][expression statement] ;\
16-
> &nbsp;&nbsp; | [_FlowControlExpressionStatement_][expression statement] ;<sup>?</sup>\
17-
> &nbsp;&nbsp; )<sup>\*</sup>
18-
19-
A *block expression*, or *block*, is a control flow expression and anonymouse
10+
11+
A *block expression*, or *block*, is a control flow expression and anonymous
2012
namespace scope for items and variable declarations. As a control flow
2113
expression, a block sequentially executes its component non-item declaration
2214
statements and then its final optional expression. As an anonymous namespace
@@ -60,7 +52,7 @@ assert_eq!(5, five);
6052
> expression of an expression statement, the expected type is `()` unless it
6153
> is followed immediately by a semicolon.
6254
63-
Blocks are always [value expressions] and evaluate the last expression in
55+
Blocks are always [value expressions] and evaluate the last expression in
6456
value expression context. This can be used to force moving a value if really
6557
needed. For example, the following example fails on the call to `consume_self`
6658
because the struct was moved out of `s` in the block expression.
@@ -126,9 +118,7 @@ fn is_unix_platform() -> bool {
126118
```
127119

128120
[_InnerAttribute_]: attributes.html
129-
[_ItemDeclaration_]: items.html
130-
[_LetStatement_]: statements.html#let-statements
131-
[expression statement]: statements.html#expression-statements
121+
[_Statement_]: statements.html
132122
[_Expression_]: expressions.html
133123
[expression]: expressions.html
134124
[statements]: statements.html

src/statements.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Statements
22

3+
> **<sup>Syntax</sup>**\
4+
> _Statement_ :\
5+
> &nbsp;&nbsp; &nbsp;&nbsp; `;`\
6+
> &nbsp;&nbsp; | [_Item_]\
7+
> &nbsp;&nbsp; | [_LetStatement_]\
8+
> &nbsp;&nbsp; | [_ExpressionWithoutBlock_][expression] `;`\
9+
> &nbsp;&nbsp; | [_ExpressionWithBlock_][expression]
10+
11+
312
A *statement* is a component of a [block], which is in turn a component of an
413
outer [expression] or [function].
514

@@ -42,6 +51,10 @@ fn outer() {
4251

4352
### `let` statements
4453

54+
> **<sup>Syntax</sup>**\
55+
> _LetStatement_ :\
56+
> &nbsp;&nbsp; `let` [_Pattern_] ( `:` [_Type_] )<sup>?</sup> (`=` [_Expression_] )<sup>?</sup> `;`
57+
4558
A *`let` statement* introduces a new set of [variables], given by a [pattern]. The
4659
pattern is followed optionally by a type annotation and then optionally by an
4760
initializer expression. When no type annotation is given, the compiler will
@@ -107,3 +120,8 @@ statement are [`cfg`], and [the lint check attributes].
107120
[`cfg`]: conditional-compilation.html
108121
[the lint check attributes]: attributes.html#lint-check-attributes
109122
[pattern]: patterns.html
123+
[_Expression_]: expressions.html
124+
[_Item_]: items.html
125+
[_LetStatement_]: #let-statements
126+
[_Pattern_]: patterns.html
127+
[_Type_]: types.html

0 commit comments

Comments
 (0)