Class: SyntaxTree::QSymbols

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Instance Method Summary collapse

Instance Method Details

#format(q) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/syntax_tree/node.rb', line 62

def format(q)
  opening, closing = "[", "]"

  q.group do
    q.text(opening)

    unless elements.empty?
      loc = elements.first.location.to(elements.last.location)
      literals = convert_to_literals(q, elements)
      contents = Args.new(parts: literals, location: loc)

      q.indent do
        q.breakable_empty
        q.format(contents)
        q.if_break { q.text(",") } if q.trailing_comma?
      end
    end

    q.breakable_empty
    q.text(closing)
  end
end