Sha256: d20e315f54d3b6d110755f363d9cffa042b5d74e1afbe17c4cd670ac86cf8203

Contents?: true

Size: 971 Bytes

Versions: 1

Compression:

Stored size: 971 Bytes

Contents

# 已完成

module Antlr4ruby

  # @abstract
  class AbstractParseTreeVisitor
    # @override
    def visit(tree)
      tree.accept(self)
    end

    # @override
    def visit_children(node)
      result = default_result
      n = node.get_child_count
      n.times do |i|
        unless should_visit_next_child(node, result)
          break
        end

        child = node.get_child(i)
        if child
          child_result = child.accept(self)
          result = aggregate_result(result, child_result)
        end
      end

      result
    end

    # @!override
    def visit_terminal(_node)
      default_result
    end

    def visit_error_node(_node)
      default_result
    end

    protected

    def default_result
      nil
    end

    def aggregate_result(_aggregate, next_result)
      next_result
    end

    def should_visit_next_child(_node, _current_result)
      true
    end
  end
end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
antlr4ruby-0.1.0 lib/antlr4ruby/tree/abstract_parse_tree_visitor.rb