@@ -3079,6 +3079,61 @@ object Parsers {
3079
3079
3080
3080
/* -------- PARAMETERS ------------------------------------------- */
3081
3081
3082
+ /** DefParamClause ::= DefTypeParamClause
3083
+ * | DefTermParamClause
3084
+ * | UsingParamClause
3085
+ */
3086
+ def typeOrTermParamClause (nparams : Int , // number of parameters preceding this clause
3087
+ ofClass : Boolean = false , // owner is a class
3088
+ ofCaseClass : Boolean = false , // owner is a case class
3089
+ prefix : Boolean = false , // clause precedes name of an extension method
3090
+ givenOnly : Boolean = false , // only given parameters allowed
3091
+ firstClause : Boolean = false , // clause is the first in regular list of clauses
3092
+ ownerKind : ParamOwner
3093
+ ): List [TypeDef ] | List [ValDef ] =
3094
+ if (in.token == LPAREN )
3095
+ paramClause(nparams, ofClass, ofCaseClass, prefix, givenOnly, firstClause)
3096
+ else if (in.token == LBRACKET )
3097
+ typeParamClause(ownerKind)
3098
+ else
3099
+ Nil
3100
+
3101
+ end typeOrTermParamClause
3102
+
3103
+ /** DefParamClauses ::= DefParamClause { DefParamClause }
3104
+ */
3105
+ def typeOrTermParamClauses (
3106
+ ownerKind : ParamOwner ,
3107
+ ofClass : Boolean = false ,
3108
+ ofCaseClass : Boolean = false ,
3109
+ givenOnly : Boolean = false ,
3110
+ numLeadParams : Int = 0
3111
+ ): List [List [TypeDef ] | List [ValDef ]] =
3112
+
3113
+ def recur (firstClause : Boolean , nparams : Int ): List [List [TypeDef ] | List [ValDef ]] =
3114
+ newLineOptWhenFollowedBy(LPAREN )
3115
+ newLineOptWhenFollowedBy(LBRACKET )
3116
+ if in.token == LPAREN then
3117
+ val paramsStart = in.offset
3118
+ val params = paramClause(
3119
+ nparams,
3120
+ ofClass = ofClass,
3121
+ ofCaseClass = ofCaseClass,
3122
+ givenOnly = givenOnly,
3123
+ firstClause = firstClause)
3124
+ val lastClause = params.nonEmpty && params.head.mods.flags.is(Implicit )
3125
+ params :: (
3126
+ if lastClause then Nil
3127
+ else recur(firstClause = false , nparams + params.length))
3128
+ else if in.token == LBRACKET then
3129
+ typeParamClause(ownerKind) :: recur(firstClause, nparams)
3130
+ else Nil
3131
+ end recur
3132
+
3133
+ recur(firstClause = true , nparams = numLeadParams)
3134
+ end typeOrTermParamClauses
3135
+
3136
+
3082
3137
/** ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’
3083
3138
* ClsTypeParam ::= {Annotation} [‘+’ | ‘-’]
3084
3139
* id [HkTypeParamClause] TypeParamBounds
@@ -3143,11 +3198,15 @@ object Parsers {
3143
3198
* UsingClsParamClause::= ‘(’ ‘using’ [‘erased’] (ClsParams | ContextTypes) ‘)’
3144
3199
* ClsParams ::= ClsParam {‘,’ ClsParam}
3145
3200
* ClsParam ::= {Annotation}
3201
+ *
3202
+ * TypelessClause ::= DefTermParamClause
3203
+ * | UsingParamClause
3146
3204
*
3147
- * DefParamClause ::= ‘(’ [‘erased’] DefParams ‘)’ | UsingParamClause
3148
- * UsingParamClause ::= ‘(’ ‘using’ [‘erased’] (DefParams | ContextTypes) ‘)’
3149
- * DefParams ::= DefParam {‘,’ DefParam}
3150
- * DefParam ::= {Annotation} [‘inline’] Param
3205
+ * DefTermParamClause::= [nl] ‘(’ [DefTermParams] ‘)’
3206
+ * UsingParamClause ::= ‘(’ ‘using’ [‘erased’] (DefTermParams | ContextTypes) ‘)’
3207
+ * DefImplicitClause ::= [nl] ‘(’ ‘implicit’ DefTermParams ‘)’
3208
+ * DefTermParams ::= DefTermParam {‘,’ DefTermParam}
3209
+ * DefTermParam ::= {Annotation} [‘inline’] Param
3151
3210
*
3152
3211
* Param ::= id `:' ParamType [`=' Expr]
3153
3212
*
@@ -3246,7 +3305,7 @@ object Parsers {
3246
3305
}
3247
3306
3248
3307
/** ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ [‘implicit’] ClsParams ‘)’]
3249
- * DefParamClauses ::= {DefParamClause} [[nl] ‘(’ [‘implicit’] DefParams ‘)’]
3308
+ * TypelessClauses ::= TypelessClause {TypelessClause}
3250
3309
*
3251
3310
* @return The parameter definitions
3252
3311
*/
@@ -3515,9 +3574,9 @@ object Parsers {
3515
3574
}
3516
3575
3517
3576
/** DefDef ::= DefSig [‘:’ Type] ‘=’ Expr
3518
- * | this ParamClause ParamClauses `=' ConstrExpr
3577
+ * | this TypelessClauses [DefImplicitClause] `=' ConstrExpr
3519
3578
* DefDcl ::= DefSig `:' Type
3520
- * DefSig ::= id [DefTypeParamClause] DefParamClauses
3579
+ * DefSig ::= id [DefParamClauses] [DefImplicitClause]
3521
3580
* | ExtParamClause [nl] [‘.’] id DefParamClauses
3522
3581
*/
3523
3582
def defDefOrDcl (start : Offset , mods : Modifiers , numLeadParams : Int = 0 ): DefDef = atSpan(start, nameStart) {
@@ -3555,8 +3614,7 @@ object Parsers {
3555
3614
val mods1 = addFlag(mods, Method )
3556
3615
val ident = termIdent()
3557
3616
var name = ident.name.asTermName
3558
- val tparams = typeParamClauseOpt(ParamOwner .Def )
3559
- val vparamss = paramClauses(numLeadParams = numLeadParams)
3617
+ val paramss = typeOrTermParamClauses(ParamOwner .Def , numLeadParams = numLeadParams)
3560
3618
var tpt = fromWithinReturnType { typedOpt() }
3561
3619
if (migrateTo3) newLineOptWhenFollowedBy(LBRACE )
3562
3620
val rhs =
@@ -3574,7 +3632,7 @@ object Parsers {
3574
3632
accept(EQUALS )
3575
3633
expr()
3576
3634
3577
- val ddef = DefDef (name, joinParams(tparams, vparamss) , tpt, rhs)
3635
+ val ddef = DefDef (name, paramss , tpt, rhs)
3578
3636
if (isBackquoted(ident)) ddef.pushAttachment(Backquoted , ())
3579
3637
finalizeDef(ddef, mods1, start)
3580
3638
}
@@ -3837,7 +3895,7 @@ object Parsers {
3837
3895
finalizeDef(gdef, mods1, start)
3838
3896
}
3839
3897
3840
- /** Extension ::= ‘extension’ [DefTypeParamClause] {UsingParamClause} ‘(’ DefParam ‘)’
3898
+ /** Extension ::= ‘extension’ [DefTypeParamClause] {UsingParamClause} ‘(’ DefTermParam ‘)’
3841
3899
* {UsingParamClause} ExtMethods
3842
3900
*/
3843
3901
def extension (): ExtMethods =
0 commit comments