class Sexp::Sibling

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

Attributes

distance[R]

An optional distance requirement for the matcher.

sibling[R]

The RHS of the matcher.

subject[R]

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.rb, line 1314
def initialize subject, sibling, distance = nil
  @subject = subject
  @sibling = sibling
  @distance = distance
end

Public Instance Methods

satisfy?(o) click to toggle source

Satisfied if o contains subject followed by sibling

# File lib/sexp.rb, line 1323
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
    }
  }
end