Skip to content

Commit 3bc1ff2

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 09c681e commit 3bc1ff2

File tree

3 files changed

+22
-28
lines changed

3 files changed

+22
-28
lines changed

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

+18-19
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} | `;'
@@ -890,7 +890,7 @@ object Parsers {
890890
lookahead.nextToken()
891891
skipParams()
892892
skipParams()
893-
lookahead.isColon()
893+
lookahead.isColon
894894

895895
def followingIsExtension() =
896896
val next = in.lookahead.token
@@ -1460,7 +1460,7 @@ object Parsers {
14601460
val paramStart = in.offset
14611461
val ts = in.currentRegion.withCommasExpected {
14621462
funArgType() match
1463-
case Ident(name) if name != tpnme.WILDCARD && in.isColon() =>
1463+
case Ident(name) if name != tpnme.WILDCARD && in.isColon =>
14641464
isValParamList = true
14651465
commaSeparatedRest(
14661466
typedFunParam(paramStart, name.toTermName, imods),
@@ -1867,7 +1867,7 @@ object Parsers {
18671867
}
18681868

18691869
def contextBounds(pname: TypeName): List[Tree] =
1870-
if in.isColon() then
1870+
if in.isColon then
18711871
atSpan(in.skipToken()) {
18721872
AppliedTypeTree(toplevelTyp(), Ident(pname))
18731873
} :: contextBounds(pname)
@@ -1882,7 +1882,7 @@ object Parsers {
18821882
Nil
18831883

18841884
def typedOpt(): Tree =
1885-
if in.isColon() then { in.nextToken(); toplevelTyp() }
1885+
if in.isColon then { in.nextToken(); toplevelTyp() }
18861886
else TypeTree().withSpan(Span(in.lastOffset))
18871887

18881888
def typeDependingOn(location: Location): Tree =
@@ -2110,8 +2110,8 @@ object Parsers {
21102110
else expr1Rest(postfixExpr(location), location)
21112111
end expr1
21122112

2113-
def expr1Rest(t: Tree, location: Location): Tree = in.token match
2114-
case EQUALS =>
2113+
def expr1Rest(t: Tree, location: Location): Tree =
2114+
if in.token == EQUALS then
21152115
t match
21162116
case Ident(_) | Select(_, _) | Apply(_, _) | PrefixOp(_, _) =>
21172117
atSpan(startOffset(t), in.skipToken()) {
@@ -2120,12 +2120,11 @@ object Parsers {
21202120
}
21212121
case _ =>
21222122
t
2123-
case COLONop | COLONfollow =>
2123+
else if in.isColon then
21242124
in.nextToken()
21252125
ascription(t, location)
2126-
case _ =>
2126+
else
21272127
t
2128-
end expr1Rest
21292128

21302129
def ascription(t: Tree, location: Location): Tree = atSpan(startOffset(t)) {
21312130
in.token match {
@@ -2354,7 +2353,7 @@ object Parsers {
23542353
case _ =>
23552354
if isLiteral then
23562355
literal()
2357-
else if in.isColon() then
2356+
else if in.isColon then
23582357
syntaxError(IllegalStartSimpleExpr(tokenString(in.token)))
23592358
in.nextToken()
23602359
simpleExpr(location)
@@ -2381,7 +2380,7 @@ object Parsers {
23812380
case USCORE =>
23822381
atSpan(startOffset(t), in.skipToken()) { PostfixOp(t, Ident(nme.WILDCARD)) }
23832382
case _ =>
2384-
if in.isColon() && location == Location.InParens && followingIsLambdaParams() then
2383+
if in.isColon && location == Location.InParens && followingIsLambdaParams() then
23852384
t match
23862385
case id @ Ident(name) =>
23872386
if name.is(WildcardParamName) then
@@ -2485,7 +2484,7 @@ object Parsers {
24852484
!fn.isInstanceOf[Trees.Apply[?]] // allow one () as annotation argument
24862485
else if lookahead.token == IDENTIFIER then
24872486
lookahead.nextToken()
2488-
!lookahead.isColon()
2487+
!lookahead.isColon
24892488
else in.canStartExprTokens.contains(lookahead.token)
24902489
}
24912490
}
@@ -2718,7 +2717,7 @@ object Parsers {
27182717
*/
27192718
def pattern1(location: Location = Location.InPattern): Tree =
27202719
val p = pattern2()
2721-
if in.token == COLONop || in.token == COLONfollow then
2720+
if in.isColon then
27222721
in.nextToken()
27232722
ascription(p, location)
27242723
else p
@@ -2919,7 +2918,7 @@ object Parsers {
29192918
if allowed.contains(in.token)
29202919
|| in.isSoftModifier
29212920
&& localModifierTokens.subsetOf(allowed) // soft modifiers are admissible everywhere local modifiers are
2922-
&& !in.lookahead.isColon()
2921+
&& !in.lookahead.isColon
29232922
then
29242923
val isAccessMod = accessModifierTokens contains in.token
29252924
val mods1 = addModifier(mods)
@@ -3126,7 +3125,7 @@ object Parsers {
31263125
val isParams =
31273126
!impliedMods.is(Given)
31283127
|| startParamTokens.contains(in.token)
3129-
|| isIdent && (in.name == nme.inline || in.lookahead.isColon())
3128+
|| isIdent && (in.name == nme.inline || in.lookahead.isColon)
31303129
if isParams then commaSeparated(() => param())
31313130
else contextTypes(ofClass, nparams, impliedMods)
31323131
checkVarArgsRules(clause)
@@ -3739,7 +3738,7 @@ object Parsers {
37393738
isUsingClause(extParams)
37403739
do ()
37413740
leadParamss ++= paramClauses(givenOnly = true, numLeadParams = nparams)
3742-
if in.isColon() then
3741+
if in.isColon then
37433742
syntaxError("no `:` expected here")
37443743
in.nextToken()
37453744
val methods: List[Tree] =
@@ -3949,7 +3948,7 @@ object Parsers {
39493948
*/
39503949
def selfType(): ValDef =
39513950
if (in.isIdent || in.token == THIS)
3952-
&& in.lookahead.token == COLONop && followingIsSelfType()
3951+
&& in.lookahead.isColon && followingIsSelfType()
39533952
|| in.lookahead.token == ARROW
39543953
then
39553954
atSpan(in.offset) {
@@ -3959,7 +3958,7 @@ object Parsers {
39593958
nme.WILDCARD
39603959
else ident()
39613960
val selfTpt =
3962-
if in.token == COLONfollow then
3961+
if in.isColon then
39633962
in.nextToken()
39643963
infixType()
39653964
else

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

+3-8
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

+1-1
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)