Skip to content

Commit 6c26763

Browse files
committed
Syntax polishing
Complete the description in `syntax.md` and align it with the parser.
1 parent 464b61c commit 6c26763

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,9 +1285,9 @@ object Parsers {
12851285

12861286
/** SimpleExpr ::= new Template
12871287
* | BlockExpr
1288-
* | ‘'’ BlockExpr
1289-
* | ‘'’ ‘(’ ExprsInParens ‘)’
1290-
* | ‘'’ ‘[’ Type ‘]’
1288+
* | ‘'{’ BlockExprContents ‘}’
1289+
* | ‘'(’ ExprsInParens ‘)’
1290+
* | ‘'[’ Type ‘]’
12911291
* | SimpleExpr1 [`_']
12921292
* SimpleExpr1 ::= literal
12931293
* | xmlLiteral
@@ -1467,7 +1467,8 @@ object Parsers {
14671467
}
14681468
else fn
14691469

1470-
/** BlockExpr ::= `{' (CaseClauses | Block) `}'
1470+
/** BlockExpr ::= `{' BlockExprContents `}'
1471+
* BlockExprContents ::= CaseClauses | Block
14711472
*/
14721473
def blockExpr(): Tree = atPos(in.offset) {
14731474
inDefScopeBraces {

docs/docs/internals/syntax.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ upper ::= ‘A’ | … | ‘Z’ | ‘\$’ | ‘_’ “… and U
2626
lower ::= ‘a’ | … | ‘z’ “… and Unicode category Ll”
2727
letter ::= upper | lower “… and Unicode categories Lo, Lt, Nl”
2828
digit ::= ‘0’ | … | ‘9’
29-
paren ::= ‘(’ | ‘)’ | ‘[’ | ‘]’ | ‘{’ | ‘}’
29+
paren ::= ‘(’ | ‘)’ | ‘[’ | ‘]’ | ‘{’ | ‘}’ | ‘'(’ | ‘'[’ | ‘'{’
3030
delim ::= ‘`’ | ‘'’ | ‘"’ | ‘.’ | ‘;’ | ‘,’
3131
opchar ::= “printableChar not matched by (whiteSpace | upper | lower |
3232
letter | digit | paren | delim | opchar | Unicode_Sm |
@@ -183,9 +183,9 @@ InfixExpr ::= PrefixExpr
183183
PrefixExpr ::= [‘-’ | ‘+’ | ‘~’ | ‘!’] SimpleExpr PrefixOp(expr, op)
184184
SimpleExpr ::= ‘new’ Template New(templ)
185185
| BlockExpr
186-
| ‘'’ BlockExpr
187-
| ‘'’ ‘(’ ExprsInParens ‘)’
188-
| ‘'’ ‘[’ Type ‘]’
186+
| ''{’ BlockExprContents ‘}’
187+
| ‘'(’ ExprsInParens ‘)’
188+
| ‘'[’ Type ‘]’
189189
| SimpleExpr1 [‘_’] PostfixOp(expr, _)
190190
SimpleExpr1 ::= Literal
191191
| Path
@@ -202,8 +202,8 @@ ParArgumentExprs ::= ‘(’ ExprsInParens ‘)’
202202
| ‘(’ [ExprsInParens] PostfixExpr ‘:’ ‘_’ ‘*’ ‘)’ exprs :+ Typed(expr, Ident(wildcardStar))
203203
ArgumentExprs ::= ParArgumentExprs
204204
| [nl] BlockExpr
205-
BlockExpr ::= ‘{’ CaseClauses ‘}’ Match(EmptyTree, cases)
206-
| ‘{’ Block ‘}’ block // starts at {
205+
BlockExpr ::= ‘{’ BlockExprContents ‘}’
206+
BlockExprContents ::= CaseClauses | Block
207207
Block ::= {BlockStat semi} [BlockResult] Block(stats, expr?)
208208
BlockStat ::= Import
209209
| {Annotation} [‘implicit’ | ‘lazy’] Def
@@ -220,8 +220,8 @@ Enumerator ::= Generator
220220
Generator ::= Pattern1 ‘<-’ Expr GenFrom(pat, expr)
221221
Guard ::= ‘if’ PostfixExpr
222222
223-
CaseClauses ::= CaseClause { CaseClause } CaseDef(pat, guard?, block) // block starts at =>
224-
CaseClause ::= ‘case’ (Pattern [Guard] ‘=>’ Block | INT)
223+
CaseClauses ::= CaseClause { CaseClause } Match(EmptyTree, cases)
224+
CaseClause ::= ‘case’ (Pattern [Guard] ‘=>’ Block | INT) CaseDef(pat, guard?, block) // block starts at =>
225225
226226
Pattern ::= Pattern1 { ‘|’ Pattern1 } Alternative(pats)
227227
Pattern1 ::= PatVar ‘:’ RefinedType Bind(name, Typed(Ident(wildcard), tpe))

0 commit comments

Comments
 (0)