@@ -77,6 +77,9 @@ object Scanners {
77
77
78
78
/** Is current token first one after a newline? */
79
79
def isAfterLineEnd : Boolean = lineOffset >= 0
80
+
81
+ def isOperator =
82
+ token == IDENTIFIER && isOperatorPart(name(name.length - 1 ))
80
83
}
81
84
82
85
abstract class ScannerCommon (source : SourceFile )(using Context ) extends CharArrayReader with TokenData {
@@ -348,12 +351,27 @@ object Scanners {
348
351
&& (isWhitespace(ch) || ch == LF )
349
352
&& ! pastBlankLine
350
353
&& {
354
+ // Is current lexeme assumed to start an expression?
355
+ // This is the case if the lexime is one of the tokens that
356
+ // starts an expression. Furthermore, if the previous token is
357
+ // in backticks, the lexeme may not be a binary operator.
358
+ // I.e. in
359
+ //
360
+ // a
361
+ // `x` += 1
362
+ //
363
+ // `+=` is not assumed to start an expression since it follows an identifier
364
+ // in backticks and is a binary operator. Hence, `x` is not classified as a
365
+ // leading infix operator.
366
+ def assumeStartsExpr (lexeme : TokenData ) =
367
+ canStartExprTokens.contains(lexeme.token)
368
+ && (token != BACKQUOTED_IDENT || ! lexeme.isOperator || nme.raw.isUnary(lexeme.name))
351
369
val lookahead = LookaheadScanner ()
352
370
lookahead.allowLeadingInfixOperators = false
353
371
// force a NEWLINE a after current token if it is on its own line
354
372
lookahead.nextToken()
355
- canStartExprTokens.contains (lookahead.token )
356
- || lookahead.token == NEWLINE && canStartExprTokens.contains (lookahead.next.token )
373
+ assumeStartsExpr (lookahead)
374
+ || lookahead.token == NEWLINE && assumeStartsExpr (lookahead.next)
357
375
}
358
376
&& {
359
377
if migrateTo3 then
0 commit comments