Base pattern for matching a repeated element.
abstract class base repeat element[readonly value element type]
implements reversible pattern[element type]
extends base pattern[element type]
abstract boolean match empty()
implement implicit boolean call(readonly list[element type] the list)
var nonnegative index : 0
while index < the listsize
if !matches(the list[index])
return false
index += 1
return index > 0 || match empty()
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)
for (the element : the list)
if !matches(the element)
return false
return true
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 listsize && matches(the list[index])
index += 1
if index == 0 && !match empty()
return missinginstance
else
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)
assert start index <= the listsize
if match empty()
if start index == the listsize || !matches(the list[start index])
return base range • new(start index, start index)
for var nonnegative i : start index; i < the listsize; i += 1
if matches(the list[i])
i += 1
while i < the listsize && matches(the list[i])
i += 1
return base range • new(start range, i)
return missinginstance
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)
var integer i
if end index is null
i = the listsize - 1
else
assert end index <= the listsize
i = end index - 1
if match empty()
if i < 0
return base range • new(0, 0)
else
assert i is nonnegative
if !matches(the list[i])
return base range • new(i + 1, i + 1)
for ; i >= 0; i -= 1
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
return base range • new(i, end range)
return missinginstance
implement void validate()
pass