Match a sequence of patterns.
class sequence pattern[readonly value element type]
extends base pattern[element type]
implement void validate()
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 list • is empty
return true
var nonnegative index : 0
var nonnegative prefix : 0
while index < patterns list • size - 1
private nonnegative or null match subsequence(readonly list[element type] the list, var nonnegative index, var nonnegative prefix)
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)
return match subsequence(the list, 0, 0)
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)