From c8ccdbf6a2ffd8213365edbf76c5f2b957dc9f75 Mon Sep 17 00:00:00 2001 From: Alex Martini Date: Mon, 9 Oct 2023 17:28:45 -0700 Subject: [PATCH 1/6] In-out supports more than just simple variables. Co-authored-by: Sarah Canto <61300898+sarahnicoleboo@users.noreply.github.com> --- TSPL.docc/ReferenceManual/Expressions.md | 2 +- TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TSPL.docc/ReferenceManual/Expressions.md b/TSPL.docc/ReferenceManual/Expressions.md index ab58727b0..56a71a83e 100644 --- a/TSPL.docc/ReferenceManual/Expressions.md +++ b/TSPL.docc/ReferenceManual/Expressions.md @@ -61,7 +61,7 @@ as described in . > Grammar of an in-out expression: > -> *in-out-expression* → **`&`** *identifier* +> *in-out-expression* → **`&`** *expression* ### Try Operator diff --git a/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md b/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md index c177c3d3b..fcb90bafe 100644 --- a/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md +++ b/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md @@ -323,7 +323,7 @@ make the same change here also. > Grammar of an in-out expression: > -> *in-out-expression* → **`&`** *identifier* +> *in-out-expression* → **`&`** *expression* > Grammar of a try expression: > From 5f7abc99e4f088c66cca2801806402ed2d55ff5a Mon Sep 17 00:00:00 2001 From: Alex Martini Date: Tue, 10 Oct 2023 15:15:33 -0700 Subject: [PATCH 2/6] Narrow the rule to reduce overproduction. This grammar avoids productions like &x+y -- even though x+y is a valid expression, you can't use it this way in an in-out expression. However, it does still overproduce -- for example, a.b() is a valid postfix expression but &a.b() isn't a valid in-out expression. Co-authored-by: Joe Groff --- TSPL.docc/ReferenceManual/Expressions.md | 2 +- TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TSPL.docc/ReferenceManual/Expressions.md b/TSPL.docc/ReferenceManual/Expressions.md index 56a71a83e..2b9267568 100644 --- a/TSPL.docc/ReferenceManual/Expressions.md +++ b/TSPL.docc/ReferenceManual/Expressions.md @@ -61,7 +61,7 @@ as described in . > Grammar of an in-out expression: > -> *in-out-expression* → **`&`** *expression* +> *in-out-expression* → **`&`** *postfix-expression* ### Try Operator diff --git a/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md b/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md index fcb90bafe..fe8bdf56a 100644 --- a/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md +++ b/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md @@ -323,7 +323,7 @@ make the same change here also. > Grammar of an in-out expression: > -> *in-out-expression* → **`&`** *expression* +> *in-out-expression* → **`&`** *postfix-expression* > Grammar of a try expression: > From 3d0044bc790c99500cfd8a514e5039bd7b24fa5a Mon Sep 17 00:00:00 2001 From: Alex Martini Date: Wed, 11 Oct 2023 10:16:52 -0700 Subject: [PATCH 3/6] Generalize to allow parenthesized expression. Moving up one level in the grammar introduces additional overgeneration, but otherwise code like f(&(x)) doesn't match. --- TSPL.docc/ReferenceManual/Expressions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TSPL.docc/ReferenceManual/Expressions.md b/TSPL.docc/ReferenceManual/Expressions.md index 2b9267568..96b11b9e6 100644 --- a/TSPL.docc/ReferenceManual/Expressions.md +++ b/TSPL.docc/ReferenceManual/Expressions.md @@ -61,7 +61,7 @@ as described in . > Grammar of an in-out expression: > -> *in-out-expression* → **`&`** *postfix-expression* +> *in-out-expression* → **`&`** *primary-expression* ### Try Operator From 8f2387ddba4910f1b13039bd030204d3c5a3ccaf Mon Sep 17 00:00:00 2001 From: Alex Martini Date: Wed, 11 Oct 2023 10:40:13 -0700 Subject: [PATCH 4/6] Implement in-out with its own production rules. There isn't a clear point in the expression grammar where everything produced by that rule is allowed in an in-out expression, but nothing else, so we will always either over- or under-produce if we write in-out-expression in terms of existing productions. Combined rules from the parts of the grammar that are definitely supported to make these production rules, although this list might be incomplete: - The grammar for . is borrowed from explicit-member-expression - The grammar for [] is borrowed from subscript-expression - The grammar for () is adapted from parenthesized-expression --- TSPL.docc/ReferenceManual/Expressions.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/TSPL.docc/ReferenceManual/Expressions.md b/TSPL.docc/ReferenceManual/Expressions.md index 96b11b9e6..774e79acc 100644 --- a/TSPL.docc/ReferenceManual/Expressions.md +++ b/TSPL.docc/ReferenceManual/Expressions.md @@ -61,7 +61,12 @@ as described in . > Grammar of an in-out expression: > -> *in-out-expression* → **`&`** *primary-expression* +> *in-out-expression* → **`&`** *in-out-expression-tail* +> *in-out-expression-tail* → *in-out-expression-tail* **`.`** *decimal-digits* +> *in-out-expression-tail* → *in-out-expression-tail* **`.`** *identifier* +> *in-out-expression-tail* → *in-out-expression-tail* **`[`** *function-call-argument-list* **`]`** +> *in-out-expression-tail* → **`(`** *in-out-expression-tail* **`)`** +> *in-out-expression-tail* → *identifier* ### Try Operator From f9043ee8599eb26fecc971423acc42af5893058e Mon Sep 17 00:00:00 2001 From: Alex Martini Date: Thu, 12 Oct 2023 15:02:57 -0700 Subject: [PATCH 5/6] Limit grammar overproduction in prose. The previous grammar didn't include `self` or `.self` or implicit member expressions, as Rintaro Ishizaki noted on the PR. Duplicating those productions here, with modifications to prevent them from pulling in all of primary-expression or postfix-expression, would make this grammar a bit too long and unwieldy. --- TSPL.docc/ReferenceManual/Expressions.md | 16 ++++++++++------ TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/TSPL.docc/ReferenceManual/Expressions.md b/TSPL.docc/ReferenceManual/Expressions.md index 774e79acc..01d337fb2 100644 --- a/TSPL.docc/ReferenceManual/Expressions.md +++ b/TSPL.docc/ReferenceManual/Expressions.md @@ -51,6 +51,15 @@ as an in-out argument to a function call expression. &<#expression#> ``` +The _expression_ is a combination of the following kinds of expression: + +- An identifier or `self` +- Access to a member, including properties, tuple elements, and `.self` +- Access to an array subscript + +Member access can be explicit like `f(&x.y)` or implicit like `f(&.z)`. +The _expression_ can also include grouping parentheses. + For more information about in-out parameters and to see an example, see . @@ -61,12 +70,7 @@ as described in . > Grammar of an in-out expression: > -> *in-out-expression* → **`&`** *in-out-expression-tail* -> *in-out-expression-tail* → *in-out-expression-tail* **`.`** *decimal-digits* -> *in-out-expression-tail* → *in-out-expression-tail* **`.`** *identifier* -> *in-out-expression-tail* → *in-out-expression-tail* **`[`** *function-call-argument-list* **`]`** -> *in-out-expression-tail* → **`(`** *in-out-expression-tail* **`)`** -> *in-out-expression-tail* → *identifier* +> *in-out-expression* → **`&`** *primary-expression* ### Try Operator diff --git a/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md b/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md index fe8bdf56a..20ecde510 100644 --- a/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md +++ b/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md @@ -323,7 +323,7 @@ make the same change here also. > Grammar of an in-out expression: > -> *in-out-expression* → **`&`** *postfix-expression* +> *in-out-expression* → **`&`** *primary-expression* > Grammar of a try expression: > From 644e240d1ffb7f3927bfedb2dc6795ed066e51c9 Mon Sep 17 00:00:00 2001 From: Alex Martini Date: Thu, 2 Nov 2023 14:05:34 -0700 Subject: [PATCH 6/6] Fix underproduction like f(&x.y) in grammar. The grammar for postfix-expression produces this case, and includes primary-expression. This grammar also allows for production of parentheses because primary-expression produces parenthesized-expression. Co-authored-by: Sarah Canto <61300898+sarahnicoleboo@users.noreply.github.com> --- TSPL.docc/ReferenceManual/Expressions.md | 2 +- TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TSPL.docc/ReferenceManual/Expressions.md b/TSPL.docc/ReferenceManual/Expressions.md index 01d337fb2..3d0b08e31 100644 --- a/TSPL.docc/ReferenceManual/Expressions.md +++ b/TSPL.docc/ReferenceManual/Expressions.md @@ -70,7 +70,7 @@ as described in . > Grammar of an in-out expression: > -> *in-out-expression* → **`&`** *primary-expression* +> *in-out-expression* → **`&`** *postfix-expression* ### Try Operator diff --git a/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md b/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md index 20ecde510..fe8bdf56a 100644 --- a/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md +++ b/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md @@ -323,7 +323,7 @@ make the same change here also. > Grammar of an in-out expression: > -> *in-out-expression* → **`&`** *primary-expression* +> *in-out-expression* → **`&`** *postfix-expression* > Grammar of a try expression: >