Base pattern for matching a repeated pattern.
The pattern can't match an empty list.
class repeat pattern[readonly value element type]
extends base pattern[element type]
repeat pattern(pattern[element type] the pattern, boolean do match empty)
this • the pattern = the pattern
this • do match empty = do match empty
implement implicit boolean call(readonly list[element type] the list)
var nonnegative index : 0
while index < the list • size
return index > 0 || do 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)
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
if index == 0 && !do match empty
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)
if do match empty
if start index == the list • size || the pattern • match prefix(the list • skip(start index)) is null
for var nonnegative i : start index; i < the list • size; i += 1
if match is_not null
start range : i
assert match > 0
i += match
while i < the list • size