@@ -2904,6 +2904,61 @@ object Parsers {
2904
2904
2905
2905
/* -------- PARAMETERS ------------------------------------------- */
2906
2906
2907
+ /** DefParamClause ::= DefTypeParamClause
2908
+ * | DefTermParamClause
2909
+ * | UsingParamClause
2910
+ */
2911
+ def typeOrTermParamClause (nparams : Int , // number of parameters preceding this clause
2912
+ ofClass : Boolean = false , // owner is a class
2913
+ ofCaseClass : Boolean = false , // owner is a case class
2914
+ prefix : Boolean = false , // clause precedes name of an extension method
2915
+ givenOnly : Boolean = false , // only given parameters allowed
2916
+ firstClause : Boolean = false , // clause is the first in regular list of clauses
2917
+ ownerKind : ParamOwner .Value
2918
+ ): List [TypeDef ] | List [ValDef ] =
2919
+ if (in.token == LPAREN )
2920
+ paramClause(nparams, ofClass, ofCaseClass, prefix, givenOnly, firstClause)
2921
+ else if (in.token == LBRACKET )
2922
+ typeParamClause(ownerKind)
2923
+ else
2924
+ Nil
2925
+
2926
+ end typeOrTermParamClause
2927
+
2928
+ /** DefParamClauses ::= DefParamClause { DefParamClause }
2929
+ */
2930
+ def typeOrTermParamClauses (
2931
+ ownerKind : ParamOwner .Value ,
2932
+ ofClass : Boolean = false ,
2933
+ ofCaseClass : Boolean = false ,
2934
+ givenOnly : Boolean = false ,
2935
+ numLeadParams : Int = 0
2936
+ ): List [List [TypeDef ] | List [ValDef ]] =
2937
+
2938
+ def recur (firstClause : Boolean , nparams : Int ): List [List [TypeDef ] | List [ValDef ]] =
2939
+ newLineOptWhenFollowedBy(LPAREN )
2940
+ newLineOptWhenFollowedBy(LBRACKET )
2941
+ if in.token == LPAREN then
2942
+ val paramsStart = in.offset
2943
+ val params = paramClause(
2944
+ nparams,
2945
+ ofClass = ofClass,
2946
+ ofCaseClass = ofCaseClass,
2947
+ givenOnly = givenOnly,
2948
+ firstClause = firstClause)
2949
+ val lastClause = params.nonEmpty && params.head.mods.flags.is(Implicit )
2950
+ params :: (
2951
+ if lastClause then Nil
2952
+ else recur(firstClause = false , nparams + params.length))
2953
+ else if in.token == LBRACKET then
2954
+ typeParamClause(ownerKind) :: recur(firstClause, nparams)
2955
+ else Nil
2956
+ end recur
2957
+
2958
+ recur(firstClause = true , nparams = numLeadParams)
2959
+ end typeOrTermParamClauses
2960
+
2961
+
2907
2962
/** ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’
2908
2963
* ClsTypeParam ::= {Annotation} [‘+’ | ‘-’]
2909
2964
* id [HkTypeParamClause] TypeParamBounds
@@ -2968,11 +3023,15 @@ object Parsers {
2968
3023
* UsingClsParamClause::= ‘(’ ‘using’ [‘erased’] (ClsParams | ContextTypes) ‘)’
2969
3024
* ClsParams ::= ClsParam {‘,’ ClsParam}
2970
3025
* ClsParam ::= {Annotation}
3026
+ *
3027
+ * TypelessClause ::= DefTermParamClause
3028
+ * | UsingParamClause
2971
3029
*
2972
- * DefParamClause ::= ‘(’ [‘erased’] DefParams ‘)’ | UsingParamClause
2973
- * UsingParamClause ::= ‘(’ ‘using’ [‘erased’] (DefParams | ContextTypes) ‘)’
2974
- * DefParams ::= DefParam {‘,’ DefParam}
2975
- * DefParam ::= {Annotation} [‘inline’] Param
3030
+ * DefTermParamClause::= [nl] ‘(’ [DefTermParams] ‘)’
3031
+ * UsingParamClause ::= ‘(’ ‘using’ [‘erased’] (DefTermParams | ContextTypes) ‘)’
3032
+ * DefImplicitClause ::= [nl] ‘(’ ‘implicit’ DefTermParams ‘)’
3033
+ * DefTermParams ::= DefTermParam {‘,’ DefTermParam}
3034
+ * DefTermParam ::= {Annotation} [‘inline’] Param
2976
3035
*
2977
3036
* Param ::= id `:' ParamType [`=' Expr]
2978
3037
*
@@ -3070,7 +3129,7 @@ object Parsers {
3070
3129
}
3071
3130
3072
3131
/** ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ [‘implicit’] ClsParams ‘)’]
3073
- * DefParamClauses ::= {DefParamClause} [[nl] ‘(’ [‘implicit’] DefParams ‘)’]
3132
+ * TypelessClauses ::= TypelessClause {TypelessClause}
3074
3133
*
3075
3134
* @return The parameter definitions
3076
3135
*/
@@ -3322,9 +3381,9 @@ object Parsers {
3322
3381
}
3323
3382
3324
3383
/** DefDef ::= DefSig [‘:’ Type] ‘=’ Expr
3325
- * | this ParamClause ParamClauses `=' ConstrExpr
3384
+ * | this TypelessClauses [DefImplicitClause] `=' ConstrExpr
3326
3385
* DefDcl ::= DefSig `:' Type
3327
- * DefSig ::= id [DefTypeParamClause] DefParamClauses
3386
+ * DefSig ::= id [DefParamClauses] [DefImplicitClause]
3328
3387
* | ExtParamClause [nl] [‘.’] id DefParamClauses
3329
3388
*/
3330
3389
def defDefOrDcl (start : Offset , mods : Modifiers , numLeadParams : Int = 0 ): DefDef = atSpan(start, nameStart) {
@@ -3362,8 +3421,7 @@ object Parsers {
3362
3421
val mods1 = addFlag(mods, Method )
3363
3422
val ident = termIdent()
3364
3423
var name = ident.name.asTermName
3365
- val tparams = typeParamClauseOpt(ParamOwner .Def )
3366
- val vparamss = paramClauses(numLeadParams = numLeadParams)
3424
+ val paramss = typeOrTermParamClauses(ParamOwner .Def , numLeadParams = numLeadParams)
3367
3425
var tpt = fromWithinReturnType { typedOpt() }
3368
3426
if (migrateTo3) newLineOptWhenFollowedBy(LBRACE )
3369
3427
val rhs =
@@ -3381,7 +3439,7 @@ object Parsers {
3381
3439
accept(EQUALS )
3382
3440
expr()
3383
3441
3384
- val ddef = DefDef (name, joinParams(tparams, vparamss) , tpt, rhs)
3442
+ val ddef = DefDef (name, paramss , tpt, rhs)
3385
3443
if (isBackquoted(ident)) ddef.pushAttachment(Backquoted , ())
3386
3444
finalizeDef(ddef, mods1, start)
3387
3445
}
@@ -3643,7 +3701,7 @@ object Parsers {
3643
3701
finalizeDef(gdef, mods1, start)
3644
3702
}
3645
3703
3646
- /** Extension ::= ‘extension’ [DefTypeParamClause] {UsingParamClause} ‘(’ DefParam ‘)’
3704
+ /** Extension ::= ‘extension’ [DefTypeParamClause] {UsingParamClause} ‘(’ DefTermParam ‘)’
3647
3705
* {UsingParamClause} ExtMethods
3648
3706
*/
3649
3707
def extension (): ExtMethods =
0 commit comments