class Fast::FindFromArgument

Allow the user to interpolate expressions from external stuff. Use `%1` in the expression and the Matcher#prepare_arguments will interpolate the argument in the expression. @example interpolate the node value 1

Fast.match?("(int %1)", Fast.ast("1"), 1) # => true
Fast.match?("(int %1)", Fast.ast("1"), 2) # => false

@example interpolate multiple arguments

Fast.match?("(%1 %2)", Fast.ast("1"), :int, 1) # => true

Attributes

arguments[W]

Public Class Methods

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

  @capture_argument = token.to_i - 1
  raise 'Arguments start in one' if @capture_argument.negative?
end

Public Instance Methods

match?(node) click to toggle source
# File lib/fast.rb, line 562
def match?(node)
  raise 'You must define arguments to match' unless @arguments

  compare_symbol_or_head @arguments[@capture_argument], node
end
to_s() click to toggle source
# File lib/fast.rb, line 568
def to_s
  "find_with_arg[\\#{@capture_argument}]"
end