@@ -135,10 +135,13 @@ object Scanners {
135
135
*/
136
136
protected def putChar (c : Char ): Unit = litBuf.append(c)
137
137
138
- /** Clear buffer and set name and token
139
- * If `target` is different from `this`, don't treat identifiers as end tokens
138
+ /** Finish an IDENTIFIER with `this.name`. */
139
+ inline def finishNamed (): Unit = finishNamedToken(IDENTIFIER , this )
140
+
141
+ /** Clear buffer and set name and token.
142
+ * If `target` is different from `this`, don't treat identifiers as end tokens.
140
143
*/
141
- def finishNamed (idtoken : Token = IDENTIFIER , target : TokenData = this ): Unit =
144
+ def finishNamedToken (idtoken : Token , target : TokenData ): Unit =
142
145
target.name = termName(litBuf.chars, 0 , litBuf.length)
143
146
litBuf.clear()
144
147
target.token = idtoken
@@ -242,24 +245,18 @@ object Scanners {
242
245
/** A buffer for comments */
243
246
private val commentBuf = CharBuffer ()
244
247
245
- private def handleMigration (keyword : Token ): Token =
246
- if scala3keywords.contains(keyword) && migrateTo3 then treatAsIdent()
247
- else keyword
248
-
249
- private def treatAsIdent (): Token =
250
- val name0 = name // don't capture the `name` var in the message closure, it may be null later
251
- report.errorOrMigrationWarning(
252
- i " $name0 is now a keyword, write ` $name0` instead of $name0 to keep it as an identifier " ,
253
- sourcePos())
254
- patch(source, Span (offset), " `" )
255
- patch(source, Span (offset + name.length), " `" )
256
- IDENTIFIER
257
-
258
- def toToken (name : SimpleName ): Token = {
259
- val idx = name.start
248
+ def toToken (identifier : SimpleName ): Token =
249
+ def handleMigration (keyword : Token ): Token =
250
+ if scala3keywords.contains(keyword) && migrateTo3 then
251
+ val what = tokenString(keyword)
252
+ report.errorOrMigrationWarning(i " $what is now a keyword, write ` $what` instead of $what to keep it as an identifier " , sourcePos())
253
+ patch(source, Span (offset), " `" )
254
+ patch(source, Span (offset + identifier.length), " `" )
255
+ IDENTIFIER
256
+ else keyword
257
+ val idx = identifier.start
260
258
if (idx >= 0 && idx <= lastKeywordStart) handleMigration(kwArray(idx))
261
259
else IDENTIFIER
262
- }
263
260
264
261
def newTokenData : TokenData = new TokenData {}
265
262
@@ -1002,7 +999,7 @@ object Scanners {
1002
999
getLitChars('`' )
1003
1000
if (ch == '`' ) {
1004
1001
nextChar()
1005
- finishNamed (BACKQUOTED_IDENT )
1002
+ finishNamedToken (BACKQUOTED_IDENT , target = this )
1006
1003
if (name.length == 0 )
1007
1004
error(" empty quoted identifier" )
1008
1005
else if (name == nme.WILDCARD )
@@ -1168,7 +1165,7 @@ object Scanners {
1168
1165
nextRawChar()
1169
1166
ch != SU && Character .isUnicodeIdentifierPart(ch)
1170
1167
do ()
1171
- finishNamed( target = next)
1168
+ finishNamedToken( IDENTIFIER , target = next)
1172
1169
}
1173
1170
else
1174
1171
error(" invalid string interpolation: `$$`, `$\" `, `$`ident or `$`BlockExpr expected" )
0 commit comments