From 11e905a2d745b429ed3951afe0d6b4e85e1288aa Mon Sep 17 00:00:00 2001 From: Dmitrii Naumenko Date: Tue, 26 Jan 2021 14:43:26 +0300 Subject: [PATCH 1/3] syntax.md: support multiple if-guards on same line Consider the example: ```scala for { x <- 1 to 5 if true; if true; if true } yield x ``` Note, that multiple if guards start from a new line and are not separated with a semicolon or a new line. This code is compiled ok in Scala 3 and is a valid code according to Scala 2 syntax reference: (though looks like there is a bug in implementation https://github.com/scala/bug/issues/12323) But it's not supported according to the Scala 3 syntax reference. related issues: https://github.com/scala/bug/issues/12323 https://youtrack.jetbrains.com/issue/SCL-13220 --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 2 +- docs/docs/internals/syntax.md | 4 ++-- docs/docs/reference/syntax.md | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 21727c7ec2be..83d60b398d8a 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -2459,7 +2459,7 @@ object Parsers { else Nil /** Enumerator ::= Generator - * | Guard + * | Guard {Guard} * | Pattern1 `=' Expr */ def enumerator(): Tree = diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 670d46ff0568..74b5fc274241 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -269,9 +269,9 @@ ForExpr ::= ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerat | ‘for’ Enumerators (‘do’ Expr | ‘yield’ Expr) ForDo(enums, expr) Enumerators ::= Generator {semi Enumerator | Guard} Enumerator ::= Generator - | Guard + | Guard {Guard} | Pattern1 ‘=’ Expr GenAlias(pat, expr) -Generator ::= [‘case’] Pattern1 ‘<-’ Expr GenFrom(pat, expr) +Generator ::= [‘case’] Pattern1 ‘<-’ Expr GenFrom(pat, expr) Guard ::= ‘if’ PostfixExpr CaseClauses ::= CaseClause { CaseClause } Match(EmptyTree, cases) diff --git a/docs/docs/reference/syntax.md b/docs/docs/reference/syntax.md index b2de66272ddf..a2653d26bd19 100644 --- a/docs/docs/reference/syntax.md +++ b/docs/docs/reference/syntax.md @@ -264,9 +264,9 @@ ForExpr ::= ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerat | ‘for’ Enumerators (‘do’ Expr | ‘yield’ Expr) Enumerators ::= Generator {semi Enumerator | Guard} Enumerator ::= Generator - | Guard - | Pattern1 ‘=’ Expr -Generator ::= [‘case’] Pattern1 ‘<-’ Expr + | Guard {Guard} + | Pattern1 ‘=’ Expr GenAlias(pat, expr) +Generator ::= [‘case’] Pattern1 ‘<-’ Expr GenFrom(pat, expr) Guard ::= ‘if’ PostfixExpr CaseClauses ::= CaseClause { CaseClause } From 3409c47d0e2fe1a8683d2ceb6d973a86b5bdf1bc Mon Sep 17 00:00:00 2001 From: Dmitrii Naumenko Date: Thu, 15 Jul 2021 14:17:33 +0300 Subject: [PATCH 2/3] Update docs/docs/reference/syntax.md Co-authored-by: Jamie Thompson --- docs/docs/reference/syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/reference/syntax.md b/docs/docs/reference/syntax.md index a2653d26bd19..11ad6b1d3981 100644 --- a/docs/docs/reference/syntax.md +++ b/docs/docs/reference/syntax.md @@ -265,7 +265,7 @@ ForExpr ::= ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerat Enumerators ::= Generator {semi Enumerator | Guard} Enumerator ::= Generator | Guard {Guard} - | Pattern1 ‘=’ Expr GenAlias(pat, expr) + | Pattern1 ‘=’ Expr Generator ::= [‘case’] Pattern1 ‘<-’ Expr GenFrom(pat, expr) Guard ::= ‘if’ PostfixExpr From 294351a0e4837a04391066e44268d075db2eed82 Mon Sep 17 00:00:00 2001 From: Dmitrii Naumenko Date: Thu, 15 Jul 2021 14:17:40 +0300 Subject: [PATCH 3/3] Update docs/docs/reference/syntax.md Co-authored-by: Jamie Thompson --- docs/docs/reference/syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/reference/syntax.md b/docs/docs/reference/syntax.md index 11ad6b1d3981..ff87b3d61d57 100644 --- a/docs/docs/reference/syntax.md +++ b/docs/docs/reference/syntax.md @@ -266,7 +266,7 @@ Enumerators ::= Generator {semi Enumerator | Guard} Enumerator ::= Generator | Guard {Guard} | Pattern1 ‘=’ Expr -Generator ::= [‘case’] Pattern1 ‘<-’ Expr GenFrom(pat, expr) +Generator ::= [‘case’] Pattern1 ‘<-’ Expr Guard ::= ‘if’ PostfixExpr CaseClauses ::= CaseClause { CaseClause }