Skip to content

Commit 48680cc

Browse files
committed
.
1 parent 40f397f commit 48680cc

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ object Scanners {
374374
case STRINGLIT =>
375375
currentRegion match {
376376
case InString(_, outer) => currentRegion = outer
377-
case InDedentedString(outer) => currentRegion = outer
377+
case InDedentedString(_, outer) => currentRegion = outer
378378
case _ =>
379379
}
380380
case _ =>
@@ -386,7 +386,9 @@ object Scanners {
386386
lastOffset = lastCharOffset
387387
currentRegion match
388388
case InString(multiLine, _) if lastToken != STRINGPART => fetchStringPart(multiLine)
389-
case InDedentedString(_) if lastToken != STRINGPART => fetchDedentedStringPart()
389+
case InDedentedString(quoteCount, _) if lastToken != STRINGPART =>
390+
offset = charOffset - 1
391+
getDedentedStringPartWithDelimiter(quoteCount)
390392
case _ => fetchToken()
391393
if token == ERROR then adjustSepRegions(STRINGLIT) // make sure we exit enclosing string literal
392394
else
@@ -997,10 +999,11 @@ object Scanners {
997999
if (token == INTERPOLATIONID) {
9981000
// For interpolation, handle as string part
9991001
nextRawChar()
1000-
getDedentedString(isInterpolated = true)
1001-
currentRegion = InDedentedString(currentRegion)
1002+
val quoteCount = getDedentedString(isInterpolated = true)
1003+
currentRegion = InDedentedString(quoteCount, currentRegion)
10021004
} else {
10031005
getDedentedString(isInterpolated = false)
1006+
// No need to store quoteCount for non-interpolated strings
10041007
}
10051008
}
10061009
else {
@@ -1295,8 +1298,9 @@ object Scanners {
12951298
* - All lines must be empty or indented further than closing delimiter
12961299
* - Supports extended delimiters (e.g., '''', ''''')
12971300
* @param isInterpolated If true, handles $ interpolation and returns STRINGPART tokens
1301+
* @return The quote count (number of quotes in the delimiter) for storing in the region
12981302
*/
1299-
private def getDedentedString(isInterpolated: Boolean): Unit = {
1303+
private def getDedentedString(isInterpolated: Boolean): Int = {
13001304
// For interpolated strings, we're already at the first character after '''
13011305
// For non-interpolated, we need to consume the first character
13021306
if (!isInterpolated) nextChar()
@@ -1312,7 +1316,7 @@ object Scanners {
13121316
if (ch != LF && ch != CR) {
13131317
error(em"dedented string literal must start with newline after opening quotes")
13141318
token = ERROR
1315-
return
1319+
return 0
13161320
}
13171321

13181322
// Skip the initial newline (CR LF or just LF)
@@ -1322,6 +1326,7 @@ object Scanners {
13221326
// For interpolated strings, check if we need to handle $ interpolation first
13231327
if (isInterpolated) {
13241328
getDedentedStringPartWithDelimiter(quoteCount)
1329+
quoteCount
13251330
} else {
13261331
// Collect all lines until we find the closing delimiter
13271332
val lines = scala.collection.mutable.ArrayBuffer[String]()
@@ -1442,6 +1447,8 @@ object Scanners {
14421447
token = STRINGLIT
14431448
}
14441449
}
1450+
1451+
quoteCount
14451452
}
14461453
}
14471454

@@ -1635,10 +1642,6 @@ object Scanners {
16351642
getStringPart(multiLine)
16361643
}
16371644

1638-
private def fetchDedentedStringPart() = {
1639-
offset = charOffset - 1
1640-
getDedentedString(isInterpolated = true)
1641-
}
16421645

16431646
private def isTripleQuote(): Boolean =
16441647
if (ch == '"') {
@@ -1958,7 +1961,7 @@ object Scanners {
19581961
end Region
19591962

19601963
case class InString(multiLine: Boolean, outer: Region) extends Region(RBRACE)
1961-
case class InDedentedString(outer: Region) extends Region(RBRACE)
1964+
case class InDedentedString(quoteCount: Int, outer: Region) extends Region(RBRACE)
19621965
case class InParens(prefix: Token, outer: Region) extends Region(prefix + 1)
19631966
case class InBraces(outer: Region) extends Region(RBRACE)
19641967
case class InCase(outer: Region) extends Region(OUTDENT)

0 commit comments

Comments
 (0)