@@ -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
@@ -616,6 +619,11 @@ object Parsers {
616
619
try op finally in.adjustSepRegions(closing)
617
620
}
618
621
622
+ def inSepRegion [T ](f : Region => Region )(op : => T ): T =
623
+ val cur = in.currentRegion
624
+ in.currentRegion = f(cur)
625
+ try op finally in.currentRegion = cur
626
+
619
627
/** Parse `body` while checking (under -noindent) that a `{` is not missing before it.
620
628
* This is done as follows:
621
629
* If the next token S is indented relative to the current region,
@@ -1785,7 +1793,7 @@ object Parsers {
1785
1793
var t : Tree = atSpan(in.offset) { Parens (inParens(exprInParens())) }
1786
1794
val enclosedInParens = ! toBeContinued(altToken)
1787
1795
if ! enclosedInParens then
1788
- t = inSepRegion(LBRACE , RBRACE ) {
1796
+ t = inSepRegion(InCond ) {
1789
1797
expr1Rest(postfixExprRest(simpleExprRest(t)), Location .ElseWhere )
1790
1798
}
1791
1799
if in.token == altToken then
@@ -1803,7 +1811,7 @@ object Parsers {
1803
1811
if in.isNestedStart then
1804
1812
try expr() finally newLinesOpt()
1805
1813
else
1806
- inSepRegion(LBRACE , RBRACE )(expr())
1814
+ inSepRegion(InCond )(expr())
1807
1815
if rewriteToOldSyntax(t.span.startPos) then
1808
1816
revertToParens(t)
1809
1817
if altToken == THEN && in.isNewLine then
@@ -2470,7 +2478,7 @@ object Parsers {
2470
2478
if (in.token == INDENT )
2471
2479
inBracesOrIndented(enumerators())
2472
2480
else {
2473
- val ts = inSepRegion(LBRACE , RBRACE )(enumerators())
2481
+ val ts = inSepRegion(InCond )(enumerators())
2474
2482
if (rewriteToOldSyntax(Span (start)) && ts.nonEmpty)
2475
2483
if (ts.head.sourcePos.startLine != ts.last.sourcePos.startLine) {
2476
2484
patch(source, Span (forEnd), " {" )
@@ -2514,7 +2522,7 @@ object Parsers {
2514
2522
* ExprCaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Expr
2515
2523
*/
2516
2524
def caseClause (exprOnly : Boolean = false ): CaseDef = atSpan(in.offset) {
2517
- val (pat, grd) = inSepRegion(LPAREN , RPAREN ) {
2525
+ val (pat, grd) = inSepRegion(InCase ) {
2518
2526
accept(CASE )
2519
2527
(pattern(), guard())
2520
2528
}
@@ -2526,7 +2534,7 @@ object Parsers {
2526
2534
/** TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [nl]
2527
2535
*/
2528
2536
def typeCaseClause (): CaseDef = atSpan(in.offset) {
2529
- val pat = inSepRegion(LPAREN , RPAREN ) {
2537
+ val pat = inSepRegion(InCase ) {
2530
2538
accept(CASE )
2531
2539
infixType()
2532
2540
}
0 commit comments