From ee2e306f8919d937c8c93984c25f941dd1deaa7d Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 1 Nov 2025 17:07:06 +0200 Subject: fix(src/StringConsumer): Fix compparisons with word attr and length calculation --- src/StringConsumer/IWordsConsumer.cl | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/StringConsumer') 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; }}; -- cgit v1.3.1-23-gd82d