Summary Files Commits Branches @commit @diff @stats
path: root / src / StringConsumer / IWordsConsumer.cl
diff options
context:
space:
mode:
Commit26fa0559b0689a4647c38a2275c5880148248718 (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-11-01 18:13:33 +0200
Committer
 Syndamia <kamen@syndamia.com>
2025-11-01 18:13:33 +0200
Filesc6e3ad8bcb2a873607bc9d619f5cee22185f1765 /src/StringConsumer/IWordsConsumer.cl
cool-self-hosted-main.tar
cool-self-hosted-main.tar.gz
cool-self-hosted-main.zip
Parentbeccf376ecbcc3819cc0d102b3635b6e5f39fa9e (diff)
feat(src/StringConsumer): Add higher order consumers, integer, binary operation and if keywords consumers HEAD main
Higher order consumers are called that way because they use other (base) consumers in their logic. In a sense, the other consumers are parameters to the higher order consumers.
1 files changed, 27 insertions, 4 deletions
-rw-r--r--src/StringConsumer/IWordsConsumer.cl31
diff --git a/src/StringConsumer/IWordsConsumer.cl b/src/StringConsumer/IWordsConsumer.cl
index 4c184bf..a1c22ba 100644
--- a/src/StringConsumer/IWordsConsumer.cl
+++ b/src/StringConsumer/IWordsConsumer.cl
@@ -37,16 +37,37 @@ class WordList inherits System {
any_starts(s: String, start: Int) : Int {
if or(word = "", s.length() <= start)
- then 0
+ then
+ 0
+ else if and(s.length() < start + word.length(), not isvoid next)
+ then
+ next.any_starts(s, start)
else if s.substr(start, word.length()) = word
- then word.length()
+ then
+ word.length()
else if isvoid next
- then 0
- else next.any_starts(s, start)
+ then
+ 0
+ else
+ next.any_starts(s, start)
+ fi
fi
fi
fi
};
+
+ empty() : Bool {
+ if not (word = "")
+ then
+ false
+ else if isvoid next
+ then
+ true
+ else
+ next.empty()
+ fi
+ fi
+ };
};
class IWordsConsumer inherits IStringConsumer {
@@ -56,6 +77,8 @@ class IWordsConsumer inherits IStringConsumer {
let
word_length: Int <- 0
in {
+ assert(not matched_words.empty(), "consume", "object of class hasn't been initialised!");
+
consumed_length <- 0;
while 0 < (word_length <- matched_words.any_starts(s, consumed_length))
loop