From 6a3e6aa5cc863f43c49e95d336b99dcf6713a640 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 1 Nov 2025 16:48:01 +0200 Subject: feat(StringConsumer)!: Rename IWordConsumer to IWordsConsumer --- src/StringConsumer/IWordConsumer.cl | 63 -------------------------------- src/StringConsumer/IWordsConsumer.cl | 63 ++++++++++++++++++++++++++++++++ src/StringConsumer/WhitespaceConsumer.cl | 2 +- 3 files changed, 64 insertions(+), 64 deletions(-) delete mode 100644 src/StringConsumer/IWordConsumer.cl create mode 100644 src/StringConsumer/IWordsConsumer.cl (limited to 'src/StringConsumer') diff --git a/src/StringConsumer/IWordConsumer.cl b/src/StringConsumer/IWordConsumer.cl deleted file mode 100644 index 1146710..0000000 --- a/src/StringConsumer/IWordConsumer.cl +++ /dev/null @@ -1,63 +0,0 @@ -class WordList inherits System { - word: String; - next: WordList; - - 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!"); - - word <- value; - if isvoid tail then - void - else - case tail of - wl: WordList => next <- wl; - o: Object => assert(false, "init", "tail argument can be either a ConsumerList or void!"); - esac - fi; - - self; - }}; - - push(value: String) : WordList {{ - assert(not (isvoid value), "push", "value argument cannot be void!"); - - if isvoid word - then - word <- value - else if isvoid next - then - next <- (new WordList).init(value, void) - else - next.push(value) - fi - fi; - self; - }}; - - any_starts(s: String, start: Int) : Bool { - if isvoid word - then false - else if s.substr(start, word.length()) = word - then true - else if isvoid next - then false - else next.any_starts(s, start) - fi - fi - fi - }; -}; - -class IWordConsumer inherits IStringConsumer { - matched_words: WordList <- new WordList; - - consume(s: String) : Int {{ - consumed_length <- 0; - while matched_words.any_starts(s, consumed_length) - loop - consumed_length <- consumed_length + 1 - pool; - consumed_length; - }}; -}; diff --git a/src/StringConsumer/IWordsConsumer.cl b/src/StringConsumer/IWordsConsumer.cl new file mode 100644 index 0000000..ac782b4 --- /dev/null +++ b/src/StringConsumer/IWordsConsumer.cl @@ -0,0 +1,63 @@ +class WordList inherits System { + word: String; + next: WordList; + + 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!"); + + word <- value; + if isvoid tail then + void + else + case tail of + wl: WordList => next <- wl; + o: Object => assert(false, "init", "tail argument can be either a ConsumerList or void!"); + esac + fi; + + self; + }}; + + push(value: String) : WordList {{ + assert(not (isvoid value), "push", "value argument cannot be void!"); + + if isvoid word + then + word <- value + else if isvoid next + then + next <- (new WordList).init(value, void) + else + next.push(value) + fi + fi; + self; + }}; + + any_starts(s: String, start: Int) : Bool { + if isvoid word + then false + else if s.substr(start, word.length()) = word + then true + else if isvoid next + then false + else next.any_starts(s, start) + fi + fi + fi + }; +}; + +class IWordsConsumer inherits IStringConsumer { + matched_words: WordList <- new WordList; + + consume(s: String) : Int {{ + consumed_length <- 0; + while matched_words.any_starts(s, consumed_length) + loop + consumed_length <- consumed_length + 1 + pool; + consumed_length; + }}; +}; diff --git a/src/StringConsumer/WhitespaceConsumer.cl b/src/StringConsumer/WhitespaceConsumer.cl index 8f20385..3a8c4dc 100644 --- a/src/StringConsumer/WhitespaceConsumer.cl +++ b/src/StringConsumer/WhitespaceConsumer.cl @@ -1,4 +1,4 @@ -class WhitespaceConsumer inherits IWordConsumer { +class WhitespaceConsumer inherits IWordsConsumer { init() : IStringConsumer {{ matched_words <- matched_words .push(" ") -- cgit v1.3.1-23-gd82d