@@ -74,6 +74,9 @@ object Parsers {
7474 if source.isSelfContained then new ScriptParser (source)
7575 else new Parser (source)
7676
77+ private val InCase : Region => Region = Scanners .InCase
78+ private val InCond : Region => Region = Scanners .InBraces
79+
7780 abstract class ParserCommon (val source : SourceFile )(implicit ctx : Context ) {
7881
7982 val in : ScannerCommon
@@ -611,10 +614,10 @@ object Parsers {
611614
612615 def commaSeparated [T ](part : () => T ): List [T ] = tokenSeparated(COMMA , part)
613616
614- def inSepRegion [T ](opening : Token , closing : Token )(op : => T ): T = {
615- in.adjustSepRegions(opening)
616- try op finally in.adjustSepRegions(closing )
617- }
617+ def inSepRegion [T ](f : Region => Region )(op : => T ): T =
618+ val cur = in.currentRegion
619+ in.currentRegion = f(cur )
620+ try op finally in.currentRegion = cur
618621
619622 /** Parse `body` while checking (under -noindent) that a `{` is not missing before it.
620623 * This is done as follows:
@@ -1785,7 +1788,7 @@ object Parsers {
17851788 var t : Tree = atSpan(in.offset) { Parens (inParens(exprInParens())) }
17861789 val enclosedInParens = ! toBeContinued(altToken)
17871790 if ! enclosedInParens then
1788- t = inSepRegion(LBRACE , RBRACE ) {
1791+ t = inSepRegion(InCond ) {
17891792 expr1Rest(postfixExprRest(simpleExprRest(t)), Location .ElseWhere )
17901793 }
17911794 if in.token == altToken then
@@ -1803,7 +1806,7 @@ object Parsers {
18031806 if in.isNestedStart then
18041807 try expr() finally newLinesOpt()
18051808 else
1806- inSepRegion(LBRACE , RBRACE )(expr())
1809+ inSepRegion(InCond )(expr())
18071810 if rewriteToOldSyntax(t.span.startPos) then
18081811 revertToParens(t)
18091812 if altToken == THEN && in.isNewLine then
@@ -2470,7 +2473,7 @@ object Parsers {
24702473 if (in.token == INDENT )
24712474 inBracesOrIndented(enumerators())
24722475 else {
2473- val ts = inSepRegion(LBRACE , RBRACE )(enumerators())
2476+ val ts = inSepRegion(InCond )(enumerators())
24742477 if (rewriteToOldSyntax(Span (start)) && ts.nonEmpty)
24752478 if (ts.head.sourcePos.startLine != ts.last.sourcePos.startLine) {
24762479 patch(source, Span (forEnd), " {" )
@@ -2514,7 +2517,7 @@ object Parsers {
25142517 * ExprCaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Expr
25152518 */
25162519 def caseClause (exprOnly : Boolean = false ): CaseDef = atSpan(in.offset) {
2517- val (pat, grd) = inSepRegion(LPAREN , RPAREN ) {
2520+ val (pat, grd) = inSepRegion(InCase ) {
25182521 accept(CASE )
25192522 (pattern(), guard())
25202523 }
@@ -2526,7 +2529,7 @@ object Parsers {
25262529 /** TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [nl]
25272530 */
25282531 def typeCaseClause (): CaseDef = atSpan(in.offset) {
2529- val pat = inSepRegion(LPAREN , RPAREN ) {
2532+ val pat = inSepRegion(InCase ) {
25302533 accept(CASE )
25312534 infixType()
25322535 }
0 commit comments