Module: Machete
- Defined in:
- lib/machete.rb,
lib/machete/parser.rb,
lib/machete/version.rb,
lib/machete/matchers.rb
Defined Under Namespace
Modules: Matchers Classes: Parser
Constant Summary collapse
- VERSION =
File.read(File.dirname(__FILE__) + "/../../VERSION").strip
Class Method Summary collapse
-
.find(ast, pattern) ⇒ Array
Finds all nodes in a Rubinius AST matching a pattern.
-
.matches?(node, pattern) ⇒ Boolean
Matches a Rubinius AST node against a pattern.
Class Method Details
.find(ast, pattern) ⇒ Array
Finds all nodes in a Rubinius AST matching a pattern.
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/machete.rb', line 75 def find(ast, pattern) matcher = compiled_pattern(pattern) result = [] result << ast if matcher.matches?(ast) ast.walk(true) do |dummy, node| result << node if matcher.matches?(node) true end result end |
.matches?(node, pattern) ⇒ Boolean
Matches a Rubinius AST node against a pattern.
42 43 44 |
# File 'lib/machete.rb', line 42 def matches?(node, pattern) compiled_pattern(pattern).matches?(node) end |