Sha256: 5fbf258f6c70667be1cd982b9d8735c5fcde89daabbf0049ddebe62f20464768

Contents?: true

Size: 965 Bytes

Versions: 3

Compression:

Stored size: 965 Bytes

Contents

require 'ast'
module ATP
  # The base processor, this provides a default handler for
  # all node types and will not make any changes to the AST,
  # i.e. an equivalent AST will be returned by the process method.
  #
  # Child classes of this should be used to implement additional
  # processors to modify or otherwise work with the AST.
  #
  # @see http://www.rubydoc.info/gems/ast/2.0.0/AST/Processor
  class Processor
    include ::AST::Processor::Mixin

    def run(node)
      process(node)
    end

    def process(node)
      if node.respond_to?(:to_ast)
        super(node)
      else
        node
      end
    end

    def handler_missing(node)
      node.updated(nil, process_all(node.children))
    end

    def n(type, children)
      ATP::AST::Node.new(type, children)
    end

    def n0(type)
      n(type, [])
    end

    def n1(type, arg)
      n(type, [arg])
    end

    def n2(type, arg1, arg2)
      n(type, [arg1, arg2])
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
atp-0.7.0 lib/atp/processor.rb
atp-0.6.0 lib/atp/processor.rb
atp-0.5.4 lib/atp/processor.rb