class Cannonbol::OnMatch

Public Instance Methods

__match?(needle, starting_cursor = nil, s=[]) click to toggle source
# File lib/cannonbol/cannonbol.rb, line 241
def __match?(needle, starting_cursor = nil, s=[])
  starting_cursor ||= needle.cursor
  if s = @pattern._match?(needle, *s)
    match_string = MatchString.new(needle.string, starting_cursor, needle.cursor-1, needle.captures)
    capture_value = @capture_name && (needle.captures.has_key?(@capture_name) ? needle.captures[@capture_name] : @initial_capture_value)
    match_string = @block.call(match_string, needle.cursor, capture_value) if @block
    needle.capture(@capture_name, match_string)
    [starting_cursor, s]
  end
end