class Fear::Extractor::Matcher

@abstract abstract matcher to inherit from.

Attributes

input[R]
input_position[R]

Public Class Methods

new(node:, **attributes) click to toggle source

@param node [Fear::Extractor::Grammar::Node]

Calls superclass method
# File lib/fear/extractor/matcher.rb, line 12
def initialize(node:, **attributes)
  @input = node.input
  @input_position = node.interval.first
  super(attributes)
end

Public Instance Methods

and(other) click to toggle source
# File lib/fear/extractor/matcher.rb, line 25
def and(other)
  And.new(self, other)
end
call(arg) click to toggle source
# File lib/fear/extractor/matcher.rb, line 21
def call(arg)
  call_or_else(arg, &PartialFunction::EMPTY)
end
call_or_else(arg) { |arg| ... } click to toggle source

@param arg [any] @yield [arg] if function not defined

# File lib/fear/extractor/matcher.rb, line 31
def call_or_else(arg)
  if defined_at?(arg)
    bindings(arg)
  else
    yield arg
  end
end
failure_reason(other) click to toggle source

Shows why matcher has failed. Use it for debugging. @example

Fear['[1, 2, _]'].failure_reason([1, 3, 4])
# it will show that the second element hasn't match
# File lib/fear/extractor/matcher.rb, line 44
def failure_reason(other)
  if defined_at?(other)
    Fear.none
  else
    Fear.some("Expected `#{other.inspect}` to match:\n#{input}\n#{"~" * input_position}^")
  end
end