Module: Machete
- Defined in:
- lib/machete.rb,
lib/machete/parser.rb,
lib/machete/version.rb,
lib/machete/matchers.rb
Defined Under Namespace
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.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/machete.rb', line 42 def self.find(ast, pattern) matcher = Parser.new.parse(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.
22 23 24 |
# File 'lib/machete.rb', line 22 def self.matches?(node, pattern) Parser.new.parse(pattern).matches?(node) end |