Skip to content

Commit 8462122

Browse files
committed
Fix span of xml literal with CR-NL
Forward port scala/scala@f428cc6
1 parent 6a62bb7 commit 8462122

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

compiler/src/dotty/tools/dotc/parsing/xml/MarkupParsers.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ object MarkupParsers {
7474

7575
import parser.{ symbXMLBuilder => handle }
7676

77-
def curOffset : Int = input.charOffset - 1
77+
def curOffset : Int =
78+
val res = input.charOffset - 1
79+
if res > 0 && input.buf(res) == '\n' && input.buf(res-1) == '\r' then res - 1 else res
80+
7881
var tmppos : Span = NoSpan
7982
def ch: Char = input.ch
8083
/** this method assign the next character to ch and advances in input */
@@ -342,14 +345,14 @@ object MarkupParsers {
342345
}
343346

344347
/** Use a lookahead parser to run speculative body, and return the first char afterward. */
345-
private def charComingAfter(body: => Unit): Char = {
348+
private def charComingAfter(body: => Unit): Char =
349+
val saved = input
346350
try {
347351
input = input.lookaheadReader()
348352
body
349353
ch
350354
}
351-
finally input = parser.in
352-
}
355+
finally input = saved
353356

354357
/** xLiteral = element { element }
355358
* @return Scala representation of this xml literal
@@ -361,7 +364,6 @@ object MarkupParsers {
361364

362365
val ts = new ArrayBuffer[Tree]
363366
val start = curOffset
364-
tmppos = Span(curOffset) // Iuli: added this line, as it seems content_LT uses tmppos when creating trees
365367
content_LT(ts)
366368

367369
// parse more XML?

0 commit comments

Comments
 (0)