@@ -958,8 +958,9 @@ object Parsers {
958
958
val suffixIsUpper = Character .isUpperCase(suffixName.head)
959
959
if prefixIsUpper && ! suffixIsUpper then false
960
960
else if ! prefixIsUpper && suffixIsUpper then true
961
- else syntaxError(
962
- em " ambiguous syntax for given definition; make sure exactly one of $prefixName, $suffixName is capitalized " )
961
+ else
962
+ syntaxError(
963
+ em " ambiguous syntax for given definition; make sure exactly one of $prefixName, $suffixName is capitalized " )
963
964
true
964
965
end followingIsGivenSig
965
966
@@ -1440,7 +1441,7 @@ object Parsers {
1440
1441
1441
1442
val t =
1442
1443
if in.token == LPAREN then
1443
- typAfterParens( functionRest)
1444
+ afterArguments(x => infixTypeRest(refinedTypeRest(withTypeRest(x))), functionRest)
1444
1445
else if (in.token == LBRACKET ) {
1445
1446
val tparams = typeParamClause(ParamOwner .TypeParam )
1446
1447
if (in.token == TLARROW )
@@ -1480,14 +1481,14 @@ object Parsers {
1480
1481
buf += following()
1481
1482
buf.toList
1482
1483
1483
- def typAfterParens ( parseRest : (List [Tree ], Modifiers ) => Tree ) =
1484
+ def afterArguments [ T ]( parseSimple : Tree => T , parseFn : (List [Tree ], Modifiers ) => T ) : T =
1484
1485
val start = in.offset
1485
1486
in.nextToken()
1486
1487
var imods = Modifiers ()
1487
1488
var isValParamList = false
1488
1489
if in.token == RPAREN then
1489
1490
in.nextToken()
1490
- parseRest (Nil , imods)
1491
+ parseFn (Nil , imods)
1491
1492
else
1492
1493
openParens.change(LPAREN , 1 )
1493
1494
imods = modifiers(funTypeArgMods)
@@ -1503,7 +1504,7 @@ object Parsers {
1503
1504
openParens.change(LPAREN , - 1 )
1504
1505
accept(RPAREN )
1505
1506
if isValParamList || in.token == ARROW || in.token == CTXARROW then
1506
- parseRest (ts, imods)
1507
+ parseFn (ts, imods)
1507
1508
else
1508
1509
val ts1 =
1509
1510
for t <- ts yield
@@ -1514,12 +1515,8 @@ object Parsers {
1514
1515
case _ =>
1515
1516
t
1516
1517
val tuple = atSpan(start) { makeTupleOrParens(ts1) }
1517
- infixTypeRest(
1518
- refinedTypeRest(
1519
- withTypeRest(
1520
- annotTypeRest(
1521
- simpleTypeRest(tuple)))))
1522
- end typAfterParens
1518
+ parseSimple(annotTypeRest(simpleTypeRest(tuple)))
1519
+ end afterArguments
1523
1520
1524
1521
private def makeKindProjectorTypeDef (name : TypeName ): TypeDef =
1525
1522
TypeDef (name, WildcardTypeBoundsTree ()).withFlags(Param )
@@ -3562,13 +3559,13 @@ object Parsers {
3562
3559
syntaxError(i " extension clause can only define methods " , stat.span)
3563
3560
}
3564
3561
3565
- /** GivenDef ::= [GivenSig ] Type ‘=’ Expr
3566
- * | [GivenSig ] ConstrApps [TemplateBody]
3567
- * GivenSig ::= [id] [ DefTypeParamClause] {UsingParamClauses} ‘as’
3562
+ /** GivenDef ::= [GivenParams ] Type ['as' id] ‘=’ Expr
3563
+ * | [GivenParams ] ConstrApps ['as' id] [TemplateBody]
3564
+ * GivenParams ::= [DefTypeParamClause '=>' ] {FunArgTypes '=>'}
3568
3565
*/
3569
3566
def givenDef (start : Offset , mods : Modifiers , givenMod : Mod ) = atSpan(start, nameStart) {
3570
3567
var mods1 = addMod(mods, givenMod)
3571
- val nameStart = in.offset
3568
+ val start = in.offset
3572
3569
val (name, tparams, vparamss, parents) = if followingIsGivenSig() then
3573
3570
val name = if isIdent then ident() else EmptyTermName
3574
3571
val tparams = typeParamClauseOpt(ParamOwner .Def )
@@ -3581,6 +3578,36 @@ object Parsers {
3581
3578
accept(nme.as)
3582
3579
val parents = constrApps(commaOK = true )
3583
3580
(name, tparams, vparamss, parents)
3581
+ else if true then
3582
+ val tparams = typeParamClauseOpt(ParamOwner .Def )
3583
+ if tparams.nonEmpty then accept(ARROW )
3584
+ var counter = 0
3585
+ def nextIdx = { counter += 1 ; counter }
3586
+ def givenHeadRest (params : List [Tree ], mods : Modifiers ): (List [List [ValDef ]], List [Tree ]) =
3587
+ accept(ARROW )
3588
+ val vparams = params match
3589
+ case (_ : ValDef ) :: _ =>
3590
+ params.asInstanceOf [List [ValDef ]].map(_.withFlags(Given ))
3591
+ case _ =>
3592
+ params.map(makeSyntheticParameter(nextIdx, _, Param | Synthetic | Given ))
3593
+ val (vparamss1, parents) = givenHead()
3594
+ (vparams :: vparamss1, parents)
3595
+ def givenHeadFinish (t : Tree ): (List [List [ValDef ]], List [Tree ]) =
3596
+ (Nil , constrAppsRest(constrAppRest(t), commaOK = true ))
3597
+ def givenHead (): (List [List [ValDef ]], List [Tree ]) =
3598
+ if in.token == LPAREN then
3599
+ afterArguments(givenHeadFinish, givenHeadRest)
3600
+ else
3601
+ val constr = constrOrSimpleType()
3602
+ if in.token == ARROW then givenHeadRest(constr :: Nil , EmptyModifiers )
3603
+ else givenHeadFinish(constr)
3604
+ val (vparamss, parents) = givenHead()
3605
+ val name =
3606
+ if in.isIdent(nme.as) then
3607
+ in.nextToken()
3608
+ ident()
3609
+ else EmptyTermName
3610
+ (name, tparams, vparamss, parents)
3584
3611
else
3585
3612
(EmptyTermName , Nil , Nil , constrApps(commaOK = true ))
3586
3613
val gdef =
@@ -3662,7 +3689,9 @@ object Parsers {
3662
3689
/** ConstrApp ::= SimpleType1 {Annotation} {ParArgumentExprs}
3663
3690
*/
3664
3691
val constrApp : () => Tree = () =>
3665
- val t = constrOrSimpleType()
3692
+ constrAppRest(constrOrSimpleType())
3693
+
3694
+ def constrAppRest (t : Tree ): Tree =
3666
3695
if in.token == LPAREN then parArgumentExprss(wrapNew(t)) else t
3667
3696
3668
3697
/** ConstrApps ::= ConstrApp {(‘,’ | ‘with’) ConstrApp}
0 commit comments