=========================== DATA patternAB = { sequence: [ {zeroOrMore: 'a'}, {text: 'b'}, ] } mod sequence{ [ mod zeroOrMore (text("a")), matcher text("b") ] ) ========================== HANDLERS case matcher:: mod sequence match = function(text, matcher) { loop fold(node-> matcher, 0->pos){ n = match(matcher, mid(text, pos, length(text))).// <-- every time length? if (pos == pos_FAIL || n == pos_FAIL){ pos_FAIL:: break } else { pos+n } } } case matcher:: mod zeroOrMore (Dereferenced) match= function(text, matcher){ matcherChild = matcher:: Dereferenced. //<--- extract child(unification) loop fold inf(0->pos, n==pos_FAIL){ //<--- infinite loop? n = match(matcherChild, mid(text, pos, length(text))). if (n == pos_FAIL:: break){ pos } else { pos+n } } } case matcher:: matcher text match = function(text, matcher) { pattern = matcher:: string. if (length(text)>0 && length(pattern) <= length(text) && mid(text, 0, length(pattern)) == pattern) { length(pattern); } else { pos_FAIL; } } match = function(text::string, pattern::string)::string{ n= match(pattern, text). if (n != pos_FAIL) {mid(text, 0, n)} else {text_FAIL} } ================================= CLIENT test = function(){ match(patternAB, "aaaaab"). match(patternAB, "baaaaa"). }