@@ -135,10 +135,13 @@ object Scanners {
135135 */
136136 protected def putChar (c : Char ): Unit = litBuf.append(c)
137137
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.
140143 */
141- def finishNamed (idtoken : Token = IDENTIFIER , target : TokenData = this ): Unit =
144+ def finishNamedToken (idtoken : Token , target : TokenData ): Unit =
142145 target.name = termName(litBuf.chars, 0 , litBuf.length)
143146 litBuf.clear()
144147 target.token = idtoken
@@ -242,24 +245,18 @@ object Scanners {
242245 /** A buffer for comments */
243246 private val commentBuf = CharBuffer ()
244247
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
260258 if (idx >= 0 && idx <= lastKeywordStart) handleMigration(kwArray(idx))
261259 else IDENTIFIER
262- }
263260
264261 def newTokenData : TokenData = new TokenData {}
265262
@@ -1002,7 +999,7 @@ object Scanners {
1002999 getLitChars('`' )
10031000 if (ch == '`' ) {
10041001 nextChar()
1005- finishNamed (BACKQUOTED_IDENT )
1002+ finishNamedToken (BACKQUOTED_IDENT , target = this )
10061003 if (name.length == 0 )
10071004 error(" empty quoted identifier" )
10081005 else if (name == nme.WILDCARD )
@@ -1168,7 +1165,7 @@ object Scanners {
11681165 nextRawChar()
11691166 ch != SU && Character .isUnicodeIdentifierPart(ch)
11701167 do ()
1171- finishNamed( target = next)
1168+ finishNamedToken( IDENTIFIER , target = next)
11721169 }
11731170 else
11741171 error(" invalid string interpolation: `$$`, `$\" `, `$`ident or `$`BlockExpr expected" )
0 commit comments