@@ -1248,6 +1248,9 @@ object Parsers {
1248
1248
// note: next is defined here because current == NEWLINE
1249
1249
if (in.token == NEWLINE && in.next.token == token) in.nextToken()
1250
1250
1251
+ def newLinesOptWhenFollowedBy (token : Int ): Unit =
1252
+ if in.isNewLine && in.next.token == token then in.nextToken()
1253
+
1251
1254
def newLinesOptWhenFollowedBy (name : Name ): Unit =
1252
1255
if in.isNewLine && in.next.token == IDENTIFIER && in.next.name == name then
1253
1256
in.nextToken()
@@ -1742,8 +1745,7 @@ object Parsers {
1742
1745
* | [SimpleExpr `.'] id `=' Expr
1743
1746
* | SimpleExpr1 ArgumentExprs `=' Expr
1744
1747
* | Expr2
1745
- * | [‘inline’] Expr2 `match' `{' CaseClauses `}'
1746
- * | `given' `match' `{' ImplicitCaseClauses `}'
1748
+ * | [‘inline’] Expr2 `match' (`{' CaseClauses `}' | CaseClause)
1747
1749
* Bindings ::= `(' [Binding {`,' Binding}] `)'
1748
1750
* Binding ::= (id | `_') [`:' Type]
1749
1751
* Expr2 ::= PostfixExpr [Ascription]
@@ -1829,11 +1831,12 @@ object Parsers {
1829
1831
atSpan(in.skipToken()) {
1830
1832
val body = expr()
1831
1833
val (handler, handlerStart) =
1832
- if ( in.token == CATCH ) {
1834
+ if in.token == CATCH then
1833
1835
val span = in.offset
1834
1836
in.nextToken()
1835
- (subExpr(), span)
1836
- }
1837
+ (if in.token == CASE then Match (EmptyTree , caseClause() :: Nil )
1838
+ else subExpr(),
1839
+ span)
1837
1840
else (EmptyTree , - 1 )
1838
1841
1839
1842
handler match {
@@ -1955,20 +1958,20 @@ object Parsers {
1955
1958
mkIf(cond, thenp, elsep)
1956
1959
}
1957
1960
1958
- /** `match' { CaseClauses }
1961
+ /** `match' (`{' CaseClauses `}' | CaseClause)
1959
1962
*/
1960
1963
def matchExpr (t : Tree , start : Offset , mkMatch : (Tree , List [CaseDef ]) => Match ) =
1961
1964
indentRegion(MATCH ) {
1962
1965
atSpan(start, in.skipToken()) {
1963
- mkMatch(t, inBracesOrIndented(caseClauses( caseClause) ))
1966
+ mkMatch(t, casesExpr( caseClause))
1964
1967
}
1965
1968
}
1966
1969
1967
- /** `match' { TypeCaseClauses }
1970
+ /** `match' (`{' TypeCaseClauses `}' | TypeCaseClause)
1968
1971
*/
1969
1972
def matchType (t : Tree ): MatchTypeTree =
1970
1973
atSpan(t.span.start, accept(MATCH )) {
1971
- inBracesOrIndented( MatchTypeTree (EmptyTree , t, caseClauses (typeCaseClause) ))
1974
+ MatchTypeTree (EmptyTree , t, casesExpr (typeCaseClause))
1972
1975
}
1973
1976
1974
1977
/** FunParams ::= Bindings
@@ -2399,8 +2402,11 @@ object Parsers {
2399
2402
}
2400
2403
}
2401
2404
2405
+ def casesExpr (clause : () => CaseDef ): List [CaseDef ] =
2406
+ if in.token == CASE then clause() :: Nil
2407
+ else inBracesOrIndented(caseClauses(clause))
2408
+
2402
2409
/** CaseClauses ::= CaseClause {CaseClause}
2403
- * ImplicitCaseClauses ::= ImplicitCaseClause {ImplicitCaseClause}
2404
2410
* TypeCaseClauses ::= TypeCaseClause {TypeCaseClause}
2405
2411
*/
2406
2412
def caseClauses (clause : () => CaseDef ): List [CaseDef ] = {
@@ -2410,9 +2416,8 @@ object Parsers {
2410
2416
buf.toList
2411
2417
}
2412
2418
2413
- /** CaseClause ::= ‘case’ Pattern [Guard] `=>' Block
2414
- * ImplicitCaseClause ::= ‘case’ PatVar [Ascription] [Guard] `=>' Block
2415
- */
2419
+ /** CaseClause ::= ‘case’ Pattern [Guard] `=>' Block
2420
+ */
2416
2421
val caseClause : () => CaseDef = () => atSpan(in.offset) {
2417
2422
val (pat, grd) = inSepRegion(LPAREN , RPAREN ) {
2418
2423
accept(CASE )
@@ -2430,7 +2435,7 @@ object Parsers {
2430
2435
}
2431
2436
CaseDef (pat, EmptyTree , atSpan(accept(ARROW )) {
2432
2437
val t = typ()
2433
- if (isStatSep) in.nextToken( )
2438
+ newLinesOptWhenFollowedBy( CASE )
2434
2439
t
2435
2440
})
2436
2441
}
0 commit comments