module PatternMatch::Pattern::Backtrackable

Public Instance Methods

choice_points() click to toggle source
# File lib/pattern-match/experimental.rb, line 20
def choice_points
  if root?
    @choice_points ||= []
  else
    @parent.choice_points
  end
end
match(vals) click to toggle source
Calls superclass method
# File lib/pattern-match/experimental.rb, line 12
def match(vals)
  matched = super
  if root? and not matched and not choice_points.empty?
    restore_choice_point
  end
  matched
end

Private Instance Methods

repeating_match(vals, is_greedy) { |vs, rest| ... } click to toggle source
Calls superclass method
# File lib/pattern-match/experimental.rb, line 30
def repeating_match(vals, is_greedy)
  super do |vs, rest|
    cont = nil
    if callcc {|c| cont = c; yield vs, rest }
      save_choice_point(cont)
      true
    else
      false
    end
  end
end
restore_choice_point() click to toggle source
# File lib/pattern-match/experimental.rb, line 46
def restore_choice_point
  choice_points.pop.call(false)
end
save_choice_point(choice_point) click to toggle source
# File lib/pattern-match/experimental.rb, line 42
def save_choice_point(choice_point)
  choice_points.push(choice_point)
end