1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-06-26 11:29:28 +00:00

Better error messages when failing to parse array definitions (fixes #45)

This commit is contained in:
Karol Stasiak 2020-02-12 01:07:14 +01:00
parent 259d871786
commit 6e65cd1902
2 changed files with 26 additions and 1 deletions

View File

@ -166,6 +166,7 @@ abstract class MfParser[T](fileId: String, input: String, currentDirectory: Stri
bank <- bankDeclaration
flags <- variableFlags ~ HWS
typ <- identifier ~/ SWS
if typ != "array"
vars <- singleVariableDefinition.rep(min = 1, sep = "," ~/ HWS)
_ <- Before_EOL ~/ ""
} yield {
@ -229,8 +230,11 @@ abstract class MfParser[T](fileId: String, input: String, currentDirectory: Stri
val arrayFileContents: P[ArrayContents] = for {
p <- "file" ~ HWS ~/ "(" ~/ HWS ~/ position("file name")
filePath <- doubleQuotedString ~/ HWS
_ <- position("file start")
optStart <- ("," ~/ HWS ~/ literalAtom ~/ HWS ~/ Pass).?
_ <- position("slice length")
optLength <- ("," ~/ HWS ~/ literalAtom ~/ HWS ~/ Pass).?
_ <- position("closing parentheses")
_ <- ")" ~/ Pass
} yield {
val data = Files.readAllBytes(Paths.get(currentDirectory, filePath))
@ -314,7 +318,7 @@ abstract class MfParser[T](fileId: String, input: String, currentDirectory: Stri
const <- ("const".! ~ HWS).?
_ <- "array" ~ !letterOrDigit
elementType <- ("(" ~/ AWS ~/ identifier ~ AWS ~ ")").? ~/ HWS
name <- identifier ~ HWS
name <- identifier ~/ HWS
length <- ("[" ~/ AWS ~/ mfExpression(nonStatementLevel, false) ~ AWS ~ "]").? ~ HWS
alignment <- alignmentDeclaration(fastAlignmentForFunctions).? ~/ HWS
addr <- ("@" ~/ HWS ~/ mfExpression(1, false)).? ~/ HWS

View File

@ -614,4 +614,25 @@ class ArraySuite extends FunSuite with Matchers with AppendedClues {
""".stripMargin){ m =>
}
}
test("Error message test") {
ShouldNotParse(
"""
| const array stuff = file("", 0, 0, 0)
| void main () {
| }
""".stripMargin)
ShouldNotParse(
"""
| const array stuff = file()
| void main () {
| }
""".stripMargin)
ShouldNotParse(
"""
| const array stuff = file(1)
| void main () {
| }
""".stripMargin)
}
}