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



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

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

  q.group do
    q.text(opening)

    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

    q.breakable_empty
    q.text(closing)
  end
end