@@ -2977,6 +2977,61 @@ object Parsers {
2977
2977
2978
2978
/* -------- PARAMETERS ------------------------------------------- */
2979
2979
2980
+ /** DefParamClause ::= DefTypeParamClause
2981
+ * | DefTermParamClause
2982
+ * | UsingParamClause
2983
+ */
2984
+ def typeOrTermParamClause (nparams : Int , // number of parameters preceding this clause
2985
+ ofClass : Boolean = false , // owner is a class
2986
+ ofCaseClass : Boolean = false , // owner is a case class
2987
+ prefix : Boolean = false , // clause precedes name of an extension method
2988
+ givenOnly : Boolean = false , // only given parameters allowed
2989
+ firstClause : Boolean = false , // clause is the first in regular list of clauses
2990
+ ownerKind : ParamOwner
2991
+ ): List [TypeDef ] | List [ValDef ] =
2992
+ if (in.token == LPAREN )
2993
+ paramClause(nparams, ofClass, ofCaseClass, prefix, givenOnly, firstClause)
2994
+ else if (in.token == LBRACKET )
2995
+ typeParamClause(ownerKind)
2996
+ else
2997
+ Nil
2998
+
2999
+ end typeOrTermParamClause
3000
+
3001
+ /** DefParamClauses ::= DefParamClause { DefParamClause }
3002
+ */
3003
+ def typeOrTermParamClauses (
3004
+ ownerKind : ParamOwner ,
3005
+ ofClass : Boolean = false ,
3006
+ ofCaseClass : Boolean = false ,
3007
+ givenOnly : Boolean = false ,
3008
+ numLeadParams : Int = 0
3009
+ ): List [List [TypeDef ] | List [ValDef ]] =
3010
+
3011
+ def recur (firstClause : Boolean , nparams : Int ): List [List [TypeDef ] | List [ValDef ]] =
3012
+ newLineOptWhenFollowedBy(LPAREN )
3013
+ newLineOptWhenFollowedBy(LBRACKET )
3014
+ if in.token == LPAREN then
3015
+ val paramsStart = in.offset
3016
+ val params = paramClause(
3017
+ nparams,
3018
+ ofClass = ofClass,
3019
+ ofCaseClass = ofCaseClass,
3020
+ givenOnly = givenOnly,
3021
+ firstClause = firstClause)
3022
+ val lastClause = params.nonEmpty && params.head.mods.flags.is(Implicit )
3023
+ params :: (
3024
+ if lastClause then Nil
3025
+ else recur(firstClause = false , nparams + params.length))
3026
+ else if in.token == LBRACKET then
3027
+ typeParamClause(ownerKind) :: recur(firstClause, nparams)
3028
+ else Nil
3029
+ end recur
3030
+
3031
+ recur(firstClause = true , nparams = numLeadParams)
3032
+ end typeOrTermParamClauses
3033
+
3034
+
2980
3035
/** ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’
2981
3036
* ClsTypeParam ::= {Annotation} [‘+’ | ‘-’]
2982
3037
* id [HkTypeParamClause] TypeParamBounds
@@ -3041,11 +3096,15 @@ object Parsers {
3041
3096
* UsingClsParamClause::= ‘(’ ‘using’ [‘erased’] (ClsParams | ContextTypes) ‘)’
3042
3097
* ClsParams ::= ClsParam {‘,’ ClsParam}
3043
3098
* ClsParam ::= {Annotation}
3099
+ *
3100
+ * TypelessClause ::= DefTermParamClause
3101
+ * | UsingParamClause
3044
3102
*
3045
- * DefParamClause ::= ‘(’ [‘erased’] DefParams ‘)’ | UsingParamClause
3046
- * UsingParamClause ::= ‘(’ ‘using’ [‘erased’] (DefParams | ContextTypes) ‘)’
3047
- * DefParams ::= DefParam {‘,’ DefParam}
3048
- * DefParam ::= {Annotation} [‘inline’] Param
3103
+ * DefTermParamClause::= [nl] ‘(’ [DefTermParams] ‘)’
3104
+ * UsingParamClause ::= ‘(’ ‘using’ [‘erased’] (DefTermParams | ContextTypes) ‘)’
3105
+ * DefImplicitClause ::= [nl] ‘(’ ‘implicit’ DefTermParams ‘)’
3106
+ * DefTermParams ::= DefTermParam {‘,’ DefTermParam}
3107
+ * DefTermParam ::= {Annotation} [‘inline’] Param
3049
3108
*
3050
3109
* Param ::= id `:' ParamType [`=' Expr]
3051
3110
*
@@ -3143,7 +3202,7 @@ object Parsers {
3143
3202
}
3144
3203
3145
3204
/** ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ [‘implicit’] ClsParams ‘)’]
3146
- * DefParamClauses ::= {DefParamClause} [[nl] ‘(’ [‘implicit’] DefParams ‘)’]
3205
+ * TypelessClauses ::= TypelessClause {TypelessClause}
3147
3206
*
3148
3207
* @return The parameter definitions
3149
3208
*/
@@ -3411,9 +3470,9 @@ object Parsers {
3411
3470
}
3412
3471
3413
3472
/** DefDef ::= DefSig [‘:’ Type] ‘=’ Expr
3414
- * | this ParamClause ParamClauses `=' ConstrExpr
3473
+ * | this TypelessClauses [DefImplicitClause] `=' ConstrExpr
3415
3474
* DefDcl ::= DefSig `:' Type
3416
- * DefSig ::= id [DefTypeParamClause] DefParamClauses
3475
+ * DefSig ::= id [DefParamClauses] [DefImplicitClause]
3417
3476
* | ExtParamClause [nl] [‘.’] id DefParamClauses
3418
3477
*/
3419
3478
def defDefOrDcl (start : Offset , mods : Modifiers , numLeadParams : Int = 0 ): DefDef = atSpan(start, nameStart) {
@@ -3451,8 +3510,7 @@ object Parsers {
3451
3510
val mods1 = addFlag(mods, Method )
3452
3511
val ident = termIdent()
3453
3512
var name = ident.name.asTermName
3454
- val tparams = typeParamClauseOpt(ParamOwner .Def )
3455
- val vparamss = paramClauses(numLeadParams = numLeadParams)
3513
+ val paramss = typeOrTermParamClauses(ParamOwner .Def , numLeadParams = numLeadParams)
3456
3514
var tpt = fromWithinReturnType { typedOpt() }
3457
3515
if (migrateTo3) newLineOptWhenFollowedBy(LBRACE )
3458
3516
val rhs =
@@ -3470,7 +3528,7 @@ object Parsers {
3470
3528
accept(EQUALS )
3471
3529
expr()
3472
3530
3473
- val ddef = DefDef (name, joinParams(tparams, vparamss) , tpt, rhs)
3531
+ val ddef = DefDef (name, paramss , tpt, rhs)
3474
3532
if (isBackquoted(ident)) ddef.pushAttachment(Backquoted , ())
3475
3533
finalizeDef(ddef, mods1, start)
3476
3534
}
@@ -3733,7 +3791,7 @@ object Parsers {
3733
3791
finalizeDef(gdef, mods1, start)
3734
3792
}
3735
3793
3736
- /** Extension ::= ‘extension’ [DefTypeParamClause] {UsingParamClause} ‘(’ DefParam ‘)’
3794
+ /** Extension ::= ‘extension’ [DefTypeParamClause] {UsingParamClause} ‘(’ DefTermParam ‘)’
3737
3795
* {UsingParamClause} ExtMethods
3738
3796
*/
3739
3797
def extension (): ExtMethods =
0 commit comments