Base pattern for matching a repeated element.
abstract class base repeat element[readonly value element type]
if index == 0 && !match empty()
else
implements reversible pattern[element type]
extends base pattern[element type]
abstract boolean match empty()
implement implicit boolean call(readonly list[element type] the list)
Check whether the given list can be a start of the sequence that matches this pattern.
implement boolean is viable prefix(readonly list[element type] the list)
Returns the maximum number of the elements of a given list that matches the pattern,
or null if there is no prefix match.
This is a greedy match: it mtaches the longest prefix.
implement nonnegative or null match prefix(readonly list[element type] the list)
var nonnegative index : 0
while index < the list • size && matches(the list[index])
index += 1
return index
Gets the first non-empty match for this pattern.
implement range or null find first(readonly list[element type] the list, nonnegative start index)
if match empty()
for var nonnegative i : start index; i < the list • size; i += 1
if matches(the list[i])
Gets the last non-empty match in the end-to-start direction.
When end_index is specified, it defines the element index after the last element
index after the one being matched. If end_index is null, it defaults to
the_list.size.
implement range or null find last(readonly list[element type] the list, nonnegative or null end index)
if end index is null
else
if match empty()
i = end index - 1
if i < 0
else
for ; i >= 0; i -= 1
return base range • new(0, 0)
assert i is nonnegative
if matches(the list[i])
end range : i + 1
while i > 0
check start : i - 1
assert check start is nonnegative
if !matches(the list[check start])
break
i = check start