Skip to content

Commit 69c4ad5

Browse files
committed
Remove side-effect in isColon
Since we now convert to COLONeol only on demand, there's no need to conert back in `isColon`.
1 parent d3670a6 commit 69c4ad5

File tree

3 files changed

+22
-28
lines changed

3 files changed

+22
-28
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ object Parsers {
311311

312312
def acceptColon(): Int =
313313
val offset = in.offset
314-
if in.isColon() then { in.nextToken(); offset }
314+
if in.isColon then { in.nextToken(); offset }
315315
else accept(COLONop)
316316

317317
/** semi = nl {nl} | `;'
@@ -888,7 +888,7 @@ object Parsers {
888888
lookahead.nextToken()
889889
skipParams()
890890
skipParams()
891-
lookahead.isColon()
891+
lookahead.isColon
892892

893893
def followingIsExtension() =
894894
val next = in.lookahead.token
@@ -1458,7 +1458,7 @@ object Parsers {
14581458
val paramStart = in.offset
14591459
val ts = in.currentRegion.withCommasExpected {
14601460
funArgType() match
1461-
case Ident(name) if name != tpnme.WILDCARD && in.isColon() =>
1461+
case Ident(name) if name != tpnme.WILDCARD && in.isColon =>
14621462
isValParamList = true
14631463
commaSeparatedRest(
14641464
typedFunParam(paramStart, name.toTermName, imods),
@@ -1876,7 +1876,7 @@ object Parsers {
18761876
}
18771877

18781878
def contextBounds(pname: TypeName): List[Tree] =
1879-
if in.isColon() then
1879+
if in.isColon then
18801880
atSpan(in.skipToken()) {
18811881
AppliedTypeTree(toplevelTyp(), Ident(pname))
18821882
} :: contextBounds(pname)
@@ -1891,7 +1891,7 @@ object Parsers {
18911891
Nil
18921892

18931893
def typedOpt(): Tree =
1894-
if in.isColon() then { in.nextToken(); toplevelTyp() }
1894+
if in.isColon then { in.nextToken(); toplevelTyp() }
18951895
else TypeTree().withSpan(Span(in.lastOffset))
18961896

18971897
def typeDependingOn(location: Location): Tree =
@@ -2119,8 +2119,8 @@ object Parsers {
21192119
else expr1Rest(postfixExpr(location), location)
21202120
end expr1
21212121

2122-
def expr1Rest(t: Tree, location: Location): Tree = in.token match
2123-
case EQUALS =>
2122+
def expr1Rest(t: Tree, location: Location): Tree =
2123+
if in.token == EQUALS then
21242124
t match
21252125
case Ident(_) | Select(_, _) | Apply(_, _) | PrefixOp(_, _) =>
21262126
atSpan(startOffset(t), in.skipToken()) {
@@ -2129,12 +2129,11 @@ object Parsers {
21292129
}
21302130
case _ =>
21312131
t
2132-
case COLONop | COLONfollow =>
2132+
else if in.isColon then
21332133
in.nextToken()
21342134
ascription(t, location)
2135-
case _ =>
2135+
else
21362136
t
2137-
end expr1Rest
21382137

21392138
def ascription(t: Tree, location: Location): Tree = atSpan(startOffset(t)) {
21402139
in.token match {
@@ -2363,7 +2362,7 @@ object Parsers {
23632362
case _ =>
23642363
if isLiteral then
23652364
literal()
2366-
else if in.isColon() then
2365+
else if in.isColon then
23672366
syntaxError(IllegalStartSimpleExpr(tokenString(in.token)))
23682367
in.nextToken()
23692368
simpleExpr(location)
@@ -2390,7 +2389,7 @@ object Parsers {
23902389
case USCORE =>
23912390
atSpan(startOffset(t), in.skipToken()) { PostfixOp(t, Ident(nme.WILDCARD)) }
23922391
case _ =>
2393-
if in.isColon() && location == Location.InParens && followingIsLambdaParams() then
2392+
if in.isColon && location == Location.InParens && followingIsLambdaParams() then
23942393
t match
23952394
case id @ Ident(name) =>
23962395
if name.is(WildcardParamName) then
@@ -2494,7 +2493,7 @@ object Parsers {
24942493
!fn.isInstanceOf[Trees.Apply[?]] // allow one () as annotation argument
24952494
else if lookahead.token == IDENTIFIER then
24962495
lookahead.nextToken()
2497-
!lookahead.isColon()
2496+
!lookahead.isColon
24982497
else in.canStartExprTokens.contains(lookahead.token)
24992498
}
25002499
}
@@ -2727,7 +2726,7 @@ object Parsers {
27272726
*/
27282727
def pattern1(location: Location = Location.InPattern): Tree =
27292728
val p = pattern2()
2730-
if in.token == COLONop || in.token == COLONfollow then
2729+
if in.isColon then
27312730
in.nextToken()
27322731
ascription(p, location)
27332732
else p
@@ -2928,7 +2927,7 @@ object Parsers {
29282927
if allowed.contains(in.token)
29292928
|| in.isSoftModifier
29302929
&& localModifierTokens.subsetOf(allowed) // soft modifiers are admissible everywhere local modifiers are
2931-
&& !in.lookahead.isColon()
2930+
&& !in.lookahead.isColon
29322931
then
29332932
val isAccessMod = accessModifierTokens contains in.token
29342933
val mods1 = addModifier(mods)
@@ -3135,7 +3134,7 @@ object Parsers {
31353134
val isParams =
31363135
!impliedMods.is(Given)
31373136
|| startParamTokens.contains(in.token)
3138-
|| isIdent && (in.name == nme.inline || in.lookahead.isColon())
3137+
|| isIdent && (in.name == nme.inline || in.lookahead.isColon)
31393138
if isParams then commaSeparated(() => param())
31403139
else contextTypes(ofClass, nparams, impliedMods)
31413140
checkVarArgsRules(clause)
@@ -3748,7 +3747,7 @@ object Parsers {
37483747
isUsingClause(extParams)
37493748
do ()
37503749
leadParamss ++= paramClauses(givenOnly = true, numLeadParams = nparams)
3751-
if in.isColon() then
3750+
if in.isColon then
37523751
syntaxError("no `:` expected here")
37533752
in.nextToken()
37543753
val methods: List[Tree] =
@@ -3958,7 +3957,7 @@ object Parsers {
39583957
*/
39593958
def selfType(): ValDef =
39603959
if (in.isIdent || in.token == THIS)
3961-
&& in.lookahead.token == COLONop && followingIsSelfType()
3960+
&& in.lookahead.isColon && followingIsSelfType()
39623961
|| in.lookahead.token == ARROW
39633962
then
39643963
atSpan(in.offset) {
@@ -3968,7 +3967,7 @@ object Parsers {
39683967
nme.WILDCARD
39693968
else ident()
39703969
val selfTpt =
3971-
if in.token == COLONfollow then
3970+
if in.isColon then
39723971
in.nextToken()
39733972
infixType()
39743973
else

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,8 @@ object Scanners {
7575
def isNestedStart = token == LBRACE || token == INDENT
7676
def isNestedEnd = token == RBRACE || token == OUTDENT
7777

78-
/** Is token a COLON, after having converted COLONeol to COLON?
79-
* The conversion means that indentation is not significant after `:`
80-
* anymore. So, warning: this is a side-effecting operation.
81-
*/
82-
def isColon() =
83-
if token == COLONeol then token = COLONop
84-
token == COLONop || token == COLONfollow
78+
def isColon =
79+
token == COLONop || token == COLONfollow || token == COLONeol
8580

8681
/** Is current token first one after a newline? */
8782
def isAfterLineEnd: Boolean = lineOffset >= 0
@@ -1192,7 +1187,7 @@ object Scanners {
11921187
isSoftModifier && inModifierPosition()
11931188

11941189
def isSoftModifierInParamModifierPosition: Boolean =
1195-
isSoftModifier && lookahead.token != COLONop && lookahead.token != COLONfollow
1190+
isSoftModifier && !lookahead.isColon
11961191

11971192
def isErased: Boolean = isIdent(nme.erased) && erasedEnabled
11981193

compiler/src/dotty/tools/dotc/parsing/Tokens.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ object Tokens extends TokensCommon {
283283

284284
final val endMarkerTokens = identifierTokens | BitSet(IF, WHILE, FOR, MATCH, TRY, NEW, THROW, GIVEN, VAL, THIS)
285285

286-
final val colonEOLPredecessors = BitSet(RPAREN, RBRACKET, BACKQUOTED_IDENT, THIS, SUPER, QUOTEID, STRINGLIT, NEW)
286+
final val colonEOLPredecessors = BitSet(RPAREN, RBRACKET, BACKQUOTED_IDENT, THIS, SUPER, QUOTEID, STRINGLIT)
287287

288288
final val closingParens = BitSet(RPAREN, RBRACKET, RBRACE)
289289

0 commit comments

Comments
 (0)