Skip to content

syntax.md: update syntax of for-expressions #11624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2509,9 +2509,9 @@ object Parsers {
GenFrom(pat, subExpr(), checkMode)
}

/** ForExpr ::= `for' (`(' Enumerators `)' | `{' Enumerators `}')
* {nl} [`yield'] Expr
* | `for' Enumerators (`do' Expr | `yield' Expr)
/** ForExpr ::= for’ ‘(’ Enumerators ‘)’ {nl} [‘do‘ | ‘yield’] Expr
* | ‘for’ ‘{’ Enumerators ‘}’ {nl} [‘do‘ | ‘yield] Expr
* | forEnumerators (‘do‘ | ‘yield’) Expr
*/
def forExpr(): Tree =
atSpan(in.skipToken()) {
Expand Down
7 changes: 4 additions & 3 deletions docs/docs/internals/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,10 @@ BlockStat ::= Import
| Expr1
| EndMarker

ForExpr ::= ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerators ‘}’) ForYield(enums, expr)
{nl} [‘yield’] Expr
| ‘for’ Enumerators (‘do’ Expr | ‘yield’ Expr) ForDo(enums, expr)
ForExpr ::= ‘for’ ‘(’ Enumerators0 ‘)’ {nl} [‘do‘ | ‘yield’] Expr ForYield(enums, expr) / ForDo(enums, expr)
| ‘for’ ‘{’ Enumerators0 ‘}’ {nl} [‘do‘ | ‘yield’] Expr
| ‘for’ Enumerators0 (‘do‘ | ‘yield’) Expr
Enumerators0 ::= {nl} Enumerators [semi]
Enumerators ::= Generator {semi Enumerator | Guard}
Enumerator ::= Generator
| Guard
Expand Down
6 changes: 4 additions & 2 deletions docs/docs/reference/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,10 @@ BlockStat ::= Import
| Expr1
| EndMarker

ForExpr ::= ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerators ‘}’) {nl} [‘yield’] Expr
| ‘for’ Enumerators (‘do’ Expr | ‘yield’ Expr)
ForExpr ::= ‘for’ ‘(’ Enumerators0 ‘)’ {nl} [‘do‘ | ‘yield’] Expr
| ‘for’ ‘{’ Enumerators0 ‘}’ {nl} [‘do‘ | ‘yield’] Expr
| ‘for’ Enumerators0 (‘do‘ | ‘yield’) Expr
Enumerators0 ::= {nl} Enumerators [semi]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No {nl} needs to be inserted here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enumerators themselves do not accept new line before them.

No {nl} needs to be inserted here.

Is it because it's kinda "obvious" that here can go an arbitrary amount of new lines?
For me, it's as obvious as {nl} after ) in for / if / while, still they contain {nl} in rules.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, nl means an newline token inserted by the lexer. But there is never a newline inserted in front of a do or yield.

Enumerators ::= Generator {semi Enumerator | Guard}
Enumerator ::= Generator
| Guard
Expand Down