diff options
| author | mryouse | 2022-06-16 04:09:26 +0000 |
|---|---|---|
| committer | mryouse | 2022-06-16 04:09:26 +0000 |
| commit | a072842248fe7324574bc7733a8c4255af56c855 (patch) | |
| tree | 86641bc9c500a2463b279a7968fa7e2532179632 /structs.py | |
| parent | 3b8834623d780316f81535029f2f8fee40736878 (diff) | |
refactor: take type hints from user in function args
Diffstat (limited to 'structs.py')
| -rw-r--r-- | structs.py | 37 |
1 files changed, 4 insertions, 33 deletions
@@ -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: |
