@@ -913,7 +913,10 @@ object Parsers {
913
913
lookahead.nextToken()
914
914
if lookahead.token == IDENTIFIER then
915
915
lookahead.nextToken()
916
- lookahead.token == COLON
916
+ if lookahead.token == COLON then
917
+ lookahead.nextToken()
918
+ ! lookahead.isAfterLineEnd
919
+ else false
917
920
else false
918
921
else false
919
922
@@ -943,7 +946,10 @@ object Parsers {
943
946
lookahead.nextToken()
944
947
while lookahead.token == LPAREN || lookahead.token == LBRACKET do
945
948
lookahead.skipParens()
946
- lookahead.token == COLON || lookahead.token == SUBTYPE
949
+ if lookahead.token == COLON then
950
+ lookahead.nextToken()
951
+ ! lookahead.isAfterLineEnd
952
+ else lookahead.token == SUBTYPE
947
953
948
954
def followingIsExtension () =
949
955
val lookahead = in.LookaheadScanner ()
@@ -1304,7 +1310,12 @@ object Parsers {
1304
1310
}
1305
1311
1306
1312
def possibleTemplateStart (isNew : Boolean = false ): Unit =
1307
- if in.token == WITH then
1313
+ in.observeColonEOL()
1314
+ if in.token == COLONEOL then
1315
+ in.nextToken()
1316
+ if in.token != INDENT then
1317
+ syntaxError(i " indented definitions expected " )
1318
+ else if in.token == WITH then
1308
1319
in.nextToken()
1309
1320
if in.token != LBRACE && in.token != INDENT then
1310
1321
syntaxError(i " indented definitions or `{` expected " )
@@ -1458,7 +1469,7 @@ object Parsers {
1458
1469
def infixTypeRest (t : Tree ): Tree =
1459
1470
infixOps(t, canStartTypeTokens, refinedType, isType = true , isOperator = ! isPostfixStar)
1460
1471
1461
- /** RefinedType ::= WithType {[nl | `with' ] Refinement}
1472
+ /** RefinedType ::= WithType {[nl] Refinement}
1462
1473
*/
1463
1474
val refinedType : () => Tree = () => refinedTypeRest(withType())
1464
1475
@@ -2082,7 +2093,8 @@ object Parsers {
2082
2093
}
2083
2094
else simpleExpr()
2084
2095
2085
- /** SimpleExpr ::= ‘new’ (ConstrApp [[‘with’] TemplateBody] | TemplateBody)
2096
+ /** SimpleExpr ::= ‘new’ ConstrApp {`with` ConstrApp} [TemplateBody]
2097
+ * | ‘new’ TemplateBody
2086
2098
* | BlockExpr
2087
2099
* | ‘$’ ‘{’ Block ‘}’
2088
2100
* | Quoted
@@ -2177,7 +2189,7 @@ object Parsers {
2177
2189
}
2178
2190
}
2179
2191
2180
- /** SimpleExpr ::= ‘new’ ConstrApp {`with` ConstrApp} [[‘with’] TemplateBody]
2192
+ /** SimpleExpr ::= ‘new’ ConstrApp {`with` ConstrApp} [TemplateBody]
2181
2193
* | ‘new’ TemplateBody
2182
2194
*/
2183
2195
def newExpr (): Tree =
@@ -3352,7 +3364,7 @@ object Parsers {
3352
3364
syntaxError(s " Only access modifiers are allowed on enum $where" )
3353
3365
mods1
3354
3366
3355
- /** EnumDef ::= id ClassConstr InheritClauses [‘with’] EnumBody
3367
+ /** EnumDef ::= id ClassConstr InheritClauses EnumBody
3356
3368
*/
3357
3369
def enumDef (start : Offset , mods : Modifiers ): TypeDef = atSpan(start, nameStart) {
3358
3370
val mods1 = checkAccessOnly(mods, " definitions" )
@@ -3415,8 +3427,7 @@ object Parsers {
3415
3427
}
3416
3428
3417
3429
/** GivenDef ::= [GivenSig (‘:’ | <:)] {FunArgTypes ‘=>’} AnnotType ‘=’ Expr
3418
- * | [GivenSig ‘:’] {FunArgTypes ‘=>’} ConstrApps [[‘with’] TemplateBody]
3419
- * | [id ‘:’] ExtParamClause {GivenParamClause} ‘extended’ ‘with’ ExtMethods
3430
+ * | [GivenSig ‘:’] {FunArgTypes ‘=>’} ConstrApps [TemplateBody]
3420
3431
* GivenSig ::= [id] [DefTypeParamClause] {GivenParamClause}
3421
3432
* ExtParamClause ::= [DefTypeParamClause] DefParamClause
3422
3433
* ExtMethods ::= [nl] ‘{’ ‘def’ DefDef {semi ‘def’ DefDef} ‘}’
@@ -3458,83 +3469,68 @@ object Parsers {
3458
3469
if in.token == LPAREN && followingIsParamOrGivenType()
3459
3470
then paramClauses() // todo: ONLY admit a single paramClause
3460
3471
else Nil
3461
- val isExtension = isIdent(nme.extended)
3462
3472
def checkAllGivens (vparamss : List [List [ValDef ]], what : String ) =
3463
3473
vparamss.foreach(_.foreach(vparam =>
3464
3474
if ! vparam.mods.is(Given ) then syntaxError(em " $what must be `given` " , vparam.span)))
3465
- if isExtension then
3466
- if ! name.isEmpty && ! hasLabel then
3467
- syntaxError(em " name $name of extension clause must be followed by `:` " , nameStart)
3468
- vparamss match
3469
- case (vparam :: Nil ) :: vparamss1 if ! vparam.mods.is(Given ) =>
3470
- checkAllGivens(vparamss1, " follow-on parameter in extension clause" )
3471
- case _ =>
3472
- syntaxError(" extension clause must start with a single regular parameter" , paramsStart)
3473
- in.nextToken()
3474
- accept(WITH )
3475
- val (self, stats) = templateBody()
3476
- stats.foreach(checkExtensionMethod(tparams, _))
3477
- ModuleDef (name, Template (makeConstructor(tparams, vparamss), Nil , Nil , self, stats))
3478
- else
3479
- def makeGiven (params : List [ValDef ]): List [ValDef ] =
3480
- params.map(param => param.withMods(param.mods | Given ))
3481
- def conditionalParents (): List [Tree ] =
3482
- accept(ARROW )
3483
- if in.token == LPAREN && followingIsParam() then
3484
- vparamss = vparamss :+ makeGiven(paramClause(vparamss.flatten.length))
3485
- conditionalParents()
3486
- else
3487
- val constrs = constrApps(commaOK = true , templateCanFollow = true )
3488
- if in.token == ARROW && constrs.forall(_.isType) then
3489
- vparamss = vparamss
3490
- :+ typesToGivenParams(constrs, ofClass = false , vparamss.flatten.length)
3491
- conditionalParents()
3492
- else constrs
3493
-
3494
- val isConditional =
3495
- in.token == ARROW
3496
- && vparamss.length == 1
3497
- && (hasLabel || name.isEmpty && tparams.isEmpty)
3498
- if ! isConditional then checkAllGivens(vparamss, " parameter of given instance" )
3499
- val parents =
3500
- if in.token == SUBTYPE && ! hasLabel then
3501
- if ! mods.is(Inline ) then
3502
- syntaxError(" `<:` is only allowed for given with `inline` modifier" )
3503
- in.nextToken()
3504
- TypeBoundsTree (EmptyTree , annotType()) :: Nil
3505
- else if isConditional then
3506
- vparamss = vparamss.map(makeGiven)
3475
+ def makeGiven (params : List [ValDef ]): List [ValDef ] =
3476
+ params.map(param => param.withMods(param.mods | Given ))
3477
+ def conditionalParents (): List [Tree ] =
3478
+ accept(ARROW )
3479
+ if in.token == LPAREN && followingIsParam() then
3480
+ vparamss = vparamss :+ makeGiven(paramClause(vparamss.flatten.length))
3481
+ conditionalParents()
3482
+ else
3483
+ val constrs = constrApps(commaOK = true , templateCanFollow = true )
3484
+ if in.token == ARROW && constrs.forall(_.isType) then
3485
+ vparamss = vparamss
3486
+ :+ typesToGivenParams(constrs, ofClass = false , vparamss.flatten.length)
3507
3487
conditionalParents()
3508
- else
3509
- if ! hasLabel && ! (name.isEmpty && tparams.isEmpty && vparamss.isEmpty) then
3510
- accept( COLON )
3511
- val constrs = constrApps(commaOK = true , templateCanFollow = true )
3512
- if in.token == ARROW && vparamss.isEmpty && constrs.forall(_.isType) then
3513
- vparamss = typesToGivenParams(constrs, ofClass = false , 0 ) :: Nil
3514
- conditionalParents( )
3515
- else
3516
- constrs
3517
-
3518
- if in.token == EQUALS && parents.length == 1 && parents.head.isType then
3488
+ else constrs
3489
+
3490
+ val isConditional =
3491
+ in.token == ARROW
3492
+ && vparamss.length == 1
3493
+ && (hasLabel || name.isEmpty && tparams.isEmpty)
3494
+ if ! isConditional then checkAllGivens(vparamss, " parameter of given instance " )
3495
+ val parents =
3496
+ if in.token == SUBTYPE && ! hasLabel then
3497
+ if ! mods.is( Inline ) then
3498
+ syntaxError( " `<:` is only allowed for given with `inline` modifier " )
3519
3499
in.nextToken()
3520
- mods1 |= Final
3521
- DefDef (name, tparams, vparamss, parents.head, subExpr())
3500
+ TypeBoundsTree (EmptyTree , annotType()) :: Nil
3501
+ else if isConditional then
3502
+ vparamss = vparamss.map(makeGiven)
3503
+ conditionalParents()
3522
3504
else
3523
- parents match
3524
- case TypeBoundsTree (_, _) :: _ => syntaxError(" `=` expected" )
3525
- case _ =>
3526
- possibleTemplateStart()
3527
- val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal ))
3528
- val vparamss1 = vparamss.map(_.map(vparam =>
3529
- vparam.withMods(vparam.mods &~ Param | ParamAccessor | PrivateLocal )))
3530
- val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil )
3531
- if tparams.isEmpty && vparamss.isEmpty then ModuleDef (name, templ)
3532
- else TypeDef (name.toTypeName, templ)
3505
+ if ! hasLabel && ! (name.isEmpty && tparams.isEmpty && vparamss.isEmpty) then
3506
+ accept(COLON )
3507
+ val constrs = constrApps(commaOK = true , templateCanFollow = true )
3508
+ if in.token == ARROW && vparamss.isEmpty && constrs.forall(_.isType) then
3509
+ vparamss = typesToGivenParams(constrs, ofClass = false , 0 ) :: Nil
3510
+ conditionalParents()
3511
+ else
3512
+ constrs
3513
+
3514
+ if in.token == EQUALS && parents.length == 1 && parents.head.isType then
3515
+ in.nextToken()
3516
+ mods1 |= Final
3517
+ DefDef (name, tparams, vparamss, parents.head, subExpr())
3518
+ else
3519
+ parents match
3520
+ case TypeBoundsTree (_, _) :: _ => syntaxError(" `=` expected" )
3521
+ case _ =>
3522
+ possibleTemplateStart()
3523
+ val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal ))
3524
+ val vparamss1 = vparamss.map(_.map(vparam =>
3525
+ vparam.withMods(vparam.mods &~ Param | ParamAccessor | PrivateLocal )))
3526
+ val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil )
3527
+ if tparams.isEmpty && vparamss.isEmpty then ModuleDef (name, templ)
3528
+ else TypeDef (name.toTypeName, templ)
3533
3529
}
3534
3530
finalizeDef(gdef, mods1, start)
3535
3531
}
3536
3532
3537
- /** ExtensionDef ::= [id] ‘of ’ ExtParamClause {GivenParamClause} ‘with’ ExtMethods
3533
+ /** ExtensionDef ::= [id] ‘on ’ ExtParamClause {GivenParamClause} ExtMethods
3538
3534
*/
3539
3535
def extensionDef (start : Offset , mods : Modifiers ): ModuleDef =
3540
3536
in.nextToken()
@@ -3580,7 +3576,7 @@ object Parsers {
3580
3576
else Nil
3581
3577
t :: ts
3582
3578
3583
- /** Template ::= InheritClauses [[‘with’] TemplateBody]
3579
+ /** Template ::= InheritClauses [TemplateBody]
3584
3580
* InheritClauses ::= [‘extends’ ConstrApps] [‘derives’ QualId {‘,’ QualId}]
3585
3581
*/
3586
3582
def template (constr : DefDef , isEnum : Boolean = false ): Template = {
@@ -3650,7 +3646,7 @@ object Parsers {
3650
3646
case x : RefTree => atSpan(start, pointOffset(pkg))(PackageDef (x, stats))
3651
3647
}
3652
3648
3653
- /** Packaging ::= package QualId [nl | `with' ] `{' TopStatSeq `}'
3649
+ /** Packaging ::= package QualId [nl] `{' TopStatSeq `}'
3654
3650
*/
3655
3651
def packaging (start : Int ): Tree = {
3656
3652
val pkg = qualId()
0 commit comments