Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ object SyntaxHighlighting {
val n = takeChar()
if (interpolationPrefixes.contains(n)) {
// Interpolation prefixes are a superset of the keyword start chars
val next = remaining.take(3).mkString
if (next.startsWith("\"")) {
newBuf += n
prev = n
if (remaining.nonEmpty) takeChar() // drop 1 for appendLiteral
appendString('"', next == "\"\"\"")
val (prefix, after) = remaining.span(interpolationPrefixes.contains)
if (after.startsWith("\"")) {
newBuf += n ++= prefix
prev = prefix.lastOption.getOrElse(n)
if (remaining.nonEmpty) takeChars(prefix.length + 1) // drop 1 for appendLiteral
appendString('"', after.startsWith("\"\"\""), true)
} else {
if (n.isUpper && (keywordStart || prev == '.')) {
appendWhile(n, !typeEnders.contains(_), typeDef)
Expand Down Expand Up @@ -116,7 +116,7 @@ object SyntaxHighlighting {
case '@' =>
appendWhile('@', !typeEnders.contains(_), annotation)
case '\"' =>
appendString('\"', multiline = remaining.take(2).mkString == "\"\"")
appendString('\"', multiline = remaining.take(2).mkString == "\"\"", false)
case '\'' =>
appendSingleQuote('\'')
case '`' =>
Expand Down Expand Up @@ -181,11 +181,10 @@ object SyntaxHighlighting {
newBuf append NoColor
}

def appendString(delim: Char, multiline: Boolean = false) = {
def appendString(delim: Char, multiline: Boolean = false, inInterpolation: Boolean) = {
var curr: Char = 0
var continue = true
var closing = 0
val inInterpolation = interpolationPrefixes.contains(prev)
newBuf append (LiteralColor + delim)

def shouldInterpolate =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class SyntaxHighlightingTests {
def strings = {
// For some reason we currently use literal color for string
test("\"Hello\"", "<L|\"Hello\">")
test("s\"Hello\"", "s<L|\"Hello\">")
test("s\"Hello $name\"", "s<L|\"Hello <V|$name<L|\">")
test("raw\"Hello\"", "raw<L|\"Hello\">")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add one more with triple quotes: s"""Hello"""

test("raw\"\"\"Hello\"\"\"", "raw<L|\"\"\"Hello\"\"\">")
}

@Test
Expand Down