aboutsummaryrefslogtreecommitdiff
path: root/lexer.py
diff options
context:
space:
mode:
authormryouse2022-05-22 20:34:02 +0000
committermryouse2022-05-22 20:34:02 +0000
commit28e89dff46b23b2fd73704d46db96b86e7e35e3c (patch)
treebd6c8de5d5f302a52855d6896c21c6927d73398b /lexer.py
parent435934f89b9d3d15b7a22514a40a641d2fe74c31 (diff)
refactor: structs into their own file
Diffstat (limited to 'lexer.py')
-rw-r--r--lexer.py67
1 files changed, 1 insertions, 66 deletions
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")