Module: Yoda::Parsing::AstTraversable

Included in:
NodeObjects::Namespace
Defined in:
lib/yoda/parsing/ast_traversable.rb

Instance Method Summary collapse

Instance Method Details

#calc_nodes_to_current_location(root_node, current_location) ⇒ Array<::Parser::AST::Node>

Parameters:

  • root_node (Array<::Parser::AST::Node>)
  • current_location (Parser::Source::Map)

Returns:

  • (Array<::Parser::AST::Node>)


7
8
9
10
11
12
13
14
15
# File 'lib/yoda/parsing/ast_traversable.rb', line 7

def calc_nodes_to_current_location(root_node, current_location)
  nodes = [root_node]
  node = root_node
  while node && !node.children.empty?
    node = node.children.find { |n| n.respond_to?(:location) && current_location.included?(n.location) }
    nodes << node if node && node.is_a?(::Parser::AST::Node)
  end
  nodes
end