aboutsummaryrefslogtreecommitdiff
path: root/structs.py
diff options
context:
space:
mode:
Diffstat (limited to 'structs.py')
-rw-r--r--structs.py37
1 files changed, 4 insertions, 33 deletions
diff --git a/structs.py b/structs.py
index 72fabf7..adfd0e4 100644
--- a/structs.py
+++ b/structs.py
@@ -1,6 +1,7 @@
from dataclasses import dataclass
from enum import Enum, auto
from typing import Any
+from typeclass import TypeEnum
# tokens and types
# NOTE: this can probably be simplified
@@ -54,42 +55,12 @@ class TokenType(Enum):
# types
INT_TYPE = auto()
FLOAT_TYPE = auto()
+ NUMBER_TYPE = auto()
STRING_TYPE = auto()
ANY_TYPE = auto()
LIST_TYPE = auto()
-
-
-class TypeEnum(Enum):
- ANY = auto()
- STRING = auto()
- INT = auto()
- FLOAT = auto()
- NUMBER = auto()
- LIST = auto()
- LITERAL = auto()
- BOOL = auto()
-
- def __str__(self):
- return f":{self.name.lower()}"
-
-TYPE_HIERARCHY = { TypeEnum.ANY: None,
- TypeEnum.LITERAL: TypeEnum.ANY,
- TypeEnum.LIST: TypeEnum.ANY,
- TypeEnum.STRING: TypeEnum.LITERAL,
- TypeEnum.BOOL: TypeEnum.LITERAL,
- TypeEnum.NUMBER: TypeEnum.LITERAL,
- TypeEnum.INT: TypeEnum.NUMBER,
- TypeEnum.FLOAT: TypeEnum.NUMBER }
-
-def is_subtype_of(candidate, expected):
- if candidate == expected:
- return True
- parent = TYPE_HIERARCHY[candidate]
- while parent is not None:
- if parent == expected:
- return True
- parent = TYPE_HIERARCHY[parent]
- return False
+ LITERAL_TYPE = auto()
+ BOOL_TYPE = auto()
@dataclass
class Token: