class RuboCop::AST::NodePattern::Compiler

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/rubocop/ast/node_pattern/compiler.rbs

class RuboCop::AST::NodePattern::Compiler
  def compile_as_atom: (RuboCop::AST::NodePattern::Node node) -> String
  def compile_as_node_pattern: (RuboCop::AST::NodePattern::Node node, **Hash options) -> String
  def compile_sequence: (RuboCop::AST::NodePattern::Node::Sequence sequence, var: String) -> String
  def next_capture: () -> String
  def with_temp_variables: (*Array[String] names, ) -> String
end

/docs/modules/ROOT/pages/node_pattern.adoc
Doc on how this fits in the compiling process:
Defers work to its subcompilers
The top-level compiler holding the global state

def compile_as_atom(node)

Experimental RBS support (using type sampling data from the type_fusion project).

def compile_as_atom: (RuboCop::AST::NodePattern::Node node) -> String

This signature was generated using 1 sample from 1 application.

def compile_as_atom(node)
  @atom_subcompiler.compile(node)
end

def compile_as_node_pattern(node, **options)

Experimental RBS support (using type sampling data from the type_fusion project).

def compile_as_node_pattern: (RuboCop::AST::NodePattern::Node node, **access | String options) -> String

This signature was generated using 1 sample from 1 application.

def compile_as_node_pattern(node, **options)
  self.class::NodePatternSubcompiler.new(self, **options).compile(node)
end

def compile_sequence(sequence, var:)

Experimental RBS support (using type sampling data from the type_fusion project).

def compile_sequence: (RuboCop::AST::NodePattern::Node::Sequence sequence, var: String) -> String

This signature was generated using 1 sample from 1 application.

def compile_sequence(sequence, var:)
  self.class::SequenceSubcompiler.new(self, sequence: sequence, var: var).compile_sequence
end

def each_union(enum, &block)

union branches (captures and unification).
Enumerates `enum` while keeping track of state across
def each_union(enum, &block)
  enforce_same_captures(binding.union_bind(enum), &block)
end

def enforce_same_captures(enum)

def enforce_same_captures(enum)
  return to_enum __method__, enum unless block_given?
  captures_before = captures_after = nil
  enum.each do |node|
    captures_before ||= @captures
    @captures = captures_before
    yield node
    captures_after ||= @captures
    if captures_after != @captures
      raise Invalid, 'each branch must have same number of captures'
    end
  end
end

def freeze

def freeze
  @named_parameters.freeze
  super
end

def initialize

def initialize
  @temp_depth = 0 # avoid name clashes between temp variables
  @captures = 0 # number of captures seen
  @positional_parameters = 0 # highest % (param) number seen
  @named_parameters = Set[] # keyword parameters
  @binding = Binding.new # bound variables
  @atom_subcompiler = self.class::AtomSubcompiler.new(self)
end

def named_parameter(name)

def named_parameter(name)
  @named_parameters << name
  name
end

def new_capture

def new_capture
  @captures
ensure
  @captures += 1
end

def next_capture

Experimental RBS support (using type sampling data from the type_fusion project).

def next_capture: () -> String

This signature was generated using 2 samples from 1 application.

def next_capture
  "captures[#{new_capture}]"
end

def parser

def parser
  @parser ||= Parser.new
end

def positional_parameter(number)

def positional_parameter(number)
  @positional_parameters = number if number > @positional_parameters
  "param#{number}"
end

def with_temp_variables(*names, &block)

Experimental RBS support (using type sampling data from the type_fusion project).

def with_temp_variables: (*( | String | String) names, ) -> String

This signature was generated using 3 samples from 1 application.

def with_temp_variables(*names, &block)
  @temp_depth += 1
  suffix = @temp_depth if @temp_depth > 1
  names = block.parameters.map(&:last) if names.empty?
  names.map! { |name| "#{name}#{suffix}" }
  yield(*names)
ensure
  @temp_depth -= 1
end