Class: RuboCop::AST::NodePattern::Parser::WithMeta::Builder

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

Overview

Overrides Builder to emit nodes with locations

Instance Method Summary collapse

Methods inherited from Builder

#emit_capture, #emit_subsequence, #emit_union

Instance Method Details

#emit_atom(type, token) ⇒ Object


40
41
42
43
44
45
46
47
# File 'lib/rubocop/ast/node_pattern/with_meta.rb', line 40

def emit_atom(type, token)
  value, loc = token
  begin_l = loc.resize(1)
  end_l = loc.end.adjust(begin_pos: -1)
  begin_l = nil if begin_l.source.match?(/\w/)
  end_l = nil if end_l.source.match?(/\w/)
  n(type, [value], source_map(token, begin_t: begin_l, end_t: end_l))
end

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


61
62
63
64
65
66
67
# File 'lib/rubocop/ast/node_pattern/with_meta.rb', line 61

def emit_call(type, selector_t, args = nil)
  selector, = selector_t
  begin_t, arg_nodes, end_t = args

  map = source_map(selector_t, begin_t: begin_t, end_t: end_t, selector_t: selector_t)
  n(type, [selector, *arg_nodes], map)
end

#emit_list(type, begin_t, children, end_t) ⇒ Object


55
56
57
58
59
# File 'lib/rubocop/ast/node_pattern/with_meta.rb', line 55

def emit_list(type, begin_t, children, end_t)
  expr = children.first.loc.expression.join(children.last.loc.expression)
  map = source_map(expr, begin_t: begin_t, end_t: end_t)
  n(type, children, map)
end

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


49
50
51
52
53
# File 'lib/rubocop/ast/node_pattern/with_meta.rb', line 49

def emit_unary_op(type, operator_t = nil, *children)
  children[-1] = children[-1].first if children[-1].is_a?(Array) # token?
  map = source_map(children.first.loc.expression, operator_t: operator_t)
  n(type, children, map)
end