class Fast::FindWithCapture

Allow use previous captures while searching in the AST. Use `\1` to point the match to the first captured element or sequential numbers considering the order of the captures.

@example check comparision of integers that will always return true

ast = Fast.ast("1 == 1") => s(:send, s(:int, 1), :==, s(:int, 1))
Fast.match?("(send $(int _) == \1)", ast) # => [s(:int, 1)]

Attributes

previous_captures[W]

Public Class Methods

new(token) click to toggle source
# File lib/fast.rb, line 527
def initialize(token)
  token = token.token if token.respond_to?(:token)
  raise 'You must use captures!' unless token

  @capture_index = token.to_i
end

Public Instance Methods

match?(node) click to toggle source
# File lib/fast.rb, line 534
def match?(node)
  node == @previous_captures[@capture_index - 1]
end
to_s() click to toggle source
# File lib/fast.rb, line 538
def to_s
  "fc[\\#{@capture_index}]"
end