Pattern that matches a list of elements.
class list pattern[readonly equality comparable element type]
extends base pattern[element type]
immutable list[element type] element list
list pattern(readonly list[element type] element list)
this • element list = element listfrozen copy()
implement implicit boolean call(readonly list[element type] the list)
return the listsize == element listsize && is viable prefix(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)
if the listsize > element listsize
return false
for var nonnegative index : 0; index < the listsize; index += 1
if the list[index] != element list[index]
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)
if the listsize >= elements size && this(the listslice(0, elements size))
return elements size
else
return missinginstance
Gets the first non-empty match for this pattern.
implement range or null find first(readonly list[element type] the list, var nonnegative start index)
var nonnegative index : start index
while elements size + index <= the listsize
if this(the listslice(index, index + elements size))
return base range • new(index, index + elements size)
index += 1
return missinginstance
implement void validate()
pass