module Unparser::AST

Namespace for AST processing tools

Constants

ASSIGN_NODES

Nodes that assign a local variable

CLOSE_NODES
FIRST_CHILD
INHERIT_NODES
RESET_NODES
TAUTOLOGY

Public Class Methods

local_variable_assignments(node) click to toggle source

Return local variables that get assigned in scope

@param [Parser::AST::Node] node

@return [Set<Symbol>]

@api private

# File lib/unparser/ast.rb, line 57
def self.local_variable_assignments(node)
  Enumerator.new(
    node,
    method(:not_reset_scope?)
  ).types(ASSIGN_NODES)
end
local_variable_reads(node) click to toggle source

Return local variables read

@param [Parser::AST::Node] node

@return [Set<Symbol>]

@api private

# File lib/unparser/ast.rb, line 72
def self.local_variable_reads(node)
  Enumerator.new(
    node,
    method(:not_close_scope?)
  ).type(:lvar).map(&FIRST_CHILD).to_set
end
not_close_scope?(node) click to toggle source

Test for local variable inherited scope reset

@param [Parser::AST::Node] node

@return [Boolean]

@api private

# File lib/unparser/ast.rb, line 33
def self.not_close_scope?(node)
  !CLOSE_NODES.include?(node.type)
end
not_reset_scope?(node) click to toggle source

Test for local variable scope reset

@param [Parser::AST::Node] node

@return [Boolean]

@api private

# File lib/unparser/ast.rb, line 45
def self.not_reset_scope?(node)
  !RESET_NODES.include?(node.type)
end