Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ScannerTokens: symbolic infix check to common (#3608)
This way, this check will be available publically.
- Loading branch information
Showing
4 changed files
with
57 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 30 additions & 1 deletion
31
scalameta/tokens/shared/src/main/scala/scala/meta/tokens/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,32 @@ | ||
package scala.meta | ||
|
||
package object tokens extends tokens.Api | ||
import scala.annotation.tailrec | ||
import scala.meta.internal.tokens.Chars | ||
|
||
package object tokens extends tokens.Api { | ||
|
||
implicit class TokenExtensions(private val value: Token) extends AnyVal { | ||
@inline def isBackquoted: Boolean = value.text.isBackquoted | ||
@inline def isSymbolicInfixOperator: Boolean = | ||
value.isInstanceOf[Token.Ident] && isIdentSymbolicInfixOperator | ||
@inline def isIdentSymbolicInfixOperator: Boolean = value.text.isIdentSymbolicInfixOperator | ||
} | ||
|
||
implicit class StringExtensions(private val value: String) extends AnyVal { | ||
|
||
def isBackquoted: Boolean = value.startsWith("`") && value.endsWith("`") | ||
|
||
def isIdentSymbolicInfixOperator: Boolean = isBackquoted || { | ||
@tailrec | ||
def iter(idx: Int, nonEmpty: Boolean): Boolean = { | ||
val ch = value(idx) | ||
if (ch == '_') nonEmpty || idx > 0 && iter(idx - 1, false) | ||
else Chars.isOperatorPart(ch) && (idx == 0 || iter(idx - 1, true)) | ||
} | ||
|
||
val len = value.length | ||
len == 0 || iter(len - 1, false) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters