Sha256: 10f3012cc719883a02097a201a1e4fe5f1befb73009fa15dddc8a588b918ad85

Contents?: true

Size: 866 Bytes

Versions: 23

Compression:

Stored size: 866 Bytes

Contents

# encoding: UTF-8

module Mutant

  # Walker for all ast nodes
  class Walker

    # Run walkter
    #
    # @param [Parser::AST::Node] root
    #
    # @return [self]
    #
    # @api private
    #
    def self.run(root, &block)
      new(root, block)
      self
    end

    private_class_method :new

    # Initialize and run walker
    #
    # @param [Parser::AST::Node] root
    # @param [#call(node)] block
    #
    # @return [undefined]
    #
    # @api private
    #
    def initialize(root, block)
      @root, @block = root, block
      dispatch(root)
    end

  private

    # Perform dispatch
    #
    # @param [Parser::AST::Node] node
    #
    # @return [undefined]
    #
    # @api private
    #
    def dispatch(node)
      @block.call(node)
      node.children.grep(Parser::AST::Node).each(&method(:dispatch))
    end
  end # Walker

end # Mutant

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
mutant-0.5.26 lib/mutant/walker.rb
mutant-0.5.25 lib/mutant/walker.rb
mutant-0.5.24 lib/mutant/walker.rb
mutant-0.5.23 lib/mutant/walker.rb
mutant-0.5.22 lib/mutant/walker.rb
mutant-0.5.21 lib/mutant/walker.rb
mutant-0.5.20 lib/mutant/walker.rb
mutant-0.5.19 lib/mutant/walker.rb
mutant-0.5.18 lib/mutant/walker.rb
mutant-0.5.17 lib/mutant/walker.rb
mutant-0.5.16 lib/mutant/walker.rb
mutant-0.5.15 lib/mutant/walker.rb
mutant-0.5.14 lib/mutant/walker.rb
mutant-0.5.13 lib/mutant/walker.rb
mutant-0.5.12 lib/mutant/walker.rb
mutant-0.5.11 lib/mutant/walker.rb
mutant-0.5.10 lib/mutant/walker.rb
mutant-0.5.9 lib/mutant/walker.rb
mutant-0.5.8 lib/mutant/walker.rb
mutant-0.5.7 lib/mutant/walker.rb