diff options
| author | mryouse | 2022-06-18 01:47:06 +0000 |
|---|---|---|
| committer | mryouse | 2022-06-18 01:49:05 +0000 |
| commit | 8286580ef27d1434c3c2c52e71f19b4a42ec19cf (patch) | |
| tree | 182f97f4932969c3c99727f74465632c47b5d07c /lexer.py | |
| parent | e2b105629164a6df98c8b1ca63c5304ef697b2d1 (diff) | |
make LexError a NebPanic, and fix lexing errors with :bools
Diffstat (limited to 'lexer.py')
| -rw-r--r-- | lexer.py | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -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 |
