@@ -1296,7 +1296,7 @@ object Parsers {
1296
1296
1297
1297
def possibleTemplateStart (isNew : Boolean = false ): Unit =
1298
1298
in.observeColonEOL()
1299
- if in.token == COLONEOL || in.token == WITH then
1299
+ if in.token == COLONEOL then
1300
1300
if in.lookahead.isIdent(nme.end) then in.token = NEWLINE
1301
1301
else
1302
1302
in.nextToken()
@@ -2333,7 +2333,7 @@ object Parsers {
2333
2333
possibleTemplateStart()
2334
2334
val parents =
2335
2335
if in.isNestedStart then Nil
2336
- else constrApps(commaOK = false )
2336
+ else constrApps(exclude = COMMA )
2337
2337
colonAtEOLOpt()
2338
2338
possibleTemplateStart(isNew = true )
2339
2339
parents match {
@@ -3536,7 +3536,7 @@ object Parsers {
3536
3536
val parents =
3537
3537
if (in.token == EXTENDS ) {
3538
3538
in.nextToken()
3539
- constrApps(commaOK = true )
3539
+ constrApps()
3540
3540
}
3541
3541
else Nil
3542
3542
Template (constr, parents, Nil , EmptyValDef , Nil )
@@ -3670,16 +3670,16 @@ object Parsers {
3670
3670
3671
3671
/** ConstrApps ::= ConstrApp ({‘,’ ConstrApp} | {‘with’ ConstrApp})
3672
3672
*/
3673
- def constrApps (commaOK : Boolean ): List [Tree ] =
3673
+ def constrApps (exclude : Token = EMPTY ): List [Tree ] =
3674
3674
val t = constrApp()
3675
3675
val ts =
3676
- if in.token == WITH || commaOK && in.token == COMMA then
3676
+ val tok = in.token
3677
+ if (tok == WITH || tok == COMMA ) && tok != exclude then
3677
3678
in.nextToken()
3678
- constrApps(commaOK )
3679
+ constrApps(exclude = if tok == WITH then COMMA else WITH )
3679
3680
else Nil
3680
3681
t :: ts
3681
3682
3682
-
3683
3683
/** `{`with` ConstrApp} but no EOL allowed after `with`.
3684
3684
*/
3685
3685
def withConstrApps (): List [Tree ] =
@@ -3704,7 +3704,7 @@ object Parsers {
3704
3704
in.sourcePos())
3705
3705
Nil
3706
3706
}
3707
- else constrApps(commaOK = true )
3707
+ else constrApps()
3708
3708
}
3709
3709
else Nil
3710
3710
newLinesOptWhenFollowedBy(nme.derives )
@@ -3758,8 +3758,7 @@ object Parsers {
3758
3758
3759
3759
/** with Template, with EOL <indent> interpreted */
3760
3760
def withTemplate (constr : DefDef , parents : List [Tree ]): Template =
3761
- if in.token != WITH then syntaxError(em " `with` expected " )
3762
- possibleTemplateStart() // consumes a WITH token
3761
+ accept(WITH )
3763
3762
val (self, stats) = templateBody()
3764
3763
Template (constr, parents, Nil , self, stats)
3765
3764
.withSpan(Span (constr.span.orElse(parents.head.span).start, in.lastOffset))
0 commit comments