diff options
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 | 
