mirror of
https://github.com/KarolS/millfork.git
synced 2025-01-01 06:29:53 +00:00
Better error messages when failing to parse array definitions (fixes #45)
This commit is contained in:
parent
259d871786
commit
6e65cd1902
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user