~deciduously/nlox

nlox/src/nloxpkg/loxerror.nim -rw-r--r-- 504 bytes
0f2f20d1Ben Lovy Scanner 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#! Error logging

type
    LoxError* = ref object of RootObj
        had_error*: bool

proc new_lox_error*(): LoxError =
    LoxError(had_error: false)

# Error reporting helper
method report(self: LoxError, line: int, where: string, message: string) {.base.} =
    stderr.writeLine("[line " & $line & "] Error" & where & ": " & message)
    self.had_error = true

# Error reporting with line number
method error*(self: LoxError, line: int, message: string) {.base.} =
    self.report(line, "", message)