Improve error handling and error messages
This commit is contained in:
parent
c3bac2cf46
commit
31ee29538e
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
14
src/main.nim
14
src/main.nim
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue