Sha256: 5695c649bd28d55141071b707ad2a9561c234fcf4a6004a1f1044a97d49bdac6

Contents?: true

Size: 899 Bytes

Versions: 11

Compression:

Stored size: 899 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
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
atp-0.5.3 lib/atp/processor.rb
atp-0.5.0 lib/atp/processor.rb
atp-0.4.3 lib/atp/processor.rb
atp-0.4.2 lib/atp/processor.rb
atp-0.4.1 lib/atp/processor.rb
atp-0.4.0 lib/atp/processor.rb
atp-0.3.3 lib/atp/processor.rb
atp-0.3.2 lib/atp/processor.rb
atp-0.3.1 lib/atp/processor.rb
atp-0.3.0 lib/atp/processor.rb
atp-0.2.1 lib/atp/processor.rb