Class: SyntaxTree::Symbols

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

Overview

Symbols represents a symbol array literal with interpolation.

I[one two three]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elements:, location:, comments: []) ⇒ Symbols

Returns a new instance of Symbols.



11078
11079
11080
11081
11082
# File 'lib/syntax_tree.rb', line 11078

def initialize(elements:, location:, comments: [])
  @elements = elements
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



11076
11077
11078
# File 'lib/syntax_tree.rb', line 11076

def comments
  @comments
end

#elementsObject (readonly)

Array[ Word ]

the words in the symbol array literal



11070
11071
11072
# File 'lib/syntax_tree.rb', line 11070

def elements
  @elements
end

#locationObject (readonly)

Location

the location of this node



11073
11074
11075
# File 'lib/syntax_tree.rb', line 11073

def location
  @location
end

Instance Method Details

#child_nodesObject



11084
11085
11086
# File 'lib/syntax_tree.rb', line 11084

def child_nodes
  []
end

#format(q) ⇒ Object



11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
# File 'lib/syntax_tree.rb', line 11088

def format(q)
  q.group(0, "%I[", "]") do
    q.indent do
      q.breakable("")
      q.seplist(elements, -> { q.breakable }) do |element|
        q.format(element)
      end
    end
    q.breakable("")
  end
end

#pretty_print(q) ⇒ Object



11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
# File 'lib/syntax_tree.rb', line 11100

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("symbols")

    q.breakable
    q.group(2, "(", ")") { q.seplist(elements) { |element| q.pp(element) } }

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



11111
11112
11113
11114
11115
11116
11117
11118
# File 'lib/syntax_tree.rb', line 11111

def to_json(*opts)
  {
    type: :symbols,
    elems: elements,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end