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
84
85
86
# 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)
      str_contents =
        elements.map do |element|
          SymbolLiteral.new(value: element, location: nil)
        end
      contents = Args.new(parts: str_contents, 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