Class: Astel::NodePattern
- Inherits:
-
Object
- Object
- Astel::NodePattern
- Defined in:
- lib/astel/node_pattern.rb,
lib/astel/node_pattern.rb,
lib/astel/node_pattern/lexer.rb,
lib/astel/node_pattern/parser.rb,
lib/astel/node_pattern/matcher_compiler.rb,
lib/astel/node_pattern/predicate_compiler.rb
Defined Under Namespace
Modules: CaptureMatching Classes: Lexer, MatcherCompiler, Parser, PatternError, PredicateCompiler, Token
Constant Summary collapse
- COMPILER_CACHE_LIMIT =
128
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(predicate, matcher) ⇒ NodePattern
constructor
A new instance of NodePattern.
- #match(node) {|captures| ... } ⇒ Object
Constructor Details
#initialize(predicate, matcher) ⇒ NodePattern
Returns a new instance of NodePattern.
63 64 65 66 67 68 69 70 |
# File 'lib/astel/node_pattern.rb', line 63 def initialize(predicate, matcher) define_singleton_method(:match?, predicate) return unless matcher define_singleton_method(:match_captures, matcher) singleton_class.send(:private, :match_captures) extend CaptureMatching end |
Class Method Details
.compile(source) ⇒ Object
43 44 45 46 |
# File 'lib/astel/node_pattern.rb', line 43 def self.compile(source) predicate, matcher = compiled_matchers(source) new(predicate, matcher) end |
Instance Method Details
#match(node) {|captures| ... } ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/astel/node_pattern.rb', line 72 def match(node) return unless match?(node) captures = [] yield captures if block_given? captures end |