1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-05-29 04:41:30 +00:00

Point at the end of the line if the error is something missing at the end of the line

This commit is contained in:
Karol Stasiak 2020-12-01 03:21:04 +01:00
parent 52c9da36b8
commit 7962a1d083
2 changed files with 11 additions and 2 deletions

View File

@ -62,7 +62,7 @@ abstract class MfParser[T](fileId: String, input: String, currentDirectory: Stri
parse parse
} }
private val lineStarts: Array[Int] = (0 +: input.zipWithIndex.filter(_._1 == '\n').map(_._2)).toArray private val lineStarts: Array[Int] = (-1 +: input.zipWithIndex.filter(_._1 == '\n').map(_._2).map(_+1)).toArray
def position(label: String = ""): P[Position] = Index.map(i => indexToPosition(i, label)) def position(label: String = ""): P[Position] = Index.map(i => indexToPosition(i, label))
@ -71,7 +71,7 @@ abstract class MfParser[T](fileId: String, input: String, currentDirectory: Stri
if (lineNumber < 0) { if (lineNumber < 0) {
lineNumber = - lineNumber - 2 lineNumber = - lineNumber - 2
} }
val columnNumber = i - lineStarts(lineNumber) val columnNumber = i - lineStarts(lineNumber) + 1
lineNumber += 1 lineNumber += 1
val newPosition = Position(fileId, lineNumber, columnNumber, i) val newPosition = Position(fileId, lineNumber, columnNumber, i)
if (newPosition.cursor > lastPosition.cursor) { if (newPosition.cursor > lastPosition.cursor) {

View File

@ -86,4 +86,13 @@ class ParserSuite extends FunSuite with Matchers {
|} |}
|""".stripMargin) |""".stripMargin)
} }
test("EOL error reporting") {
ShouldNotParse(
"""
|void main() {
| for i,
|}
|""".stripMargin)
}
} }