diff --git a/src/main/scala/millfork/parser/MfParser.scala b/src/main/scala/millfork/parser/MfParser.scala index a0e18cc8..29f8b3e0 100644 --- a/src/main/scala/millfork/parser/MfParser.scala +++ b/src/main/scala/millfork/parser/MfParser.scala @@ -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 diff --git a/src/test/scala/millfork/test/ArraySuite.scala b/src/test/scala/millfork/test/ArraySuite.scala index ef1e2abe..e26c406e 100644 --- a/src/test/scala/millfork/test/ArraySuite.scala +++ b/src/test/scala/millfork/test/ArraySuite.scala @@ -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) + } }