From ed78cd23f92b8b96dd7ffa3313be2262b0b29ff0 Mon Sep 17 00:00:00 2001 From: mryouse Date: Sat, 4 Jun 2022 03:13:30 +0000 Subject: refactor: more literal types --- structs.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'structs.py') 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) + ")" -- cgit v1.2.3