@@ -1554,105 +1554,71 @@ object Parsers {
15541554 in.buf(in.charOffset + 1 ) == '\' '
15551555 in.nextToken()
15561556
1557- if (isDedented) {
1558- // Collect all string parts and their offsets
1559- val stringParts = new ListBuffer [(String , Offset )]
1560- val interpolatedExprs = new ListBuffer [Tree ]
1561-
1562- var offsetCorrection = 3 // triple single quotes
1563- while (in.token == STRINGPART ) {
1564- val literalOffset = in.offset + offsetCorrection
1565- stringParts += ((in.strVal, literalOffset))
1566- offsetCorrection = 0
1567- in.nextToken()
1557+ // Collect all string parts and their offsets
1558+ val stringParts = new ListBuffer [(String , Offset )]
1559+ val interpolatedExprs = new ListBuffer [Tree ]
1560+
1561+ var offsetCorrection = if (isDedented) 3 else if (isTripleQuoted) 3 else 1
1562+ while (in.token == STRINGPART ) {
1563+ val literalOffset = in.offset + offsetCorrection
1564+ stringParts += ((in.strVal, literalOffset))
1565+ offsetCorrection = 0
1566+ in.nextToken()
15681567
1569- // Collect the interpolated expression
1570- interpolatedExprs += atSpan(in.offset) {
1571- if (in.token == IDENTIFIER )
1572- termIdent()
1573- else if (in.token == USCORE && inPattern) {
1574- in.nextToken()
1575- Ident (nme.WILDCARD )
1576- }
1577- else if (in.token == THIS ) {
1578- in.nextToken()
1579- This (EmptyTypeIdent )
1580- }
1581- else if (in.token == LBRACE )
1582- if (inPattern) Block (Nil , inBraces(pattern()))
1583- else expr()
1584- else {
1585- report.error(InterpolatedStringError (), source.atSpan(Span (in.offset)))
1586- EmptyTree
1587- }
1568+ // Collect the interpolated expression
1569+ interpolatedExprs += atSpan(in.offset) {
1570+ if (in.token == IDENTIFIER )
1571+ termIdent()
1572+ else if (in.token == USCORE && inPattern) {
1573+ in.nextToken()
1574+ Ident (nme.WILDCARD )
1575+ }
1576+ else if (in.token == THIS ) {
1577+ in.nextToken()
1578+ This (EmptyTypeIdent )
1579+ }
1580+ else if (in.token == LBRACE )
1581+ if (inPattern) Block (Nil , inBraces(pattern()))
1582+ else expr()
1583+ else {
1584+ report.error(InterpolatedStringError (), source.atSpan(Span (in.offset)))
1585+ EmptyTree
15881586 }
15891587 }
1588+ }
15901589
1591- // Get the final STRINGLIT
1592- val finalLiteral = if (in.token == STRINGLIT ) {
1593- val s = in.strVal
1594- val off = in.offset + offsetCorrection
1595- stringParts += ((s, off))
1596- in.nextToken()
1597- true
1598- } else false
1590+ // Get the final STRINGLIT
1591+ val finalLiteral = if (in.token == STRINGLIT ) {
1592+ val s = in.strVal
1593+ val off = in.offset + offsetCorrection
1594+ stringParts += ((s, off))
1595+ in.nextToken()
1596+ true
1597+ } else false
15991598
1600- // Now dedent all string parts based on the last one's closing indentation
1601- if (stringParts.nonEmpty) {
1599+ val dedentedParts =
1600+ if (! isDedented) stringParts
1601+ else {
16021602 val lastPart = stringParts.last._1
16031603 val closingIndent = extractClosingIndent(lastPart, in.offset)
1604-
1605- // Dedent all parts
1606- val dedentedParts = stringParts.zipWithIndex.map { case ((str, offset), index) =>
1607- (dedentString(str, in.offset, closingIndent, index == 0 , index == stringParts.length- 1 ), offset)
1604+ stringParts.zipWithIndex.map { case ((str, offset), index) =>
1605+ (dedentString(str, in.offset, closingIndent, index == 0 , index == stringParts.length - 1 ), offset)
16081606 }
1607+ }
16091608
1610- // Build the segments with dedented strings
1611- for (i <- 0 until dedentedParts.size - 1 ) {
1612- val (dedentedStr, offset) = dedentedParts(i)
1613- segmentBuf += Thicket (
1614- atSpan(offset, offset, offset + dedentedStr.length) { Literal (Constant (dedentedStr)) },
1615- interpolatedExprs(i)
1616- )
1617- }
1609+ // Build the segments with dedented strings
1610+ for (i <- 0 until dedentedParts.size - 1 ) {
1611+ val (dedentedStr, offset) = dedentedParts(i)
1612+ segmentBuf += Thicket (
1613+ atSpan(offset, offset, offset + dedentedStr.length) { Literal (Constant (dedentedStr)) },
1614+ interpolatedExprs(i)
1615+ )
1616+ }
16181617
1619- // Add the final literal if present
1620- if (finalLiteral) {
1621- val (dedentedStr, offset) = dedentedParts.last
1622- segmentBuf += atSpan(offset, offset, offset + dedentedStr.length) { Literal (Constant (dedentedStr)) }
1623- }
1624- }
1625- } else {
1626- // Non-dedented string: use original logic
1627- def nextSegment (literalOffset : Offset ) =
1628- segmentBuf += Thicket (
1629- literal(literalOffset, inPattern = inPattern, inStringInterpolation = true ),
1630- atSpan(in.offset) {
1631- if (in.token == IDENTIFIER )
1632- termIdent()
1633- else if (in.token == USCORE && inPattern) {
1634- in.nextToken()
1635- Ident (nme.WILDCARD )
1636- }
1637- else if (in.token == THIS ) {
1638- in.nextToken()
1639- This (EmptyTypeIdent )
1640- }
1641- else if (in.token == LBRACE )
1642- if (inPattern) Block (Nil , inBraces(pattern()))
1643- else expr()
1644- else {
1645- report.error(InterpolatedStringError (), source.atSpan(Span (in.offset)))
1646- EmptyTree
1647- }
1648- })
1649-
1650- var offsetCorrection = if isTripleQuoted then 3 else 1
1651- while (in.token == STRINGPART )
1652- nextSegment(in.offset + offsetCorrection)
1653- offsetCorrection = 0
1654- if (in.token == STRINGLIT )
1655- segmentBuf += literal(inPattern = inPattern, negOffset = in.offset + offsetCorrection, inStringInterpolation = true )
1618+ // Add the final literal if present
1619+ if (finalLiteral) {
1620+ val (dedentedStr, offset) = dedentedParts.last
1621+ segmentBuf += atSpan(offset, offset, offset + dedentedStr.length) { Literal (Constant (dedentedStr)) }
16561622 }
16571623
16581624 InterpolatedString (interpolator, segmentBuf.toList)
0 commit comments