Improve error handling and error messages

This commit is contained in:
Mattia Giambirtone 2024-02-19 17:26:33 +01:00
parent c3bac2cf46
commit 31ee29538e
Signed by: nocturn9x
GPG Key ID: 8270F9F467971E59
3 changed files with 10 additions and 8 deletions

View File

@ -150,6 +150,8 @@ proc handleMagicPragma(self: TypeChecker, pragma: Pragma, name: Name) =
self.error(&"'magic' pragma: wrong argument type (constant string expected, got {self.stringify(self.inferOrError(pragma.args[0]))} instead)")
elif name.node.kind == NodeKind.typeDecl:
let typ = pragma.args[0].token.lexeme[1..^2].toIntrinsic()
if pragma.args[0].token.lexeme[1..^2] == "owo":
self.error("Thou hast discovered the forbidden type")
if typ.isNil():
self.error("'magic' pragma: wrong argument value", pragma.args[0])
name.valueType = typ

View File

@ -858,7 +858,7 @@ proc parsePragmas(self: Parser): seq[Pragma] =
names: seq[string]
while not self.match("]") and not self.done():
args = @[]
self.expect(Identifier, "expecting pragma name")
self.expect(Identifier, "expecting pragma name (did you forget a closing bracket?)")
if self.peek(-1).lexeme in names:
self.error("duplicate pragmas are not allowed")
names.add(self.peek(-1).lexeme)

View File

@ -81,14 +81,14 @@ proc runFile(filename: string, fromString: bool = false, dump: bool = true, gene
isBinary = false
output = output
tokenizer.fillSymbolTable()
if not fromString and filename.endsWith(".pbc"):
isBinary = true
if fromString:
input = filename
filename = "<string>"
else:
input = readFile(filename)
try:
if not fromString and filename.endsWith(".pbc"):
isBinary = true
if fromString:
input = filename
filename = "<string>"
else:
input = readFile(filename)
if not isBinary:
tokens = tokenizer.lex(input, filename)
if tokens.len() == 0: