diff options
| -rw-r--r-- | exceptions.py | 3 | ||||
| -rw-r--r-- | lexer.py | 18 |
2 files changed, 14 insertions, 7 deletions
diff --git a/exceptions.py b/exceptions.py index 229ec88..8bbe000 100644 --- a/exceptions.py +++ b/exceptions.py @@ -8,3 +8,6 @@ class InterpretPanic(NebPanic): big_message += f" (got {arg})" super().__init__(big_message) +class LexError(NebPanic): + def __init__(self, message, line): + super().__init__(f"line {line}: {message}") @@ -1,10 +1,7 @@ from structs import TokenType, Token +from exceptions import LexError import sys -class LexError(BaseException): - - def __init__(self, message, line): - super().__init__(f"line {line}: {message}") types = { ":int": TokenType.INT_TYPE, @@ -146,12 +143,19 @@ def get_string(data, line): return Token(TokenType.STRING, str(string), str(string), line), counter + 1, offset def get_bool(data, line): - if len(data) >= 4 and data[:4] == "true": + counter = 0 + value = "" + while data[counter] not in SEPARATORS: + value += data[counter] + counter += 1 + if counter >= len(data): + break + if value == "true": return Token(TokenType.TRUE, "#true", True, line), 4 - elif len(data) >= 5 and data[:5] == "false": + elif value == "false": return Token(TokenType.FALSE, "#false", False, line), 5 else: - raise Exception("couldn't parse boolean") + raise LexError("couldn't parse boolean", line) def get_symbol(data, line): counter = 0 |
