@@ -74,6 +74,9 @@ object Parsers {
74
74
if source.isSelfContained then new ScriptParser (source)
75
75
else new Parser (source)
76
76
77
+ private val InCase : Region => Region = Scanners .InCase
78
+ private val InCond : Region => Region = Scanners .InBraces
79
+
77
80
abstract class ParserCommon (val source : SourceFile )(implicit ctx : Context ) {
78
81
79
82
val in : ScannerCommon
@@ -611,10 +614,10 @@ object Parsers {
611
614
612
615
def commaSeparated [T ](part : () => T ): List [T ] = tokenSeparated(COMMA , part)
613
616
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
618
621
619
622
/** Parse `body` while checking (under -noindent) that a `{` is not missing before it.
620
623
* This is done as follows:
@@ -1785,7 +1788,7 @@ object Parsers {
1785
1788
var t : Tree = atSpan(in.offset) { Parens (inParens(exprInParens())) }
1786
1789
val enclosedInParens = ! toBeContinued(altToken)
1787
1790
if ! enclosedInParens then
1788
- t = inSepRegion(LBRACE , RBRACE ) {
1791
+ t = inSepRegion(InCond ) {
1789
1792
expr1Rest(postfixExprRest(simpleExprRest(t)), Location .ElseWhere )
1790
1793
}
1791
1794
if in.token == altToken then
@@ -1803,7 +1806,7 @@ object Parsers {
1803
1806
if in.isNestedStart then
1804
1807
try expr() finally newLinesOpt()
1805
1808
else
1806
- inSepRegion(LBRACE , RBRACE )(expr())
1809
+ inSepRegion(InCond )(expr())
1807
1810
if rewriteToOldSyntax(t.span.startPos) then
1808
1811
revertToParens(t)
1809
1812
if altToken == THEN && in.isNewLine then
@@ -2470,7 +2473,7 @@ object Parsers {
2470
2473
if (in.token == INDENT )
2471
2474
inBracesOrIndented(enumerators())
2472
2475
else {
2473
- val ts = inSepRegion(LBRACE , RBRACE )(enumerators())
2476
+ val ts = inSepRegion(InCond )(enumerators())
2474
2477
if (rewriteToOldSyntax(Span (start)) && ts.nonEmpty)
2475
2478
if (ts.head.sourcePos.startLine != ts.last.sourcePos.startLine) {
2476
2479
patch(source, Span (forEnd), " {" )
@@ -2514,7 +2517,7 @@ object Parsers {
2514
2517
* ExprCaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Expr
2515
2518
*/
2516
2519
def caseClause (exprOnly : Boolean = false ): CaseDef = atSpan(in.offset) {
2517
- val (pat, grd) = inSepRegion(LPAREN , RPAREN ) {
2520
+ val (pat, grd) = inSepRegion(InCase ) {
2518
2521
accept(CASE )
2519
2522
(pattern(), guard())
2520
2523
}
@@ -2526,7 +2529,7 @@ object Parsers {
2526
2529
/** TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [nl]
2527
2530
*/
2528
2531
def typeCaseClause (): CaseDef = atSpan(in.offset) {
2529
- val pat = inSepRegion(LPAREN , RPAREN ) {
2532
+ val pat = inSepRegion(InCase ) {
2530
2533
accept(CASE )
2531
2534
infixType()
2532
2535
}
0 commit comments