Sha256: cf57791f137928098fe8ce4289ad6a589d7cef54cb744c32eab3e5ad39b6672d

Contents?: true

Size: 798 Bytes

Versions: 1

Compression:

Stored size: 798 Bytes

Contents

module Furnace
  module AST
    module Visitor
      def visit(node)
        node.children.map! do |child|
          if child.is_a? Node
            visit child

            if child.type == :expand
              child = child.children
            end
          end

          child
        end

        node.children.flatten!

        node.children.delete_if do |child|
          if child.is_a? Node
            child.parent = node

            child.type == :remove
          end
        end

        # Invoke a specific handler
        on_handler = :"on_#{node.type}"
        if respond_to? on_handler
          send on_handler, node
        end

        # Invoke a generic handler
        if respond_to? :on_any
          send :on_any, node
        end

        node
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
furnace-0.0.1 lib/furnace/ast/visitor.rb