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 • options • append all(options • elements)
implement void validate()
if validated
return
assert options • size > 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 list • is empty
return true
for (option : options)
if option • is 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 : option • match 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 : option • find first(the list, start index)
if match is null
continue
if result is null
result = match
else if match • begin < result • begin || (match • begin == result • begin && match • end > result • end)
result = match
return result