summaryrefslogtreecommitdiff
path: root/projects/hackc/utils.py
blob: 4b9c9f05dfbf0ecd3e9d84b402deb71112a7e926 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from sys import stderr

EXIT_CODE_FILE_ERROR = 1
EXIT_CODE_INVALID_TOKEN = 2
EXIT_CODE_SYNTAX_ERROR = 4

# vim autoindent misbehaves if I type these verbatim in strings
LEFT_BRACE = "{"
RIGHT_BRACE = "}"
LEFT_PAREN = "("
RIGHT_PAREN = ")"

class JackSyntaxError(Exception):
    def __init__(self, msg, token):
        self.message = msg
        self.token = token
        super().__init__(msg)


def print_err(msg):
    print(msg, file=stderr)