aboutsummaryrefslogtreecommitdiff
path: root/tokens.py
diff options
context:
space:
mode:
authormryouse2022-05-11 01:52:25 +0000
committermryouse2022-05-11 01:52:25 +0000
commit99a327a942028ec33e746a7ffbb2a3731cb4a370 (patch)
tree363b5af54cb1dc421b1e4195cad8af3c407fb4df /tokens.py
parentee318d229463b1b963862f3bda9e2cdddd604a67 (diff)
start enhancing types
Diffstat (limited to 'tokens.py')
-rw-r--r--tokens.py40
1 files changed, 25 insertions, 15 deletions
diff --git a/tokens.py b/tokens.py
index 2d4387e..38e669c 100644
--- a/tokens.py
+++ b/tokens.py
@@ -6,22 +6,27 @@ T = TypeVar("T", int, float, str, bool)
# classes
class NebType(Enum):
+ ANY = auto()
INT = auto()
FLOAT = auto()
+ NUMBER = auto()
STRING = auto()
BOOL = auto()
+ EXPR = auto()
+ SYMBOL = auto()
def __str__(self):
return ":" + self.name.lower()
@dataclass
class NebToken:
- pass
+ type_: NebType
-@dataclass
class NebLiteral(NebToken):
- type_: NebType
- value: T
+
+ def __init__(self, type_, value):
+ super().__init__(type_)
+ self.value = value
def __str__(self):
fixed = str(self.value)
@@ -31,7 +36,7 @@ class NebLiteral(NebToken):
fixed = f'"{self.value}"'
return f"{fixed} <{self.type_}>"
-class NebSeparator(NebToken):
+class NebSeparator():
pass
class NebOpen(NebSeparator):
@@ -40,14 +45,18 @@ class NebOpen(NebSeparator):
class NebClose(NebSeparator):
pass
-@dataclass
class NebSymbol(NebToken):
- name: str
-@dataclass
+ def __init__(self, name):
+ super().__init__(NebType.SYMBOL)
+ self.name = name
+
class NebExpression(NebToken):
- symbol: NebSymbol
- args: List[NebToken]
+
+ def __init__(self, symbol, args):
+ super().__init__(NebType.EXPR)
+ self.symbol = symbol
+ self.args = args
def maybe_sig(self):
out = []
@@ -58,11 +67,12 @@ class NebExpression(NebToken):
raise Exception("expressions must have a list of literals") #TODO not true
return " ".join(out)
-@dataclass
-class NebFunction(NebToken):
- name: str
- args: List[NebType]
- returns: NebType
+class NebFunction():
+
+ def __init__(self, name, args, returns):
+ self.name = name
+ self.args = args
+ self.returns = returns
def in_sig(self):
return " ".join(":" + x.name.lower() for x in self.args)