Match one of the collection of patterns.
class option pattern[readonly value element type]
extends base pattern[element type]
protected list[pattern[element type]] options
private mutable var boolean validated
option pattern(readonly collection[pattern[element type]] options)
this • options = base list[pattern[element type]] • new()
this • optionsappend all(optionselements)
implement void validate()
if validated
return
assert optionssize > 1
for (option : options)
(option !> validatable) • validate()
assert !option(empty[element type] • new())
implement implicit boolean call(readonly list[element type] the list)
for (option : options)
if option(the list)
return true
return false
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 listis empty
return true
for (option : options)
if optionis viable prefix(the list)
return true
return false
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)
for (option : options)
match : optionmatch prefix(the list)
if match is_not null
if result is null || result < match
result = match
return result
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)
for (option : options)
match : optionfind first(the list, start index)
if match is null
continue
if result is null
result = match
else if matchbegin < resultbegin || (matchbegin == resultbegin && matchend > resultend)
result = match
return result