diff options
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 |
