@@ -606,7 +606,11 @@ object Parsers {
606
606
607
607
/** Parse indentation region `body` and rewrite it to be in braces instead */
608
608
def indentedToBraces [T ](body : => T ): T = {
609
- val indentWidth = in.indent.enclosing.width
609
+ val enclRegion = in.currentRegion.enclosing
610
+ def indentWidth = enclRegion match {
611
+ case Indented (w, _, _, _) => w
612
+ case _ => IndentWidth .Zero
613
+ }
610
614
val followsColon = testChar(in.lastOffset - 1 , ':' )
611
615
val startOpening =
612
616
if (followsColon)
@@ -701,10 +705,13 @@ object Parsers {
701
705
def bracesToIndented [T ](body : => T ): T = {
702
706
val colonRequired = possibleColonOffset == in.lastOffset
703
707
val (startOpening, endOpening) = startingElimRegion(colonRequired)
704
- val isOuterMost = in.sepRegions.isEmpty
708
+ val isOutermost = in.currentRegion.isOutermost
705
709
val savedPending = pendingPatches
706
- var canRewrite =
707
- in.sepRegions.forall(token => token == RBRACE || token == OUTDENT ) && // test (1)
710
+ def allBraces (r : Region ): Boolean = r match {
711
+ case r : InBraces => allBraces(r.enclosing)
712
+ case _ => r.isOutermost
713
+ }
714
+ var canRewrite = allBraces(in.currentRegion) && // test (1)
708
715
! testChars(in.lastOffset - 3 , " =>" ) // test(6)
709
716
val t = enclosed(LBRACE , {
710
717
canRewrite &= in.isAfterLineEnd // test (2)
@@ -726,7 +733,7 @@ object Parsers {
726
733
patch(source, Span (startClosing, endClosing), " " )
727
734
}
728
735
pendingPatches = applyPatch :: pendingPatches
729
- if (isOuterMost ) {
736
+ if (isOutermost ) {
730
737
pendingPatches.reverse.foreach(_())
731
738
pendingPatches = Nil
732
739
}
@@ -1168,7 +1175,7 @@ object Parsers {
1168
1175
}
1169
1176
1170
1177
def indentRegion [T ](tag : EndMarkerTag )(op : => T ): T = {
1171
- val iw = in.indent.width
1178
+ val iw = in.currentIndentWidth
1172
1179
val t = op
1173
1180
in.consumeEndMarker(tag, iw)
1174
1181
t
@@ -1282,6 +1289,7 @@ object Parsers {
1282
1289
}
1283
1290
else { accept(TLARROW ); typ() }
1284
1291
}
1292
+ else if (in.token == INDENT ) enclosed(INDENT , typ())
1285
1293
else infixType()
1286
1294
1287
1295
in.token match {
@@ -2152,8 +2160,15 @@ object Parsers {
2152
2160
def block (): Tree = {
2153
2161
val stats = blockStatSeq()
2154
2162
def isExpr (stat : Tree ) = ! (stat.isDef || stat.isInstanceOf [Import ])
2155
- if (stats.nonEmpty && isExpr(stats.last)) Block (stats.init, stats.last)
2156
- else Block (stats, EmptyTree )
2163
+ stats match {
2164
+ case (stat : Block ) :: Nil =>
2165
+ stat // A typical case where this happens is creating a block around a region
2166
+ // hat is already indented, e.g. something following a =>.
2167
+ case _ :: stats1 if isExpr(stats.last) =>
2168
+ Block (stats.init, stats.last)
2169
+ case _ =>
2170
+ Block (stats, EmptyTree )
2171
+ }
2157
2172
}
2158
2173
2159
2174
/** Guard ::= if PostfixExpr
@@ -2192,7 +2207,7 @@ object Parsers {
2192
2207
/** Generator ::= [‘case’] Pattern `<-' Expr
2193
2208
*/
2194
2209
def generator (): Tree = {
2195
- val casePat = if (in.token == CASE ) { in.skipCASE (); true } else false
2210
+ val casePat = if (in.token == CASE ) { in.nextToken (); true } else false
2196
2211
generatorRest(pattern1(), casePat)
2197
2212
}
2198
2213
@@ -2302,15 +2317,21 @@ object Parsers {
2302
2317
* ImplicitCaseClause ::= ‘case’ PatVar [Ascription] [Guard] `=>' Block
2303
2318
*/
2304
2319
val caseClause : () => CaseDef = () => atSpan(in.offset) {
2305
- accept(CASE )
2306
- CaseDef (pattern(), guard(), atSpan(accept(ARROW )) { block() })
2320
+ val (pat, grd) = inSepRegion(LPAREN , RPAREN ) {
2321
+ accept(CASE )
2322
+ (pattern(), guard())
2323
+ }
2324
+ CaseDef (pat, grd, atSpan(accept(ARROW )) { block() })
2307
2325
}
2308
2326
2309
2327
/** TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [nl]
2310
2328
*/
2311
2329
val typeCaseClause : () => CaseDef = () => atSpan(in.offset) {
2312
- accept(CASE )
2313
- CaseDef (infixType(), EmptyTree , atSpan(accept(ARROW )) {
2330
+ val pat = inSepRegion(LPAREN , RPAREN ) {
2331
+ accept(CASE )
2332
+ infixType()
2333
+ }
2334
+ CaseDef (pat, EmptyTree , atSpan(accept(ARROW )) {
2314
2335
val t = typ()
2315
2336
if (isStatSep) in.nextToken()
2316
2337
t
@@ -3246,7 +3267,7 @@ object Parsers {
3246
3267
*/
3247
3268
def enumCase (start : Offset , mods : Modifiers ): DefTree = {
3248
3269
val mods1 = mods | EnumCase
3249
- in.skipCASE( )
3270
+ accept( CASE )
3250
3271
3251
3272
atSpan(start, nameStart) {
3252
3273
val id = termIdent()
0 commit comments