Summary Files Commits Branches @commit @diff @stats
path: root / src / Token
diff options
context:
space:
mode:
Commitbeccf376ecbcc3819cc0d102b3635b6e5f39fa9e (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-11-01 17:30:08 +0200
Committer
 Syndamia <kamen@syndamia.com>
2025-11-01 17:30:08 +0200
Files9f3f46c787aa1bb8f1d0663223cef97e95433268 /src/Token
cool-self-hosted-beccf376ecbcc3819cc0d102b3635b6e5f39fa9e.tar
cool-self-hosted-beccf376ecbcc3819cc0d102b3635b6e5f39fa9e.tar.gz
cool-self-hosted-beccf376ecbcc3819cc0d102b3635b6e5f39fa9e.zip
Parent61f138b20a2a26a08155f414049acc0bb348ed31 (diff)
feat: Output token list
1 files changed, 56 insertions, 0 deletions
-rw-r--r--src/Token/TokenList.cl56
diff --git a/src/Token/TokenList.cl b/src/Token/TokenList.cl
new file mode 100644
index 0000000..514a8e6
--- /dev/null
+++ b/src/Token/TokenList.cl
@@ -0,0 +1,56 @@
+class TokenList inherits System {
+ token: IToken;
+ next: TokenList;
+
+ init(value: IToken, tail: Object) : TokenList {{
+ assert(not (isvoid value), "init", "value argument cannot be void!");
+ assert(isvoid token, "init", "List has already been initialised!");
+
+ token <- value;
+ if isvoid tail then
+ void
+ else
+ case tail of
+ tl: TokenList => next <- tl;
+ o: Object => assert(false, "init", "tail argument can be either a TokenList or void!");
+ esac
+ fi;
+
+ self;
+ }};
+
+ push(value: IToken) : TokenList {{
+ assert(not (isvoid value), "push", "value argument cannot be void!");
+
+ if isvoid token
+ then
+ token <- value
+ else if isvoid next
+ then
+ next <- (new TokenList).init(value, void)
+ else
+ next.push(value)
+ fi
+ fi;
+ self;
+ }};
+
+ out() : Object {{
+ if isvoid token
+ then
+ void
+ else
+ out_string("<")
+ .out_string(token.name())
+ .out_string(">")
+ fi;
+ if isvoid next
+ then
+ void
+ else {
+ out_string(" ");
+ next.out();
+ }
+ fi;
+ }};
+};