class AlternationOperator
Provides alternation as described by OrPattern
Public Class Methods
new()
click to toggle source
# File lib/textmate_grammar/regex_operators/alternation.rb, line 9 def initialize @precedence = 1 @association = :right end
Public Instance Methods
do_evaluate_self(arr_left, arr_right)
click to toggle source
(see RegexOperator#do_evaluate_self
)
# File lib/textmate_grammar/regex_operators/alternation.rb, line 15 def do_evaluate_self(arr_left, arr_right) left = fold_left(arr_left) # fold right is not applied as only the immediate right is a part of the alternation # (?:#{foo}) is not needed as alternation has the lowest precedence (in regex) # that could be generated (anything lower is required to be closed) self_string = "(?:#{left[0]}|#{arr_right[0]})" [left[1], self_string, arr_right[1..-1]].flatten end