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

EXIT_CODE_FILE_ERROR = 1
EXIT_CODE_INVALID_TOKEN = 2
EXIT_CODE_SYNTAX_ERROR = 4
EXIT_CODE_EOF = 7

# 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)