Summary Files Commits Branches @commit @diff @stats
path: root / src / StringConsumer
diff options
context:
space:
mode:
Commitee2e306f8919d937c8c93984c25f941dd1deaa7d (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-11-01 17:07:06 +0200
Committer
 Syndamia <kamen@syndamia.com>
2025-11-01 17:07:06 +0200
Files35298f76dc36a557ec3aabe4799843efd4e2920c /src/StringConsumer
cool-self-hosted-ee2e306f8919d937c8c93984c25f941dd1deaa7d.tar
cool-self-hosted-ee2e306f8919d937c8c93984c25f941dd1deaa7d.tar.gz
cool-self-hosted-ee2e306f8919d937c8c93984c25f941dd1deaa7d.zip
Parent6a3e6aa5cc863f43c49e95d336b99dcf6713a640 (diff)
fix(src/StringConsumer): Fix compparisons with word attr and length calculation
1 files changed, 13 insertions, 10 deletions
-rw-r--r--src/StringConsumer/IWordsConsumer.cl23
diff --git a/src/StringConsumer/IWordsConsumer.cl b/src/StringConsumer/IWordsConsumer.cl
index ac782b4..cdd0186 100644
--- a/src/StringConsumer/IWordsConsumer.cl
+++ b/src/StringConsumer/IWordsConsumer.cl
@@ -4,7 +4,7 @@ class WordList inherits System {
init(value: String, tail: Object) : WordList {{
assert(not (isvoid value), "init", "value argument cannot be void!");
- assert(isvoid word, "init", "List has already been initialised!");
+ assert(word = "", "init", "List has already been initialised!");
word <- value;
if isvoid tail then
@@ -22,7 +22,7 @@ class WordList inherits System {
push(value: String) : WordList {{
assert(not (isvoid value), "push", "value argument cannot be void!");
- if isvoid word
+ if word = ""
then
word <- value
else if isvoid next
@@ -35,13 +35,13 @@ class WordList inherits System {
self;
}};
- any_starts(s: String, start: Int) : Bool {
- if isvoid word
- then false
+ any_starts(s: String, start: Int) : Int {
+ if word = ""
+ then 0
else if s.substr(start, word.length()) = word
- then true
+ then word.length()
else if isvoid next
- then false
+ then 0
else next.any_starts(s, start)
fi
fi
@@ -52,11 +52,14 @@ class WordList inherits System {
class IWordsConsumer inherits IStringConsumer {
matched_words: WordList <- new WordList;
- consume(s: String) : Int {{
+ consume(s: String) : Int {
+ let
+ word_length: Int <- 0
+ in {
consumed_length <- 0;
- while matched_words.any_starts(s, consumed_length)
+ while 0 < (word_length <- matched_words.any_starts(s, consumed_length))
loop
- consumed_length <- consumed_length + 1
+ consumed_length <- consumed_length + word_length
pool;
consumed_length;
}};