Skip to content

Commit 9352ede

Browse files
committed
Reorganize multiline string handling, so that newlines are recognized correctly
1 parent 2c3212b commit 9352ede

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ object Scanners {
340340
if (next.token == EMPTY) {
341341
lastOffset = lastCharOffset
342342
currentRegion match {
343-
case InString(multiLine, _) => fetchStringPart(multiLine)
343+
case InString(multiLine, _) if lastToken != STRINGPART => fetchStringPart(multiLine)
344344
case _ => fetchToken()
345345
}
346346
if (token == ERROR) adjustSepRegions(STRINGLIT) // make sure we exit enclosing string literal
@@ -1097,13 +1097,7 @@ object Scanners {
10971097
getRawStringLit()
10981098
}
10991099

1100-
@annotation.tailrec private def getStringPart(multiLine: Boolean): Unit = {
1101-
def finishStringPart() = {
1102-
setStrVal()
1103-
token = STRINGPART
1104-
next.lastOffset = charOffset - 1
1105-
next.offset = charOffset - 1
1106-
}
1100+
@annotation.tailrec private def getStringPart(multiLine: Boolean): Unit =
11071101
if (ch == '"')
11081102
if (multiLine) {
11091103
nextRawChar()
@@ -1127,18 +1121,19 @@ object Scanners {
11271121
getStringPart(multiLine)
11281122
}
11291123
else if (ch == '{') {
1130-
finishStringPart()
1131-
nextRawChar()
1132-
next.token = LBRACE
1124+
setStrVal()
1125+
token = STRINGPART
11331126
}
11341127
else if (Character.isUnicodeIdentifierStart(ch) || ch == '_') {
1135-
finishStringPart()
1136-
while ({
1128+
setStrVal()
1129+
token = STRINGPART
1130+
next.lastOffset = charOffset - 1
1131+
next.offset = charOffset - 1
1132+
while
11371133
putChar(ch)
11381134
nextRawChar()
11391135
ch != SU && Character.isUnicodeIdentifierPart(ch)
1140-
})
1141-
()
1136+
do ()
11421137
finishNamed(target = next)
11431138
}
11441139
else
@@ -1157,7 +1152,7 @@ object Scanners {
11571152
getStringPart(multiLine)
11581153
}
11591154
}
1160-
}
1155+
end getStringPart
11611156

11621157
private def fetchStringPart(multiLine: Boolean) = {
11631158
offset = charOffset - 1

0 commit comments

Comments
 (0)