class Referral::TokenizesIdentifiers

Public Class Methods

new() click to toggle source
# File lib/referral/tokenizes_identifiers.rb, line 5
def initialize
  @translates_node_to_token = TranslatesNodeToToken.new
end

Public Instance Methods

call(root_node, root_token) click to toggle source
# File lib/referral/tokenizes_identifiers.rb, line 9
def call(root_node, root_token)
  find_names(root_node, root_token)
    .reject { |identifier_token| identifier_token.name.nil? }
    .tap do |identifiers|
    root_token.identifiers = identifiers

    if identifiers.any? { |id| id.node_type == TOKEN_TYPES[:triple_colon] }
      root_token.parent = nil
    end
  end
end

Private Instance Methods

find_names(node, parent) click to toggle source
# File lib/referral/tokenizes_identifiers.rb, line 23
def find_names(node, parent)
  return [] unless node.is_a?(RubyVM::AbstractSyntaxTree::Node)

  [
    *find_names(node.children.first, parent),
    @translates_node_to_token.call(node, parent, parent.file),
  ].compact
end