Base pattern for matching one element.
abstract class one pattern[readonly value element type]
implements reversible pattern[element type]
extends base pattern[element type]
implement implicit boolean call(readonly list[element type] the list)
return the listsize == 1 && matches(the listfirst)
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)
return the listis empty || (the listsize == 1 && matches(the listfirst))
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)
if the listis not empty && matches(the listfirst)
return 1
else
return missinginstance
Gets the first non-empty match for this pattern.
implement range or null find first(readonly list[element type] the list, nonnegative start index)
for var nonnegative i : start index; i < the listsize; i += 1
if matches(the list[i])
return base range • new(i, i + 1)
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
for ; i >= 0; i -= 1
assert i is nonnegative
if matches(the list[i])
return base range • new(i, i + 1)
return missinginstance
implement void validate()
pass