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