diff options
| Commit | beccf376ecbcc3819cc0d102b3635b6e5f39fa9e (patch) | |
|---|---|---|
| Author | 2025-11-01 17:30:08 +0200 | |
| Committer | 2025-11-01 17:30:08 +0200 | |
| Files | 9f3f46c787aa1bb8f1d0663223cef97e95433268 | |
| cool-self-hosted-beccf376ecbcc3819cc0d102b3635b6e5f39fa9e.tar cool-self-hosted-beccf376ecbcc3819cc0d102b3635b6e5f39fa9e.tar.gz cool-self-hosted-beccf376ecbcc3819cc0d102b3635b6e5f39fa9e.zip | ||
| Parent | 61f138b20a2a26a08155f414049acc0bb348ed31 (diff) | |
feat: Output token list
3 files changed, 63 insertions, 0 deletions
| -rw-r--r-- | src/StringConsumer/StringConsumerEngine.cl | 6 | ||||
| -rw-r--r-- | src/Token/TokenList.cl | 56 | ||||
| -rw-r--r-- | src/main.cl | 1 |
diff --git a/src/StringConsumer/StringConsumerEngine.cl b/src/StringConsumer/StringConsumerEngine.cl index 6fe4403..6f07d2e 100644 --- a/src/StringConsumer/StringConsumerEngine.cl +++ b/src/StringConsumer/StringConsumerEngine.cl @@ -4,6 +4,7 @@ class StringConsumerEngine inherits System { ; str: String; + tl: TokenList <- new TokenList; init(code: String) : Object {{ assert(not (code = ""), "init", "input code cannot be empty!"); @@ -23,6 +24,7 @@ class StringConsumerEngine inherits System { case consumers.find(str) of c: IStringConsumer => { str <- str.substr(c.consumed_length(), str.length() - c.consumed_length()); + tl.push(c.token()); true; }; o: Object => false; @@ -37,4 +39,8 @@ class StringConsumerEngine inherits System { empty() : Bool { str = "" }; + + generated_tokens() : TokenList { + tl + }; }; 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; + }}; +}; diff --git a/src/main.cl b/src/main.cl index 4040444..3b839a9 100644 --- a/src/main.cl +++ b/src/main.cl @@ -7,5 +7,6 @@ class Main inherits System { loop assert(sce.try_consume(), "main", "couldn't consume entire input!") pool; + sce.generated_tokens().out(); }}; }; |
