@@ -33,9 +33,6 @@ object Parsers {
33
33
import reporting .diagnostic .Message
34
34
import reporting .diagnostic .messages ._
35
35
36
- private inline val allowOldGiven = true
37
- private inline val allowOldExtension = true
38
-
39
36
case class OpInfo (operand : Tree , operator : Ident , offset : Offset )
40
37
41
38
class ParensCounters {
@@ -210,8 +207,7 @@ object Parsers {
210
207
} && ! in.isSoftModifierInModifierPosition
211
208
212
209
def isExprIntro : Boolean =
213
- if (in.token == GIVEN ) false
214
- else canStartExpressionTokens.contains(in.token) && ! in.isSoftModifierInModifierPosition
210
+ canStartExpressionTokens.contains(in.token) && ! in.isSoftModifierInModifierPosition
215
211
216
212
def isDefIntro (allowedMods : BitSet , excludedSoftModifiers : Set [TermName ] = Set .empty): Boolean =
217
213
in.token == AT ||
@@ -928,11 +924,6 @@ object Parsers {
928
924
}
929
925
else recur(operand())
930
926
}
931
- else if (in.token == GIVEN && allowOldGiven && ! isType) {
932
- val top1 = reduceStack(base, top, minInfixPrec, leftAssoc = true , nme.WITHkw , isType)
933
- assert(opStack `eq` base)
934
- recur(applyGiven(top1, operand))
935
- }
936
927
else reduceStack(base, top, minPrec, leftAssoc = true , in.name, isType)
937
928
938
929
recur(first)
@@ -1652,14 +1643,14 @@ object Parsers {
1652
1643
t
1653
1644
}
1654
1645
1655
- /** Expr ::= [ClosureMods ] FunParams =>' Expr
1646
+ /** Expr ::= [`implicit' ] FunParams =>' Expr
1656
1647
* | Expr1
1657
1648
* FunParams ::= Bindings
1658
1649
* | id
1659
1650
* | `_'
1660
1651
* ExprInParens ::= PostfixExpr `:' Type
1661
1652
* | Expr
1662
- * BlockResult ::= [ClosureMods ] FunParams =>' Block
1653
+ * BlockResult ::= [‘implicit’ ] FunParams =>' Block
1663
1654
* | Expr1
1664
1655
* Expr1 ::= [‘inline’] `if' `(' Expr `)' {nl} Expr [[semi] else Expr]
1665
1656
* | [‘inline’] `if' Expr `then' Expr [[semi] else Expr]
@@ -1689,10 +1680,10 @@ object Parsers {
1689
1680
1690
1681
def expr (location : Location .Value ): Tree = {
1691
1682
val start = in.offset
1692
- if closureMods.contains( in.token) && allowOldGiven then
1693
- implicitClosure (start, location, modifiers(closureMods ))
1683
+ if in.token == IMPLICIT then
1684
+ closure (start, location, modifiers(BitSet ( IMPLICIT ) ))
1694
1685
else if in.token == LPAREN && in.lookaheadIn(funTypeArgMods) then
1695
- implicitClosure (start, location, modifiers ())
1686
+ closure (start, location, Modifiers ())
1696
1687
else {
1697
1688
val saved = placeholderParams
1698
1689
placeholderParams = Nil
@@ -1951,10 +1942,10 @@ object Parsers {
1951
1942
}
1952
1943
else ident()
1953
1944
1954
- /** Expr ::= ClosureMods FunParams `=>' Expr
1945
+ /** Expr ::= [‘implicit’] FunParams `=>' Expr
1955
1946
* BlockResult ::= implicit id [`:' InfixType] `=>' Block // Scala2 only
1956
1947
*/
1957
- def implicitClosure (start : Int , location : Location .Value , implicitMods : Modifiers ): Tree =
1948
+ def closure (start : Int , location : Location .Value , implicitMods : Modifiers ): Tree =
1958
1949
closureRest(start, location, funParams(implicitMods, location))
1959
1950
1960
1951
def closureRest (start : Int , location : Location .Value , params : List [Tree ]): Tree =
@@ -2615,15 +2606,6 @@ object Parsers {
2615
2606
normalize(loop(start))
2616
2607
}
2617
2608
2618
- /** ClosureMods ::= { ‘implicit’ | ‘erased’ | ‘given’}
2619
- * FunTypeMods ::= { ‘erased’ | ‘given’}
2620
- */
2621
- val closureMods : BitSet =
2622
- if allowOldGiven then BitSet (GIVEN , IMPLICIT , ERASED )
2623
- else BitSet (IMPLICIT , ERASED )
2624
-
2625
- val funTypeMods : BitSet = BitSet (ERASED )
2626
-
2627
2609
val funTypeArgMods : BitSet = BitSet (GIVEN , ERASED )
2628
2610
2629
2611
/** Wrap annotation or constructor in New(...).<init> */
@@ -2735,9 +2717,9 @@ object Parsers {
2735
2717
ofClass : Boolean = false , // owner is a class
2736
2718
ofCaseClass : Boolean = false , // owner is a case class
2737
2719
prefix : Boolean = false , // clause precedes name of an extension method
2738
- firstClause : Boolean = false , // clause is the first in regular list of clauses
2739
- initialMods : Modifiers = EmptyModifiers ): List [ValDef ] = {
2740
- var impliedMods : Modifiers = initialMods
2720
+ firstClause : Boolean = false // clause is the first in regular list of clauses
2721
+ ): List [ValDef ] = {
2722
+ var impliedMods : Modifiers = EmptyModifiers
2741
2723
2742
2724
def impliedModOpt (token : Token , mod : () => Mod ): Boolean =
2743
2725
if in.token == token then
@@ -2826,47 +2808,35 @@ object Parsers {
2826
2808
*/
2827
2809
def paramClauses (ofClass : Boolean = false ,
2828
2810
ofCaseClass : Boolean = false ,
2829
- ofInstance : Boolean = false ): List [List [ValDef ]] = {
2811
+ ofInstance : Boolean = false ): List [List [ValDef ]] =
2830
2812
2831
- def recur (firstClause : Boolean , nparams : Int , contextualOnly : Boolean ): List [List [ValDef ]] = {
2832
- var initialMods = EmptyModifiers
2833
- val isNewLine = in.token == NEWLINE
2834
- newLineOptWhenFollowedBy(LPAREN )
2835
- if (in.token == GIVEN && allowOldGiven) {
2836
- in.nextToken()
2837
- initialMods |= Given
2838
- }
2839
- if (in.token == ERASED && allowOldGiven) {
2840
- in.nextToken()
2841
- initialMods |= Erased
2842
- }
2843
- var isGiven = initialMods.is(Given )
2813
+ def recur (firstClause : Boolean , nparams : Int , contextualOnly : Boolean ): List [List [ValDef ]] =
2844
2814
newLineOptWhenFollowedBy(LPAREN )
2845
- if in.token == LPAREN && ( ! isGiven || followingIsParamOrGivenType()) then
2815
+ if in.token == LPAREN then
2846
2816
val paramsStart = in.offset
2847
2817
val params = paramClause(
2848
2818
nparams,
2849
2819
ofClass = ofClass,
2850
2820
ofCaseClass = ofCaseClass,
2851
- firstClause = firstClause,
2852
- initialMods = initialMods)
2853
- params match
2854
- case param :: _ if param.mods.flags.is(Given ) => isGiven = true
2821
+ firstClause = firstClause)
2822
+ val isGiven = params match
2823
+ case param :: _ if param.mods.flags.is(Given ) => true
2855
2824
case _ =>
2856
2825
if contextualOnly then
2857
2826
syntaxError(
2858
2827
if ofInstance then em " parameters of instance definitions must be `given' clauses "
2859
2828
else em " normal parameters cannot come after `given' clauses " ,
2860
2829
paramsStart)
2830
+ false
2861
2831
val lastClause = params.nonEmpty && params.head.mods.flags.is(Implicit )
2862
- params :: (if (lastClause) Nil else recur(firstClause = false , nparams + params.length, isGiven))
2863
- else if isGiven then
2864
- val params = givenTypes(false , nparams, ofClass)
2865
- params :: recur(firstClause = false , nparams + params.length, isGiven)
2832
+ params :: (
2833
+ if lastClause then Nil
2834
+ else recur(firstClause = false , nparams + params.length, isGiven))
2866
2835
else Nil
2867
- }
2836
+ end recur
2837
+
2868
2838
recur(firstClause = true , 0 , ofInstance)
2869
- }
2839
+ end paramClauses
2870
2840
2871
2841
/* -------- DEFS ------------------------------------------- */
2872
2842
@@ -2880,9 +2850,7 @@ object Parsers {
2880
2850
*/
2881
2851
def importClause (leading : Token , mkTree : ImportConstr ): List [Tree ] = {
2882
2852
val offset = accept(leading)
2883
- val importGiven = allowOldGiven && in.token == GIVEN
2884
- if (importGiven) in.nextToken()
2885
- commaSeparated(importExpr(importGiven, mkTree)) match {
2853
+ commaSeparated(importExpr(mkTree)) match {
2886
2854
case t :: rest =>
2887
2855
// The first import should start at the start offset of the keyword.
2888
2856
val firstPos =
@@ -2899,12 +2867,12 @@ object Parsers {
2899
2867
* | ‘given’
2900
2868
* | ‘{’ ImportSelectors) ‘}’
2901
2869
*/
2902
- def importExpr (importGiven : Boolean , mkTree : ImportConstr ): () => Tree = {
2870
+ def importExpr (mkTree : ImportConstr ): () => Tree = {
2903
2871
2904
2872
/** '_' | 'given'
2905
2873
*/
2906
2874
def wildcardSelectorId () =
2907
- val name = if importGiven || in.token == GIVEN then nme.EMPTY else nme.WILDCARD
2875
+ val name = if in.token == GIVEN then nme.EMPTY else nme.WILDCARD
2908
2876
atSpan(in.skipToken()) { Ident (name) }
2909
2877
2910
2878
/** ImportSelectors ::= id [‘=>’ id | ‘=>’ ‘_’] [‘,’ ImportSelectors]
@@ -3404,37 +3372,9 @@ object Parsers {
3404
3372
/** SimpleConstrApp ::= AnnotType {ParArgumentExprs}
3405
3373
*/
3406
3374
val constrApp : () => Tree = () => {
3407
-
3408
- def isAnnotType (t : Tree ) = t match {
3409
- case _ : Ident
3410
- | _ : Select
3411
- | _ : AppliedTypeTree
3412
- | _ : Tuple
3413
- | _ : Parens
3414
- | _ : RefinedTypeTree
3415
- | _ : SingletonTypeTree
3416
- | _ : TypSplice
3417
- | _ : Annotated => true
3418
- case _ => false
3419
- }
3420
-
3421
- def givenArgs (t : Tree ): Tree =
3422
- if (in.token == GIVEN ) givenArgs(applyGiven(t, prefixExpr)) else t
3423
-
3424
- if (allowOldGiven && in.token == LPAREN )
3425
- inParens {
3426
- val t = toplevelTyp()
3427
- if (isAnnotType(t))
3428
- if (in.token == LPAREN ) givenArgs(parArgumentExprss(wrapNew(t)))
3429
- else if (in.token == GIVEN ) givenArgs(wrapNew(t))
3430
- else t
3431
- else Parens (t)
3432
- }
3433
- else {
3434
- val t = rejectWildcardType(annotType(), fallbackTree = Ident (nme.ERROR ))
3435
- // Using Ident(nme.ERROR) to avoid causing cascade errors on non-user-written code
3436
- if (in.token == LPAREN ) parArgumentExprss(wrapNew(t)) else t
3437
- }
3375
+ val t = rejectWildcardType(annotType(), fallbackTree = Ident (nme.ERROR ))
3376
+ // Using Ident(nme.ERROR) to avoid causing cascade errors on non-user-written code
3377
+ if in.token == LPAREN then parArgumentExprss(wrapNew(t)) else t
3438
3378
}
3439
3379
3440
3380
/** ConstrApps ::= ConstrApp {‘with’ ConstrApp} (to be deprecated in 3.1)
@@ -3682,29 +3622,12 @@ object Parsers {
3682
3622
setLastStatOffset()
3683
3623
if (in.token == IMPORT )
3684
3624
stats ++= importClause(IMPORT , Import )
3685
- else if (in.token == GIVEN ) {
3686
- val start = in.offset
3687
- val mods = modifiers(closureMods)
3688
- mods.mods match {
3689
- case givenMod :: Nil if ! isBindingIntro =>
3690
- stats += instanceDef(start, EmptyModifiers , Mod .Given ().withSpan(givenMod.span))
3691
- case _ =>
3692
- stats += implicitClosure(in.offset, Location .InBlock , mods)
3693
- }
3694
- }
3695
3625
else if (isExprIntro)
3696
3626
stats += expr(Location .InBlock )
3697
- else if (isDefIntro(localModifierTokens, excludedSoftModifiers = Set (nme.`opaque`)))
3698
- if (closureMods.contains(in.token)) {
3699
- val start = in.offset
3700
- var imods = modifiers(closureMods)
3701
- if (isBindingIntro)
3702
- stats += implicitClosure(start, Location .InBlock , imods)
3703
- else
3704
- stats +++= localDef(start, imods)
3705
- }
3706
- else
3707
- stats +++= localDef(in.offset)
3627
+ else if in.token == IMPLICIT && ! in.inModifierPosition() then
3628
+ stats += closure(in.offset, Location .InBlock , modifiers(BitSet (IMPLICIT )))
3629
+ else if isDefIntro(localModifierTokens, excludedSoftModifiers = Set (nme.`opaque`)) then
3630
+ stats +++= localDef(in.offset)
3708
3631
else if (! isStatSep && (in.token != CASE )) {
3709
3632
exitOnError = mustStartStat
3710
3633
syntaxErrorOrIncomplete(IllegalStartOfStatement (isModifier))
0 commit comments