aboutsummaryrefslogtreecommitdiff
path: root/structs.py
diff options
context:
space:
mode:
authormryouse2022-06-04 03:13:30 +0000
committermryouse2022-06-04 03:13:30 +0000
commited78cd23f92b8b96dd7ffa3313be2262b0b29ff0 (patch)
tree34fd6ef2feeb82223e7e3ec7c5a79b5091d6ca08 /structs.py
parentb395d5d1cd122bb07017f23110f76249398a61bb (diff)
refactor: more literal types
Diffstat (limited to 'structs.py')
-rw-r--r--structs.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/structs.py b/structs.py
index 1e01949..bab9c13 100644
--- a/structs.py
+++ b/structs.py
@@ -67,12 +67,29 @@ class Token:
def __str__(self):
return f"{self.type_.name} {self.text} {self.line}"
+# Literals
class Literal:
def __init__(self, value):
self.value = value
def __str__(self):
+ return f"{self.value}:literal"
+
+class Int(Literal):
+ def __str__(self):
+ return f"{self.value}"
+
+class Float(Literal):
+ def __str__(self):
return f"{self.value}"
+class Bool(Literal):
+ def __str__(self):
+ return f"#{str(self.value).lower()}"
+
+class String(Literal):
+ def __str__(self):
+ return f'"{self.value}"'
+
class Type:
def __init__(self, name):
self.name = name
@@ -90,4 +107,4 @@ class List:
self.args = args
self.data = data
def __str__(self):
- return "(" + " ".join(f"{arg}" for arg in self.args) + ")"
+ return "(" + ",".join(f"{arg}" for arg in self.args) + ")"