@@ -307,6 +307,11 @@ object Parsers {
307
307
offset
308
308
}
309
309
310
+ def acceptColon (): Int =
311
+ val offset = in.offset
312
+ if in.isColon() then { in.nextToken(); offset }
313
+ else accept(COLON )
314
+
310
315
/** semi = nl {nl} | `;'
311
316
* nl = `\n' // where allowed
312
317
*/
@@ -860,7 +865,7 @@ object Parsers {
860
865
lookahead.nextToken()
861
866
skipParams()
862
867
skipParams()
863
- lookahead.token == COLON
868
+ lookahead.isColon()
864
869
865
870
def followingIsExtension () =
866
871
val next = in.lookahead.token
@@ -1377,7 +1382,7 @@ object Parsers {
1377
1382
imods = modifiers(funTypeArgMods)
1378
1383
val paramStart = in.offset
1379
1384
val ts = funArgType() match {
1380
- case Ident (name) if name != tpnme.WILDCARD && in.token == COLON =>
1385
+ case Ident (name) if name != tpnme.WILDCARD && in.isColon() =>
1381
1386
isValParamList = true
1382
1387
funArgTypesRest(
1383
1388
typedFunParam(paramStart, name.toTermName, imods),
@@ -1466,7 +1471,7 @@ object Parsers {
1466
1471
/** TypedFunParam ::= id ':' Type */
1467
1472
def typedFunParam (start : Offset , name : TermName , mods : Modifiers = EmptyModifiers ): ValDef =
1468
1473
atSpan(start) {
1469
- accept( COLON )
1474
+ acceptColon( )
1470
1475
makeParameter(name, typ(), mods)
1471
1476
}
1472
1477
@@ -1760,24 +1765,23 @@ object Parsers {
1760
1765
else atSpan((t.span union cbs.head.span).start) { ContextBounds (t, cbs) }
1761
1766
}
1762
1767
1763
- def contextBounds (pname : TypeName ): List [Tree ] = in.token match {
1764
- case COLON =>
1768
+ def contextBounds (pname : TypeName ): List [Tree ] =
1769
+ if in.isColon() then
1765
1770
atSpan(in.skipToken()) {
1766
1771
AppliedTypeTree (toplevelTyp(), Ident (pname))
1767
1772
} :: contextBounds(pname)
1768
- case VIEWBOUND =>
1773
+ else if in.token == VIEWBOUND then
1769
1774
report.errorOrMigrationWarning(
1770
1775
" view bounds `<%' are no longer supported, use a context bound `:' instead" ,
1771
1776
in.sourcePos())
1772
1777
atSpan(in.skipToken()) {
1773
1778
Function (Ident (pname) :: Nil , toplevelTyp())
1774
1779
} :: contextBounds(pname)
1775
- case _ =>
1780
+ else
1776
1781
Nil
1777
- }
1778
1782
1779
1783
def typedOpt (): Tree =
1780
- if ( in.token == COLON ) { in.nextToken(); toplevelTyp() }
1784
+ if in.isColon() then { in.nextToken(); toplevelTyp() }
1781
1785
else TypeTree ().withSpan(Span (in.lastOffset))
1782
1786
1783
1787
def typeDependingOn (location : Location ): Tree =
@@ -2194,6 +2198,7 @@ object Parsers {
2194
2198
* | SimpleExpr `.` MatchClause
2195
2199
* | SimpleExpr (TypeArgs | NamedTypeArgs)
2196
2200
* | SimpleExpr1 ArgumentExprs
2201
+ * | SimpleExpr1 `:` nl ArgumentExprs
2197
2202
* Quoted ::= ‘'’ ‘{’ Block ‘}’
2198
2203
* | ‘'’ ‘[’ Type ‘]’
2199
2204
*/
@@ -2341,10 +2346,9 @@ object Parsers {
2341
2346
lookahead.nextToken()
2342
2347
if (lookahead.token == RPAREN )
2343
2348
! fn.isInstanceOf [Trees .Apply [? ]] // allow one () as annotation argument
2344
- else if ( lookahead.token == IDENTIFIER ) {
2349
+ else if lookahead.token == IDENTIFIER then
2345
2350
lookahead.nextToken()
2346
- lookahead.token != COLON
2347
- }
2351
+ ! lookahead.isColon()
2348
2352
else in.canStartExprTokens.contains(lookahead.token)
2349
2353
}
2350
2354
}
@@ -2761,7 +2765,7 @@ object Parsers {
2761
2765
if allowed.contains(in.token)
2762
2766
|| in.isSoftModifier
2763
2767
&& localModifierTokens.subsetOf(allowed) // soft modifiers are admissible everywhere local modifiers are
2764
- && in.lookahead.token != COLON
2768
+ && ! in.lookahead.isColon()
2765
2769
then
2766
2770
val isAccessMod = accessModifierTokens contains in.token
2767
2771
val mods1 = addModifier(mods)
@@ -2929,7 +2933,7 @@ object Parsers {
2929
2933
}
2930
2934
atSpan(start, nameStart) {
2931
2935
val name = ident()
2932
- accept( COLON )
2936
+ acceptColon( )
2933
2937
if (in.token == ARROW && ofClass && ! mods.is(Local ))
2934
2938
syntaxError(VarValParametersMayNotBeCallByName (name, mods.is(Mutable )))
2935
2939
val tpt = paramType()
@@ -2967,7 +2971,7 @@ object Parsers {
2967
2971
val isParams =
2968
2972
! impliedMods.is(Given )
2969
2973
|| startParamTokens.contains(in.token)
2970
- || isIdent && (in.name == nme.inline || in.lookahead.token == COLON )
2974
+ || isIdent && (in.name == nme.inline || in.lookahead.isColon() )
2971
2975
if isParams then commaSeparated(() => param())
2972
2976
else contextTypes(ofClass, nparams)
2973
2977
checkVarArgsRules(clause)
@@ -3189,13 +3193,7 @@ object Parsers {
3189
3193
case _ =>
3190
3194
first :: Nil
3191
3195
}
3192
- def emptyType = TypeTree ().withSpan(Span (in.lastOffset))
3193
- val tpt =
3194
- if (in.token == COLON ) {
3195
- in.nextToken()
3196
- toplevelTyp()
3197
- }
3198
- else emptyType
3196
+ val tpt = typedOpt()
3199
3197
val rhs =
3200
3198
if tpt.isEmpty || in.token == EQUALS then
3201
3199
accept(EQUALS )
@@ -3274,15 +3272,7 @@ object Parsers {
3274
3272
var name = ident.name.asTermName
3275
3273
val tparams = typeParamClauseOpt(ParamOwner .Def )
3276
3274
val vparamss = paramClauses(numLeadParams = numLeadParams)
3277
- var tpt = fromWithinReturnType {
3278
- if in.token == COLONEOL then in.token = COLON
3279
- // a hack to allow
3280
- //
3281
- // def f():
3282
- // T
3283
- //
3284
- typedOpt()
3285
- }
3275
+ var tpt = fromWithinReturnType { typedOpt() }
3286
3276
if (migrateTo3) newLineOptWhenFollowedBy(LBRACE )
3287
3277
val rhs =
3288
3278
if in.token == EQUALS then
@@ -3526,7 +3516,7 @@ object Parsers {
3526
3516
else Nil
3527
3517
newLinesOpt()
3528
3518
val noParams = tparams.isEmpty && vparamss.isEmpty
3529
- if ! (name.isEmpty && noParams) then accept( COLON )
3519
+ if ! (name.isEmpty && noParams) then acceptColon( )
3530
3520
val parents =
3531
3521
if isSimpleLiteral then rejectWildcardType(annotType()) :: Nil
3532
3522
else constrApp() :: withConstrApps()
@@ -3568,7 +3558,7 @@ object Parsers {
3568
3558
isUsingClause(extParams)
3569
3559
do ()
3570
3560
leadParamss ++= paramClauses(givenOnly = true , numLeadParams = nparams)
3571
- if in.token == COLON then
3561
+ if in.isColon() then
3572
3562
syntaxError(" no `:` expected here" )
3573
3563
in.nextToken()
3574
3564
val methods =
0 commit comments