@@ -135,14 +135,16 @@ object Scanners {
135135 */
136136 protected def putChar (c : Char ): Unit = litBuf.append(c)
137137
138- /** Clear buffer and set name and token */
139- def finishNamed (idtoken : Token = IDENTIFIER , target : TokenData = this ): Unit = {
138+ /** Clear buffer and set name and token
139+ * If `target` is different from `this`, don't treat identifiers as end tokens
140+ */
141+ def finishNamed (idtoken : Token = IDENTIFIER , target : TokenData = this ): Unit =
140142 target.name = termName(litBuf.chars, 0 , litBuf.length)
141143 litBuf.clear()
142144 target.token = idtoken
143- if ( idtoken == IDENTIFIER )
144- target.token = toToken(target.name)
145- }
145+ if idtoken == IDENTIFIER then
146+ val converted = toToken(target.name)
147+ if converted != END || (target eq this ) then target.token = converted
146148
147149 /** The token for given `name`. Either IDENTIFIER or a keyword. */
148150 def toToken (name : SimpleName ): Token
@@ -656,6 +658,8 @@ object Scanners {
656658 () /* skip the trailing comma */
657659 else
658660 reset()
661+ case END =>
662+ if ! isEndMarker then token = IDENTIFIER
659663 case COLON =>
660664 if fewerBracesEnabled then observeColonEOL()
661665 case RBRACE | RPAREN | RBRACKET =>
@@ -666,6 +670,21 @@ object Scanners {
666670 }
667671 }
668672
673+ protected def isEndMarker : Boolean =
674+ if isAfterLineEnd then
675+ val endLine = source.offsetToLine(offset)
676+ val lookahead = new LookaheadScanner ():
677+ override def isEndMarker = false
678+ lookahead.nextToken()
679+ if endMarkerTokens.contains(lookahead.token)
680+ && source.offsetToLine(lookahead.offset) == endLine
681+ then
682+ lookahead.nextToken()
683+ if lookahead.token == EOF
684+ || source.offsetToLine(lookahead.offset) > endLine
685+ then return true
686+ false
687+
669688 /** Is there a blank line between the current token and the last one?
670689 * A blank line consists only of characters <= ' '.
671690 * @pre afterLineEnd().
0 commit comments