Class: RuboCop::AST::NodePattern::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/ast/node_pattern/builder.rb

Overview

Responsible to build the AST nodes for ‘NodePattern`

Doc on how this fits in the compiling process:

/docs/modules/ROOT/pages/node_pattern.adoc

Direct Known Subclasses

Parser::WithMeta::Builder

Instance Method Summary collapse

Instance Method Details

#emit_atom(type, value) ⇒ Object



17
18
19
# File 'lib/rubocop/ast/node_pattern/builder.rb', line 17

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

#emit_call(type, selector, args = nil) ⇒ Object



29
30
31
32
# File 'lib/rubocop/ast/node_pattern/builder.rb', line 29

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

#emit_capture(capture_token, node) ⇒ Object



11
12
13
14
15
# File 'lib/rubocop/ast/node_pattern/builder.rb', line 11

def emit_capture(capture_token, node)
  return node if capture_token.nil?

  emit_unary_op(:capture, capture_token, node)
end

#emit_list(type, _begin, children, _end) ⇒ Object



25
26
27
# File 'lib/rubocop/ast/node_pattern/builder.rb', line 25

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

#emit_subsequence(node_list) ⇒ Object



41
42
43
44
45
# File 'lib/rubocop/ast/node_pattern/builder.rb', line 41

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

#emit_unary_op(type, _operator = nil, *children) ⇒ Object



21
22
23
# File 'lib/rubocop/ast/node_pattern/builder.rb', line 21

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

#emit_union(begin_t, pattern_lists, end_t) ⇒ Object



34
35
36
37
38
39
# File 'lib/rubocop/ast/node_pattern/builder.rb', line 34

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