Skip to content

Commit 845522e

Browse files
committed
Fix span of xml literal with CR-NL
Simplified port of scala/scala@f428cc6
1 parent 1b299b3 commit 845522e

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ private[dotty] trait MarkupParserCommon {
232232
val rest = until.tail
233233

234234
while (true) {
235-
if (ch == head && peek(rest))
235+
if ch == head && peek(rest) then
236236
return handler(positioner(), sb.toString)
237237
else if (ch == SU)
238238
truncatedError("") // throws TruncatedXMLControl in compiler

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,18 @@ object MarkupParsers {
6868
if (ch == SU) throw TruncatedXMLControl
6969
else reportSyntaxError(msg)
7070

71-
var input : CharArrayReader = _
71+
var input: CharArrayReader = _
7272
def lookahead(): BufferedIterator[Char] =
7373
(input.buf drop input.charOffset).iterator.buffered
7474

7575
import parser.{ symbXMLBuilder => handle }
7676

77-
def curOffset : Int = input.charOffset - 1
78-
var tmppos : Span = NoSpan
77+
def curOffset: Int = input.lastCharOffset
78+
79+
var tmppos: Span = NoSpan
7980
def ch: Char = input.ch
8081
/** this method assign the next character to ch and advances in input */
81-
def nextch(): Unit = { input.nextChar() }
82+
def nextch(): Unit = input.nextChar()
8283

8384
protected def ch_returning_nextch: Char = {
8485
val result = ch; input.nextChar(); result
@@ -329,9 +330,9 @@ object MarkupParsers {
329330
case c @ TruncatedXMLControl =>
330331
ifTruncated(c.getMessage)
331332
case c @ (MissingEndTagControl | ConfusedAboutBracesControl) =>
332-
parser.syntaxError(c.getMessage + debugLastElem + ">", debugLastPos)
333+
parser.syntaxError(s"${c.getMessage}$debugLastElem>", debugLastPos)
333334
case _: ArrayIndexOutOfBoundsException =>
334-
parser.syntaxError("missing end tag in XML literal for <%s>" format debugLastElem, debugLastPos)
335+
parser.syntaxError(s"missing end tag in XML literal for <$debugLastElem>", debugLastPos)
335336
}
336337
finally parser.in.resume(saved)
337338

@@ -342,14 +343,13 @@ object MarkupParsers {
342343
}
343344

344345
/** Use a lookahead parser to run speculative body, and return the first char afterward. */
345-
private def charComingAfter(body: => Unit): Char = {
346+
private def charComingAfter(body: => Unit): Char =
346347
try {
347348
input = input.lookaheadReader()
348349
body
349350
ch
350351
}
351352
finally input = parser.in
352-
}
353353

354354
/** xLiteral = element { element }
355355
* @return Scala representation of this xml literal

0 commit comments

Comments
 (0)