diff options
author | Martin Odersky <odersky@gmail.com> | 2015-06-25 12:50:59 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-06-25 12:51:18 +0200 |
commit | de1042ac04085b496b006c6567d8e737ca5d8ee7 (patch) | |
tree | 64301b956870f51e7bbbb303a09a70a80018ee70 | |
parent | d00572d159a3a15664afbf09d1ff914df4d2c512 (diff) | |
download | dotty-de1042ac04085b496b006c6567d8e737ca5d8ee7.tar.gz dotty-de1042ac04085b496b006c6567d8e737ca5d8ee7.tar.bz2 dotty-de1042ac04085b496b006c6567d8e737ca5d8ee7.zip |
Make columns start at 0.
Lines already start at 0, so columns should, too.
-rw-r--r-- | src/dotty/tools/dotc/reporting/ConsoleReporter.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/util/SourceFile.scala | 12 |
2 files changed, 9 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala index f07f43a63..26e6324eb 100644 --- a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala +++ b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala @@ -25,7 +25,7 @@ class ConsoleReporter( printMessage(pos.lineContents.stripLineEnd) def printColumnMarker(pos: SourcePosition) = - if (pos.exists) { printMessage(" " * (pos.column - 1) + "^") } + if (pos.exists) { printMessage(" " * pos.column + "^") } /** Prints the message. */ def printMessage(msg: String): Unit = { writer.print(msg + "\n"); writer.flush() } diff --git a/src/dotty/tools/dotc/util/SourceFile.scala b/src/dotty/tools/dotc/util/SourceFile.scala index 6e2ac7d79..5e8f85e28 100644 --- a/src/dotty/tools/dotc/util/SourceFile.scala +++ b/src/dotty/tools/dotc/util/SourceFile.scala @@ -72,7 +72,7 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) { def positionInUltimateSource(position: SourcePosition): SourcePosition = SourcePosition(underlying, position.pos shift start) - def isLineBreak(idx: Int) = + private def isLineBreak(idx: Int) = if (idx >= length) false else { val ch = content(idx) // don't identify the CR in CR LF as a line break, since LF will do. @@ -80,7 +80,7 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) { else isLineBreakChar(ch) } - def calculateLineIndices(cs: Array[Char]) = { + private def calculateLineIndices(cs: Array[Char]) = { val buf = new ArrayBuffer[Int] buf += 0 for (i <- 0 until cs.length) if (isLineBreak(i)) buf += i + 1 @@ -103,25 +103,29 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) { lastLine } + /** The index of the first character of the line containing position `offset` */ def startOfLine(offset: Int): Int = { require(offset >= 0) lineToOffset(offsetToLine(offset)) } + /** The start index of the line following the one containing position `offset` */ def nextLine(offset: Int): Int = lineToOffset(offsetToLine(offset) + 1 min lineIndices.length - 1) + /** The contents of the line containing position `offset` */ def lineContents(offset: Int): String = content.slice(startOfLine(offset), nextLine(offset)).mkString + /** The column corresponding to `offset`, starting at 0 */ def column(offset: Int): Int = { var idx = startOfLine(offset) var col = 0 while (idx != offset) { - col += (if (content(idx) == '\t') tabInc - col % tabInc else 1) + col += (if (content(idx) == '\t') (tabInc - col) % tabInc else 1) idx += 1 } - col + 1 + col } override def toString = file.toString |