@@ -911,6 +911,7 @@ object Parsers {
911
911
912
912
/** Are the next tokens a prefix of a formal parameter or given type?
913
913
* @pre: current token is LPAREN
914
+ * TODO: Drop once syntax has stabilized
914
915
*/
915
916
def followingIsParamOrGivenType () =
916
917
val lookahead = in.LookaheadScanner ()
@@ -944,7 +945,6 @@ object Parsers {
944
945
else
945
946
lookahead.token == SUBTYPE // TODO: remove
946
947
|| lookahead.isIdent(nme.as)
947
- || lookahead.token == WITH && lookahead.ch != Chars .LF // TODO: remove LF test
948
948
949
949
def followingIsExtension () =
950
950
val lookahead = in.LookaheadScanner ()
@@ -1344,8 +1344,8 @@ object Parsers {
1344
1344
* MonoFunType ::= FunArgTypes (‘=>’ | ‘?=>’) Type
1345
1345
* PolyFunType ::= HKTypeParamClause '=>' Type
1346
1346
* FunArgTypes ::= InfixType
1347
- * | `(' [ [ ‘['erased'] FunArgType {`,' FunArgType } ] `)'
1348
- * | '(' [ ‘['erased'] TypedFunParam {',' TypedFunParam } ')'
1347
+ * | `(' [ [ ‘[using]’ ‘[ 'erased'] FunArgType {`,' FunArgType } ] `)'
1348
+ * | '(' [ ‘[using]’ ‘[ 'erased'] TypedFunParam {',' TypedFunParam } ')'
1349
1349
*/
1350
1350
def typ (): Tree = {
1351
1351
val start = in.offset
@@ -2184,7 +2184,6 @@ object Parsers {
2184
2184
* | SimpleExpr `.' MatchClause
2185
2185
* | SimpleExpr (TypeArgs | NamedTypeArgs)
2186
2186
* | SimpleExpr1 ArgumentExprs
2187
- * | SimpleExpr ContextArguments
2188
2187
* Quoted ::= ‘'’ ‘{’ Block ‘}’
2189
2188
* | ‘'’ ‘[’ Type ‘]’
2190
2189
*/
@@ -2253,8 +2252,6 @@ object Parsers {
2253
2252
case DOT =>
2254
2253
in.nextToken()
2255
2254
simpleExprRest(selector(t), canApply = true )
2256
- case DOTWITH =>
2257
- simpleExprRest(contextArguments(t), canApply = true )
2258
2255
case LBRACKET =>
2259
2256
val tapp = atSpan(startOffset(t), in.offset) { TypeApply (t, typeArgs(namedOK = true , wildOK = false )) }
2260
2257
simpleExprRest(tapp, canApply = true )
@@ -2294,13 +2291,13 @@ object Parsers {
2294
2291
def exprsInParensOpt (): List [Tree ] =
2295
2292
if (in.token == RPAREN ) Nil else commaSeparated(exprInParens)
2296
2293
2297
- /** ParArgumentExprs ::= `(' [‘given ’] [ExprsInParens] `)'
2294
+ /** ParArgumentExprs ::= `(' [‘using ’] [ExprsInParens] `)'
2298
2295
* | `(' [ExprsInParens `,'] PostfixExpr `:' `_' `*' ')'
2299
2296
*/
2300
2297
def parArgumentExprs (): (List [Tree ], Boolean ) = inParens {
2301
2298
if in.token == RPAREN then
2302
2299
(Nil , false )
2303
- else if in.token == GIVEN then
2300
+ else if in.token == GIVEN || isIdent(nme.using) then
2304
2301
in.nextToken()
2305
2302
(commaSeparated(argumentExpr), true )
2306
2303
else
@@ -2331,7 +2328,7 @@ object Parsers {
2331
2328
else fn
2332
2329
}
2333
2330
2334
- /** ParArgumentExprss ::= {ParArgumentExprs | ContextArguments }
2331
+ /** ParArgumentExprss ::= {ParArgumentExprs}
2335
2332
*
2336
2333
* Special treatment for arguments to primary constructor annotations.
2337
2334
* (...) is considered an argument only if it does not look like a formal
@@ -2356,8 +2353,6 @@ object Parsers {
2356
2353
parArgumentExprss(
2357
2354
atSpan(startOffset(fn)) { mkApply(fn, parArgumentExprs()) }
2358
2355
)
2359
- else if in.token == DOTWITH then
2360
- parArgumentExprss(contextArguments(fn))
2361
2356
else fn
2362
2357
}
2363
2358
@@ -2387,14 +2382,6 @@ object Parsers {
2387
2382
else Block (stats, EmptyTree )
2388
2383
}
2389
2384
2390
- /** ContextArguments ::= ‘.’ ‘with’ ArgumentExprs */
2391
- def contextArguments (t : Tree ): Tree =
2392
- if in.token == DOTWITH then
2393
- atSpan(t.span.start, in.skipToken()) {
2394
- Apply (t, argumentExprs()._1).setGivenApply()
2395
- }
2396
- else t
2397
-
2398
2385
/** Guard ::= if PostfixExpr
2399
2386
*/
2400
2387
def guard (): Tree =
@@ -2886,23 +2873,22 @@ object Parsers {
2886
2873
def typeParamClauseOpt (ownerKind : ParamOwner .Value ): List [TypeDef ] =
2887
2874
if (in.token == LBRACKET ) typeParamClause(ownerKind) else Nil
2888
2875
2889
- /** AnnotTypes ::= AnnotType {‘,’ AnnotType}
2890
- * Types ::= Type {‘,’ Type}
2876
+ /** ContextTypes ::= Type {‘,’ Type}
2891
2877
*/
2892
- def givenTypes ( parseType : () => Tree , nparams : Int , ofClass : Boolean ): List [ValDef ] =
2893
- val tps = commaSeparated(parseType )
2878
+ def contextTypes ( ofClass : Boolean , nparams : Int ): List [ValDef ] =
2879
+ val tps = commaSeparated(typ )
2894
2880
var counter = nparams
2895
2881
def nextIdx = { counter += 1 ; counter }
2896
2882
val paramFlags = if ofClass then Private | Local | ParamAccessor else Param
2897
2883
tps.map(makeSyntheticParameter(nextIdx, _, paramFlags | Synthetic | Given ))
2898
2884
2899
- /** ClsParamClause ::= ‘(’ [‘erased’] ClsParams ‘)’
2900
- * GivenClsParamClause ::= 'with' ( ‘(’ (ClsParams | Types ) ‘)’ | AnnotTypes)
2885
+ /** ClsParamClause ::= ‘(’ [‘erased’] ClsParams ‘)’ | UsingClsParamClause
2886
+ * UsingClsParamClause ::= ‘(’ ‘using’ [‘erased’] (ClsParams | ContextTypes ) ‘)’
2901
2887
* ClsParams ::= ClsParam {‘,’ ClsParam}
2902
2888
* ClsParam ::= {Annotation}
2903
2889
*
2904
- * DefParamClause ::= ‘(’ [‘erased’] DefParams ‘)’
2905
- * GivenParamClause ::= ‘with’ (‘(’ (DefParams | Types ) ‘)’ | AnnotTypes)
2890
+ * DefParamClause ::= ‘(’ [‘erased’] DefParams ‘)’ | UsingParamClause
2891
+ * UsingParamClause ::= ‘(’ ‘using’ [‘erased’] (DefParams | ContextTypes ) ‘)’
2906
2892
* DefParams ::= DefParam {‘,’ DefParam}
2907
2893
* DefParam ::= {Annotation} [‘inline’] Param
2908
2894
*
@@ -2915,17 +2901,17 @@ object Parsers {
2915
2901
ofCaseClass : Boolean = false , // owner is a case class
2916
2902
prefix : Boolean = false , // clause precedes name of an extension method
2917
2903
givenOnly : Boolean = false , // only given parameters allowed
2918
- firstClause : Boolean = false , // clause is the first in regular list of clauses
2919
- prefixMods : Modifiers = EmptyModifiers // is `Given` if this is a with clause
2904
+ firstClause : Boolean = false // clause is the first in regular list of clauses
2920
2905
): List [ValDef ] = {
2921
- var impliedMods : Modifiers = prefixMods
2906
+ var impliedMods : Modifiers = EmptyModifiers
2922
2907
2923
- def impliedModOpt ( token : Token , mod : () => Mod ): Boolean =
2924
- if in.token == token then
2925
- impliedMods = addMod(impliedMods, atSpan(in.skipToken()) { mod() })
2926
- true
2908
+ def addParamMod ( mod : () => Mod ) = impliedMods = addMod(impliedMods, atSpan(in.skipToken()) { mod() })
2909
+
2910
+ def paramMods () =
2911
+ if in.token == IMPLICIT then addParamMod(() => Mod . Implicit ())
2927
2912
else
2928
- false
2913
+ if in.token == GIVEN || isIdent(nme.using) then addParamMod(() => Mod .Given ())
2914
+ if in.token == ERASED then addParamMod(() => Mod .Erased ())
2929
2915
2930
2916
def param (): ValDef = {
2931
2917
val start = in.offset
@@ -2984,32 +2970,22 @@ object Parsers {
2984
2970
val clause =
2985
2971
if prefix then param() :: Nil
2986
2972
else
2987
- if ! impliedModOpt(IMPLICIT , () => Mod .Implicit ()) then
2988
- impliedModOpt(GIVEN , () => Mod .Given ())
2989
- impliedModOpt(ERASED , () => Mod .Erased ())
2973
+ paramMods()
2990
2974
if givenOnly && ! impliedMods.is(Given ) then
2991
- syntaxError(" Normal parameter clause cannot follow context parameter clause " )
2975
+ syntaxError(" `using` expected " )
2992
2976
val isParams =
2993
2977
! impliedMods.is(Given )
2994
2978
|| startParamTokens.contains(in.token)
2995
2979
|| isIdent && (in.name == nme.inline || in.lookaheadIn(BitSet (COLON )))
2996
2980
if isParams then commaSeparated(() => param())
2997
- else givenTypes(typ , nparams, ofClass )
2981
+ else contextTypes(ofClass , nparams)
2998
2982
checkVarArgsRules(clause)
2999
2983
clause
3000
2984
}
3001
2985
}
3002
2986
3003
2987
/** ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ [‘implicit’] ClsParams ‘)’]
3004
- * | ClsParamClause ClsParamClauses
3005
- * | ClsParamClauses1
3006
- * ClsParamClauses1 ::= WithClsParamClause ClsParamClauses
3007
- * | AnnotTypes ClsParamClauses1ClsParamClauses
3008
2988
* DefParamClauses ::= {DefParamClause} [[nl] ‘(’ [‘implicit’] DefParams ‘)’]
3009
- * | DefParamClause DefParamClauses
3010
- * | DefParamClauses1
3011
- * DefParamClauses1 ::= WithCaramClause DefParamClauses
3012
- * | AnnotTypes DeParamClauses1
3013
2989
*
3014
2990
* @return The parameter definitions
3015
2991
*/
@@ -3019,33 +2995,18 @@ object Parsers {
3019
2995
3020
2996
def recur (firstClause : Boolean , nparams : Int ): List [List [ValDef ]] =
3021
2997
newLineOptWhenFollowedBy(LPAREN )
3022
- val prefixMods =
3023
- if in.token == WITH && in.ch != Chars .LF then // TODO: remove LF test
3024
- in.nextToken()
3025
- Modifiers (Given )
3026
- else
3027
- EmptyModifiers
3028
2998
if in.token == LPAREN then
3029
2999
val paramsStart = in.offset
3030
3000
val params = paramClause(
3031
3001
nparams,
3032
3002
ofClass = ofClass,
3033
3003
ofCaseClass = ofCaseClass,
3034
3004
givenOnly = givenOnly,
3035
- firstClause = firstClause,
3036
- prefixMods = prefixMods)
3005
+ firstClause = firstClause)
3037
3006
val lastClause = params.nonEmpty && params.head.mods.flags.is(Implicit )
3038
- val isGivenClause = prefixMods.is(Given )
3039
- || params.nonEmpty && params.head.mods.flags.is(Given )
3040
3007
params :: (
3041
3008
if lastClause then Nil
3042
3009
else recur(firstClause = false , nparams + params.length))
3043
- else if prefixMods.is(Given ) then
3044
- val params = givenTypes(annotType, nparams, ofClass)
3045
- params :: (
3046
- if in.token == WITH then recur(firstClause = false , nparams + params.length)
3047
- else Nil
3048
- )
3049
3010
else Nil
3050
3011
end recur
3051
3012
@@ -3090,8 +3051,8 @@ object Parsers {
3090
3051
3091
3052
/** ImportSelectors ::= id [‘=>’ id | ‘=>’ ‘_’] [‘,’ ImportSelectors]
3092
3053
* | WildCardSelector {‘,’ WildCardSelector}
3093
- * WildCardSelector ::= ‘given’ [ InfixType]
3094
- * | ‘_' [‘:’ InfixType]
3054
+ * WildCardSelector ::= ‘given’ (‘_' | InfixType)
3055
+ * | ‘_'
3095
3056
*/
3096
3057
def importSelectors (idOK : Boolean ): List [ImportSelector ] =
3097
3058
val selToken = in.token
@@ -3543,10 +3504,7 @@ object Parsers {
3543
3504
3544
3505
/** GivenDef ::= [GivenSig] [‘_’ ‘<:’] Type ‘=’ Expr
3545
3506
* | [GivenSig] ConstrApps [TemplateBody]
3546
- * GivenSig ::= [id] [DefTypeParamClause] {WithParamsOrTypes} ‘as’
3547
- * ExtParamClause ::= [DefTypeParamClause] DefParamClause
3548
- * ExtMethods ::= [nl] ‘{’ ‘def’ DefDef {semi ‘def’ DefDef} ‘}’
3549
- * WithParamsOrTypes ::= WithParamClause | AnnotTypes
3507
+ * GivenSig ::= [id] [DefTypeParamClause] {UsingParamClauses} ‘as’
3550
3508
*/
3551
3509
def givenDef (start : Offset , mods : Modifiers , instanceMod : Mod ) = atSpan(start, nameStart) {
3552
3510
var mods1 = addMod(mods, instanceMod)
@@ -3571,18 +3529,17 @@ object Parsers {
3571
3529
templ.body.foreach(checkExtensionMethod(tparams, _))
3572
3530
ModuleDef (name, templ)
3573
3531
else
3574
- val hasLabel = ! name.isEmpty && in.token == COLON || in. isIdent(nme.as)
3532
+ val hasLabel = ! name.isEmpty && in.token == COLON || isIdent(nme.as)
3575
3533
if hasLabel then in.nextToken()
3576
3534
val tparams = typeParamClauseOpt(ParamOwner .Def )
3577
3535
val paramsStart = in.offset
3578
3536
val vparamss =
3579
- if in.token == WITH && in.ch != Chars .LF // TODO: remove LF test
3580
- || in.token == LPAREN && followingIsParamOrGivenType()
3537
+ if in.token == LPAREN && followingIsParamOrGivenType()
3581
3538
then paramClauses()
3582
3539
else Nil
3583
3540
def checkAllGivens (vparamss : List [List [ValDef ]], what : String ) =
3584
3541
vparamss.foreach(_.foreach(vparam =>
3585
- if ! vparam.mods.is(Given ) then syntaxError(em " $what must be `given ` " , vparam.span)))
3542
+ if ! vparam.mods.is(Given ) then syntaxError(em " $what must be preceded by `using ` " , vparam.span)))
3586
3543
checkAllGivens(vparamss, " parameter of given instance" )
3587
3544
val parents =
3588
3545
if in.token == SUBTYPE && ! hasLabel then
@@ -3620,7 +3577,7 @@ object Parsers {
3620
3577
finalizeDef(gdef, mods1, start)
3621
3578
}
3622
3579
3623
- /** ExtensionDef ::= [id] ‘on’ ExtParamClause GivenParamClauses ExtMethods
3580
+ /** ExtensionDef ::= [id] ‘on’ ExtParamClause {UsingParamClause} ExtMethods
3624
3581
*/
3625
3582
def extensionDef (start : Offset , mods : Modifiers ): ModuleDef =
3626
3583
in.nextToken()
@@ -3644,8 +3601,7 @@ object Parsers {
3644
3601
val constrApp : () => Tree = () => {
3645
3602
val t = rejectWildcardType(annotType(), fallbackTree = Ident (nme.ERROR ))
3646
3603
// Using Ident(nme.ERROR) to avoid causing cascade errors on non-user-written code
3647
- if in.token == LPAREN || in.token == DOTWITH then parArgumentExprss(wrapNew(t))
3648
- else t
3604
+ if in.token == LPAREN then parArgumentExprss(wrapNew(t)) else t
3649
3605
}
3650
3606
3651
3607
/** ConstrApps ::= ConstrApp {(‘,’ | ‘with’) ConstrApp}
0 commit comments