@@ -3516,20 +3516,8 @@ object Parsers {
3516
3516
syntaxError(i " extension clause can only define methods " , stat.span)
3517
3517
}
3518
3518
3519
- def givenConstrApps (): List [Tree ] =
3520
- val t = constrApp()
3521
- if in.token == WITH then
3522
- in.observeWithEOL() // converts token to WITHEOL if at end of line
3523
- if in.token == WITH && in.lookahead.token != LBRACE then
3524
- in.nextToken()
3525
- t :: givenConstrApps()
3526
- else t :: Nil
3527
- else
3528
- t :: Nil
3529
-
3530
- /** GivenDef ::= [GivenSig] Type ‘=’ Expr
3531
- * | [GivenSig] ConstrApps [TemplateBody]
3532
- * GivenSig ::= [id] [DefTypeParamClause] {UsingParamClauses} ‘as’
3519
+ /** GivenDef ::= [GivenSig] (Type [‘=’ Expr] | StructuralInstance)
3520
+ * GivenSig ::= [id] [DefTypeParamClause] {UsingParamClauses} ‘:’
3533
3521
*/
3534
3522
def givenDef (start : Offset , mods : Modifiers , givenMod : Mod ) = atSpan(start, nameStart) {
3535
3523
var mods1 = addMod(mods, givenMod)
@@ -3550,7 +3538,7 @@ object Parsers {
3550
3538
if ! (name.isEmpty && noParams) then
3551
3539
if isIdent(nme.as) then in.nextToken()
3552
3540
else accept(COLON )
3553
- val parents = givenConstrApps ()
3541
+ val parents = constrApp() :: withConstrApps ()
3554
3542
val parentsIsType = parents.length == 1 && parents.head.isType
3555
3543
if in.token == EQUALS && parentsIsType then
3556
3544
accept(EQUALS )
@@ -3560,7 +3548,7 @@ object Parsers {
3560
3548
ValDef (name, parents.head, subExpr())
3561
3549
else
3562
3550
DefDef (name, tparams, vparamss, parents.head, subExpr())
3563
- else if newSyntax && in.token != WITH && in.token != WITHEOL && parentsIsType then
3551
+ else if newSyntax && in.token != WITH && in.token != WITHEOL && parentsIsType then
3564
3552
if name.isEmpty then
3565
3553
syntaxError(em " anonymous given cannot be abstract " )
3566
3554
DefDef (name, tparams, vparamss, parents.head, EmptyTree )
@@ -3571,10 +3559,7 @@ object Parsers {
3571
3559
val constr = makeConstructor(tparams1, vparamss1)
3572
3560
val templ =
3573
3561
if newSyntax || in.token == WITHEOL || in.token == WITH then
3574
- if in.token != WITHEOL then accept(WITH )
3575
- possibleTemplateStart()
3576
- val (self, stats) = templateBody()
3577
- Template (constr, parents, Nil , self, stats)
3562
+ withTemplate(constr, parents)
3578
3563
else
3579
3564
possibleTemplateStart()
3580
3565
templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil )
@@ -3652,6 +3637,18 @@ object Parsers {
3652
3637
else Nil
3653
3638
t :: ts
3654
3639
3640
+
3641
+ /** `{`with` ConstrApp} but no EOL allowed after `with`.
3642
+ */
3643
+ def withConstrApps (): List [Tree ] =
3644
+ if in.token == WITH then
3645
+ in.observeWithEOL() // converts token to WITHEOL if at end of line
3646
+ if in.token == WITH && in.lookahead.token != LBRACE then
3647
+ in.nextToken()
3648
+ constrApp() :: withConstrApps()
3649
+ else Nil
3650
+ else Nil
3651
+
3655
3652
/** Template ::= InheritClauses [TemplateBody]
3656
3653
* InheritClauses ::= [‘extends’ ConstrApps] [‘derives’ QualId {‘,’ QualId}]
3657
3654
*/
@@ -3717,6 +3714,14 @@ object Parsers {
3717
3714
template(emptyConstructor)
3718
3715
r
3719
3716
3717
+ /** with Template, with EOL <indent> interpreted */
3718
+ def withTemplate (constr : DefDef , parents : List [Tree ]): Template =
3719
+ if in.token != WITHEOL then accept(WITH )
3720
+ possibleTemplateStart() // consumes a WITHEOL token
3721
+ val (self, stats) = templateBody()
3722
+ Template (constr, parents, Nil , self, stats)
3723
+ .withSpan(Span (constr.span.orElse(parents.head.span).start, in.lastOffset))
3724
+
3720
3725
/* -------- STATSEQS ------------------------------------------- */
3721
3726
3722
3727
/** Create a tree representing a packaging */
0 commit comments