class RuboCop::AST::NodePattern::Builder

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

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

class RuboCop::AST::NodePattern::Builder
  def emit_atom: (Symbol type, Integer value) -> RuboCop::AST::NodePattern::Node
  def emit_call: (Symbol type, Symbol selector, ?nil args) -> (RuboCop::AST::NodePattern::Node | RuboCop::AST::NodePattern::Node::Predicate)
  def emit_list: (Symbol type, Symbol _begin, Array[RuboCop::AST::NodePattern::Node] children, Symbol _end) -> RuboCop::AST::NodePattern::Node::Sequence
  def n: (Symbol type, *(Array[Array, Symbol] | Array[Array, String] | Array[Array, RuboCop::AST::NodePattern::Node, RuboCop::AST::NodePattern::Node]) args) -> (RuboCop::AST::NodePattern::Node | RuboCop::AST::NodePattern::Node::Sequence)
end

/docs/modules/ROOT/pages/node_pattern.adoc
Doc on how this fits in the compiling process:
Responsible to build the AST nodes for ‘NodePattern`

def emit_atom(type, value)

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

def emit_atom: (Symbol type, Integer value) -> RuboCop::AST::NodePattern::Node

This signature was generated using 1 sample from 1 application.

def emit_atom(type, value)
  n(type, [value])
end

def emit_call(type, selector, args = nil)

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

def emit_call: (Symbol type, Symbol selector, ?nil args) -> (RuboCop::AST::NodePattern::Node | RuboCop::AST::NodePattern::Node::Predicate)

This signature was generated using 6 samples from 1 application.

def emit_call(type, selector, args = nil)
  _begin_t, arg_nodes, _end_t = args
  n(type, [selector, *arg_nodes])
end

def emit_capture(capture_token, node)

def emit_capture(capture_token, node)
  return node if capture_token.nil?
  emit_unary_op(:capture, capture_token, node)
end

def emit_list(type, _begin, children, _end)

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

def emit_list: (Symbol type, Symbol _begin, (RuboCop::AST::NodePattern::Node::Union | RuboCop::AST::NodePattern::Node | RuboCop::AST::NodePattern::Node::Rest | RuboCop::AST::NodePattern::Node::Sequence | RuboCop::AST::NodePattern::Node | RuboCop::AST::NodePattern::Node) children, Symbol _end) -> RuboCop::AST::NodePattern::Node::Sequence

This signature was generated using 3 samples from 1 application.

def emit_list(type, _begin, children, _end)
  n(type, children)
end

def emit_subsequence(node_list)

def emit_subsequence(node_list)
  return node_list.first if node_list.size == 1 # Don't put a single child in a subsequence
  emit_list(:subsequence, nil, node_list, nil)
end

def emit_unary_op(type, _operator = nil, *children)

def emit_unary_op(type, _operator = nil, *children)
  n(type, children)
end

def emit_union(begin_t, pattern_lists, end_t)

def emit_union(begin_t, pattern_lists, end_t)
  children = union_children(pattern_lists)
  type = optimizable_as_set?(children) ? :set : :union
  emit_list(type, begin_t, children, end_t)
end

def n(type, *args)

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

def n: (Symbol type, * args) -> (RuboCop::AST::NodePattern::Node | RuboCop::AST::NodePattern::Node::Sequence)

This signature was generated using 8 samples from 1 application.

def n(type, *args)
  Node::MAP[type].new(type, *args)
end

def optimizable_as_set?(children)

def optimizable_as_set?(children)
  children.all?(&:matches_within_set?)
end

def union_children(pattern_lists)

def union_children(pattern_lists)
  if pattern_lists.size == 1 # {a b c} => [[a, b, c]] => [a, b, c]
    children = pattern_lists.first
    raise NodePattern::Invalid, 'A union can not be empty' if children.empty?
    children
  else # { a b | c } => [[a, b], [c]] => [s(:subsequence, a, b), c]
    pattern_lists.map do |list|
      emit_subsequence(list)
    end
  end
end