Summary Files Commits Branches @commit @diff @stats
path: root / src / StringConsumer
diff options
context:
space:
mode:
1 files changed, 13 insertions, 10 deletions
-rw-r--r--src/StringConsumer/IWordsConsumer.cl23
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;
}};