1
0
mirror of https://github.com/KarolS/millfork.git synced 2025-08-07 12:25:40 +00:00

Some more defensive programming

This commit is contained in:
Karol Stasiak
2020-07-31 17:11:30 +02:00
parent 87d9884597
commit 89ff89bc48

View File

@@ -33,7 +33,8 @@ abstract class MfParser[T](fileId: String, input: String, currentDirectory: Stri
def toAst: Parsed[Program] = {
val parse = program.parse(input + "\n\n\n")
parse match {
case _:Failure[_, _] =>
case _: Failure[_, _] =>
if (lastPosition.cursor >= 0 && lastPosition.cursor < input.length) {
val c = input(lastPosition.cursor)
if (c >= 0x100 || c < 0x20 || c == '`') {
log.error("Invalid character U+%04X %s".format(c.toInt, Character.getName(c)), Some(lastPosition))
@@ -43,6 +44,7 @@ abstract class MfParser[T](fileId: String, input: String, currentDirectory: Stri
case _ =>
}
}
}
case _ =>
}
parse