aboutsummaryrefslogtreecommitdiff
path: root/neb/exceptions.py
blob: c34097a411bab57c9040cf13be41fcde1720f51a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class NebPanic(BaseException):
    pass

class InterpretPanic(NebPanic):
    def __init__(self, sym, msg, arg=None):
        if hasattr(sym, "line"):
            big_message = f"[{sym.line}] '{sym.name}': {msg}"
        else:
            big_message = f"[??] '{sym.name}': {msg}"
        if arg is not None:
            big_message += f" (got {arg})"
        super().__init__(big_message)

class LexError(NebPanic):
    def __init__(self, message, line):
        super().__init__(f"line {line}: {message}")

class ParseError(NebPanic):
    def __init__(self, message, line):
        super().__init__(f"line {line}: {message}")