class Sexp::Sibling

See Matcher for sibling relations: <,<<,>>,>



An optional distance requirement for the matcher.


The RHS of the matcher.


The LHS of the matcher.

Public Class Methods

new(subject, sibling, distance = nil) click to toggle source

Creates a Matcher which will match any pair of Sexps that are siblings. Defaults to matching the immediate following sibling.

# File lib/sexp_matcher.rb, line 1002
def initialize subject, sibling, distance = nil
  @subject = subject
  @sibling = sibling
  @distance = distance

Public Instance Methods

satisfy?(o) click to toggle source

Satisfied if o contains subject followed by sibling

# File lib/sexp_matcher.rb, line 1011
def satisfy? o
  # Future optimizations:
  # * Shortcut matching sibling
  subject_matches = index_matches(subject, o)
  return nil if subject_matches.empty?

  sibling_matches = index_matches(sibling, o)
  return nil if sibling_matches.empty?

  subject_matches.any? { |i1, _data_1|
    sibling_matches.any? { |i2, _data_2|
      distance ? (i2-i1 == distance) : i2 > i1