aboutsummaryrefslogtreecommitdiff
path: root/lexer.py
diff options
context:
space:
mode:
authormryouse2022-06-18 01:47:06 +0000
committermryouse2022-06-18 01:49:05 +0000
commit8286580ef27d1434c3c2c52e71f19b4a42ec19cf (patch)
tree182f97f4932969c3c99727f74465632c47b5d07c /lexer.py
parente2b105629164a6df98c8b1ca63c5304ef697b2d1 (diff)
make LexError a NebPanic, and fix lexing errors with :bools
Diffstat (limited to 'lexer.py')
-rw-r--r--lexer.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/lexer.py b/lexer.py
index bce3f51..11b5750 100644
--- a/lexer.py
+++ b/lexer.py
@@ -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