diff options
| Commit | 26fa0559b0689a4647c38a2275c5880148248718 (patch) | |
|---|---|---|
| Author | 2025-11-01 18:13:33 +0200 | |
| Committer | 2025-11-01 18:13:33 +0200 | |
| Files | c6e3ad8bcb2a873607bc9d619f5cee22185f1765 /src/StringConsumer/IWordsConsumer.cl | |
| cool-self-hosted-main.tar cool-self-hosted-main.tar.gz cool-self-hosted-main.zip | ||
| Parent | beccf376ecbcc3819cc0d102b3635b6e5f39fa9e (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.cl | 31 |
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 |
