aboutsummaryrefslogtreecommitdiff
path: root/tokens.py
diff options
context:
space:
mode:
authormryouse2022-05-10 04:27:12 +0000
committermryouse2022-05-10 04:27:12 +0000
commit12a2caa02af85f91f862d87ab0b518020751197c (patch)
tree954257414d225ba729f727cc8e472c6441ff99e0 /tokens.py
parentdb5564306399f0a3af97eb13808140542aa5b42c (diff)
make the literals print nicely
Diffstat (limited to 'tokens.py')
-rw-r--r--tokens.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tokens.py b/tokens.py
index 688fb7f..2d4387e 100644
--- a/tokens.py
+++ b/tokens.py
@@ -11,6 +11,9 @@ class NebType(Enum):
STRING = auto()
BOOL = auto()
+ def __str__(self):
+ return ":" + self.name.lower()
+
@dataclass
class NebToken:
pass
@@ -20,6 +23,14 @@ class NebLiteral(NebToken):
type_: NebType
value: T
+ def __str__(self):
+ fixed = str(self.value)
+ if self.type_ == NebType.BOOL:
+ fixed = f"#{str(self.value).lower()}"
+ elif self.type_ == NebType.STRING:
+ fixed = f'"{self.value}"'
+ return f"{fixed} <{self.type_}>"
+
class NebSeparator(NebToken):
pass