From 09323d781d2658dcfbe693d44f46ed06565f8524 Mon Sep 17 00:00:00 2001 From: Hazel OHearn Date: Tue, 8 Jun 2021 13:01:01 -0300 Subject: [PATCH 1/5] Make explicit reference to scrutinee expression in grammar snippet --- src/expressions/match-expr.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/expressions/match-expr.md b/src/expressions/match-expr.md index 53455fa9a..3a0765eb3 100644 --- a/src/expressions/match-expr.md +++ b/src/expressions/match-expr.md @@ -2,11 +2,14 @@ > **Syntax**\ > _MatchExpression_ :\ ->    `match` [_Expression_]_except struct expression_ `{`\ +>    `match` Scrutinee `{`\ >       [_InnerAttribute_]\*\ >       _MatchArms_?\ >    `}` > +>_Scrutinee_ :\ +>    [_Expression_]_except struct expression_ +> > _MatchArms_ :\ >    ( _MatchArm_ `=>` > ( [_ExpressionWithoutBlock_][_Expression_] `,` From 08a71cd9408694a66ce9f26e3b6de0334a5a9dab Mon Sep 17 00:00:00 2001 From: Hazel OHearn Date: Mon, 14 Jun 2021 13:18:26 -0300 Subject: [PATCH 2/5] Update if-let to use term Scrutinee explicitly in grammar snippet --- src/expressions/if-expr.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/expressions/if-expr.md b/src/expressions/if-expr.md index 87b088f78..bbabd9145 100644 --- a/src/expressions/if-expr.md +++ b/src/expressions/if-expr.md @@ -41,12 +41,15 @@ assert_eq!(y, "Bigger"); > **Syntax**\ > _IfLetExpression_ :\ ->    `if` `let` [_Pattern_] `=` [_Expression_]_except struct or lazy boolean operator expression_ +>    `if` `let` [_Pattern_] `=` Scrutinee > [_BlockExpression_]\ >    (`else` ( > [_BlockExpression_] > | _IfExpression_ > | _IfLetExpression_ ) )\? +> +> _Scrutinee_: +>    [_Expression_]_except struct or lazy boolean operator expression_ An `if let` expression is semantically similar to an `if` expression but in place of a condition operand it expects the keyword `let` followed by a pattern, an `=` and a [scrutinee] operand. If the value of the scrutinee matches the pattern, the corresponding block will execute. From c817f3bad8fcc42e816560385808353f74f52a40 Mon Sep 17 00:00:00 2001 From: Hazel OHearn Date: Mon, 14 Jun 2021 13:20:29 -0300 Subject: [PATCH 3/5] Update while-let to use term Scrutinee explicitly in grammar snippet --- src/expressions/loop-expr.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/expressions/loop-expr.md b/src/expressions/loop-expr.md index 8c9ad2802..87875f1ec 100644 --- a/src/expressions/loop-expr.md +++ b/src/expressions/loop-expr.md @@ -62,8 +62,12 @@ while i < 10 { > **Syntax**\ > [_PredicatePatternLoopExpression_] :\ ->    `while` `let` [_Pattern_] `=` [_Expression_]_except struct or lazy boolean operator expression_ +>    `while` `let` [_Pattern_] `=` Scrutinee > [_BlockExpression_] +> +> _Scrutinee_: +>    [_Expression_]_except struct or lazy boolean operator expression_ + A `while let` loop is semantically similar to a `while` loop but in place of a condition expression it expects the keyword `let` followed by a pattern, an `=`, a [scrutinee] expression and a block expression. If the value of the scrutinee matches the pattern, the loop body block executes then control returns to the pattern matching statement. From 0e7115d32fec1a9f11208e0353457f528e36e0e8 Mon Sep 17 00:00:00 2001 From: Hazel OHearn Date: Mon, 14 Jun 2021 13:27:35 -0300 Subject: [PATCH 4/5] Fixed slight syntax inconsistancies --- src/expressions/if-expr.md | 4 ++-- src/expressions/loop-expr.md | 4 ++-- src/expressions/match-expr.md | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/expressions/if-expr.md b/src/expressions/if-expr.md index bbabd9145..6dcad455c 100644 --- a/src/expressions/if-expr.md +++ b/src/expressions/if-expr.md @@ -41,14 +41,14 @@ assert_eq!(y, "Bigger"); > **Syntax**\ > _IfLetExpression_ :\ ->    `if` `let` [_Pattern_] `=` Scrutinee +>    `if` `let` [_Pattern_] `=` _Scrutinee_ > [_BlockExpression_]\ >    (`else` ( > [_BlockExpression_] > | _IfExpression_ > | _IfLetExpression_ ) )\? > -> _Scrutinee_: +> _Scrutinee_:\ >    [_Expression_]_except struct or lazy boolean operator expression_ An `if let` expression is semantically similar to an `if` expression but in place of a condition operand it expects the keyword `let` followed by a pattern, an `=` and a [scrutinee] operand. diff --git a/src/expressions/loop-expr.md b/src/expressions/loop-expr.md index 87875f1ec..a8da80ca3 100644 --- a/src/expressions/loop-expr.md +++ b/src/expressions/loop-expr.md @@ -62,10 +62,10 @@ while i < 10 { > **Syntax**\ > [_PredicatePatternLoopExpression_] :\ ->    `while` `let` [_Pattern_] `=` Scrutinee +>    `while` `let` [_Pattern_] `=` _Scrutinee_ > [_BlockExpression_] > -> _Scrutinee_: +> _Scrutinee_:\ >    [_Expression_]_except struct or lazy boolean operator expression_ diff --git a/src/expressions/match-expr.md b/src/expressions/match-expr.md index 3a0765eb3..febf60cc3 100644 --- a/src/expressions/match-expr.md +++ b/src/expressions/match-expr.md @@ -2,7 +2,7 @@ > **Syntax**\ > _MatchExpression_ :\ ->    `match` Scrutinee `{`\ +>    `match` _Scrutinee_ `{`\ >       [_InnerAttribute_]\*\ >       _MatchArms_?\ >    `}` From ac4ff0f3d5f980798b2463777d07e6060554c8c3 Mon Sep 17 00:00:00 2001 From: Hazel OHearn Date: Mon, 21 Jun 2021 15:59:22 -0300 Subject: [PATCH 5/5] Consolidate scrutinee expression grammar into match-expr.md, with links in if-expr and loop-expr --- src/expressions/if-expr.md | 6 ++---- src/expressions/loop-expr.md | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/expressions/if-expr.md b/src/expressions/if-expr.md index 6dcad455c..591437fc9 100644 --- a/src/expressions/if-expr.md +++ b/src/expressions/if-expr.md @@ -41,15 +41,12 @@ assert_eq!(y, "Bigger"); > **Syntax**\ > _IfLetExpression_ :\ ->    `if` `let` [_Pattern_] `=` _Scrutinee_ +>    `if` `let` [_Pattern_] `=` [_Scrutinee_]_except lazy boolean operator expression_ > [_BlockExpression_]\ >    (`else` ( > [_BlockExpression_] > | _IfExpression_ > | _IfLetExpression_ ) )\? -> -> _Scrutinee_:\ ->    [_Expression_]_except struct or lazy boolean operator expression_ An `if let` expression is semantically similar to an `if` expression but in place of a condition operand it expects the keyword `let` followed by a pattern, an `=` and a [scrutinee] operand. If the value of the scrutinee matches the pattern, the corresponding block will execute. @@ -151,6 +148,7 @@ if let PAT = ( EXPR || EXPR ) { .. } [_Expression_]: ../expressions.md [_LazyBooleanOperatorExpression_]: operator-expr.md#lazy-boolean-operators [_Pattern_]: ../patterns.md +[_Scrutinee_]: match-expr.md [_eRFCIfLetChain_]: https://github.com/rust-lang/rfcs/blob/master/text/2497-if-let-chains.md#rollout-plan-and-transitioning-to-rust-2018 [`match` expression]: match-expr.md [boolean type]: ../types/boolean.md diff --git a/src/expressions/loop-expr.md b/src/expressions/loop-expr.md index a8da80ca3..1ca62095c 100644 --- a/src/expressions/loop-expr.md +++ b/src/expressions/loop-expr.md @@ -62,11 +62,8 @@ while i < 10 { > **Syntax**\ > [_PredicatePatternLoopExpression_] :\ ->    `while` `let` [_Pattern_] `=` _Scrutinee_ +>    `while` `let` [_Pattern_] `=` [_Scrutinee_]_except lazy boolean operator expression_ > [_BlockExpression_] -> -> _Scrutinee_:\ ->    [_Expression_]_except struct or lazy boolean operator expression_ A `while let` loop is semantically similar to a `while` loop but in place of a condition expression it expects the keyword `let` followed by a pattern, an `=`, a [scrutinee] expression and a block expression. @@ -268,6 +265,7 @@ In the case a `loop` has an associated `break`, it is not considered diverging, [_BlockExpression_]: block-expr.md [_Expression_]: ../expressions.md [_Pattern_]: ../patterns.md +[_Scrutinee_]: match-expr.md [`match` expression]: match-expr.md [boolean]: ../types/boolean.md [scrutinee]: ../glossary.md#scrutinee