Skip to content

Commit c44c9bb

Browse files
authored
Merge pull request #4531 from fabianpage/fix-#4405
Fix #4405 REPL highlight for StringLiteral
2 parents 4f1945e + f811b7b commit c44c9bb

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ object SyntaxHighlighting {
7070
val n = takeChar()
7171
if (interpolationPrefixes.contains(n)) {
7272
// Interpolation prefixes are a superset of the keyword start chars
73-
val next = remaining.take(3).mkString
74-
if (next.startsWith("\"")) {
75-
newBuf += n
76-
prev = n
77-
if (remaining.nonEmpty) takeChar() // drop 1 for appendLiteral
78-
appendString('"', next == "\"\"\"")
73+
val (prefix, after) = remaining.span(interpolationPrefixes.contains)
74+
if (after.startsWith("\"")) {
75+
newBuf += n ++= prefix
76+
prev = prefix.lastOption.getOrElse(n)
77+
if (remaining.nonEmpty) takeChars(prefix.length + 1) // drop 1 for appendLiteral
78+
appendString('"', after.startsWith("\"\"\""), true)
7979
} else {
8080
if (n.isUpper && (keywordStart || prev == '.')) {
8181
appendWhile(n, !typeEnders.contains(_), typeDef)
@@ -116,7 +116,7 @@ object SyntaxHighlighting {
116116
case '@' =>
117117
appendWhile('@', !typeEnders.contains(_), annotation)
118118
case '\"' =>
119-
appendString('\"', multiline = remaining.take(2).mkString == "\"\"")
119+
appendString('\"', multiline = remaining.take(2).mkString == "\"\"", false)
120120
case '\'' =>
121121
appendSingleQuote('\'')
122122
case '`' =>
@@ -181,11 +181,10 @@ object SyntaxHighlighting {
181181
newBuf append NoColor
182182
}
183183

184-
def appendString(delim: Char, multiline: Boolean = false) = {
184+
def appendString(delim: Char, multiline: Boolean = false, inInterpolation: Boolean) = {
185185
var curr: Char = 0
186186
var continue = true
187187
var closing = 0
188-
val inInterpolation = interpolationPrefixes.contains(prev)
189188
newBuf append (LiteralColor + delim)
190189

191190
def shouldInterpolate =

compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class SyntaxHighlightingTests {
5050
def strings = {
5151
// For some reason we currently use literal color for string
5252
test("\"Hello\"", "<L|\"Hello\">")
53+
test("s\"Hello\"", "s<L|\"Hello\">")
54+
test("s\"Hello $name\"", "s<L|\"Hello <V|$name<L|\">")
55+
test("raw\"Hello\"", "raw<L|\"Hello\">")
56+
test("raw\"\"\"Hello\"\"\"", "raw<L|\"\"\"Hello\"\"\">")
5357
}
5458

5559
@Test

0 commit comments

Comments
 (0)