Class: MetaParse::FunctionMatcher

Inherits:
Matcher
  • Object
show all
Includes:
MetaParse
Defined in:
lib/meta_parse.rb

Overview

Arbitrary predicate, particularly useful for generating final return value from SequentialMatchers. Context is the containing matcher, and in the case of SequentialMatcher includes access to accumulated matches.

Instance Attribute Summary

Attributes inherited from Matcher

#spec

Instance Method Summary collapse

Methods included from MetaParse

#all_matches, #all_matches_joined, #collapse, included, #join_strings, #parse_with_method

Methods inherited from Matcher

compile, #initialize, #inspect, #m, #m?, #match, #show, #stateful

Constructor Details

This class inherits a constructor from MetaParse::Matcher

Instance Method Details

#match?(scanner, context = nil) ⇒ Boolean

Try to match against scanner using arbitrary predicated specified as Proc or Symbol naming method of Matcher’s parser.

Returns:

  • (Boolean)


406
407
408
409
410
411
412
413
# File 'lib/meta_parse.rb', line 406

def match?(scanner, context=nil)
  case spec
  when Proc
    spec.call(scanner, context)
  when Symbol
    scanner.parser.send spec, scanner, context
  end
end