1
0
mirror of https://github.com/KarolS/millfork.git synced 2025-01-01 06:29:53 +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,14 +33,16 @@ 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[_, _] =>
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))
Confusables.map.get(c) match {
case Some(ascii) =>
log.info(s"Did you mean: $ascii")
case _ =>
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))
Confusables.map.get(c) match {
case Some(ascii) =>
log.info(s"Did you mean: $ascii")
case _ =>
}
}
}
case _ =>