From 28e89dff46b23b2fd73704d46db96b86e7e35e3c Mon Sep 17 00:00:00 2001 From: mryouse Date: Sun, 22 May 2022 20:34:02 +0000 Subject: refactor: structs into their own file --- lexer.py | 67 +--------------------------------------------------------------- 1 file changed, 1 insertion(+), 66 deletions(-) (limited to 'lexer.py') diff --git a/lexer.py b/lexer.py index 3b93e41..c2460eb 100644 --- a/lexer.py +++ b/lexer.py @@ -1,6 +1,4 @@ -from dataclasses import dataclass -from enum import Enum, auto -from typing import Any +from structs import TokenType, Token import sys class LexError(BaseException): @@ -8,59 +6,6 @@ class LexError(BaseException): def __init__(self, message, line): super().__init__(f"line {line}: {message}") -class TokenType(Enum): - - PRINT = auto() - - OPEN_PAREN = auto() - CLOSE_PAREN = auto() - - EOF = auto() - - # literals - INT = auto() - FLOAT = auto() - STRING = auto() - TRUE = auto() - FALSE = auto() - - # arithmetic - PLUS = auto() - DASH = auto() - STAR = auto() - SLASH = auto() - - # strings - DOUBLE_QUOTE = auto() - - # comparison - GREATER = auto() - GREATER_EQUAL = auto() - LESS = auto() - LESS_EQUAL = auto() - EQUAL = auto() - NOT = auto() - AND = auto() - OR = auto() - - # flow - IF = auto() - FOR_COUNT = auto() - PIPE = auto() - - # keywords - DEF = auto() - LAMBDA = auto() - - # symbols - SYMBOL = auto() - - # types - INT_TYPE = auto() - FLOAT_TYPE = auto() - STRING_TYPE = auto() - ANY_TYPE = auto() - types = { ":int": TokenType.INT_TYPE, ":float": TokenType.FLOAT_TYPE, @@ -88,16 +33,6 @@ keywords = { "lambda": TokenType.LAMBDA } -@dataclass -class Token: - type_: TokenType - text: str - value: Any - line: int - - def __str__(self): - return f"{self.type_.name} {self.text} {self.line}" - WHITESPACE = [" ", "\n", "\t"] SEPARATORS = WHITESPACE + [")"] DIGITS = list("0123456789") -- cgit v1.2.3