From 26fa0559b0689a4647c38a2275c5880148248718 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 1 Nov 2025 18:13:33 +0200 Subject: feat(src/StringConsumer): Add higher order consumers, integer, binary operation and if keywords consumers 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. --- src/StringConsumer/IWordsConsumer.cl | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'src/StringConsumer/IWordsConsumer.cl') 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 -- cgit v1.3.1-26-gb76a