Class: SyntaxTree::MLHSParen

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

Overview

MLHSParen represents parentheses being used to destruct values in a multiple assignment on the left hand side.

(left, right) = value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents:, location:, comments: []) ⇒ MLHSParen

Returns a new instance of MLHSParen.



8252
8253
8254
8255
8256
# File 'lib/syntax_tree.rb', line 8252

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8250
8251
8252
# File 'lib/syntax_tree.rb', line 8250

def comments
  @comments
end

#contentsObject (readonly)

MLHS | MLHSParen

the contents inside of the parentheses



8244
8245
8246
# File 'lib/syntax_tree.rb', line 8244

def contents
  @contents
end

#locationObject (readonly)

Location

the location of this node



8247
8248
8249
# File 'lib/syntax_tree.rb', line 8247

def location
  @location
end

Instance Method Details

#child_nodesObject



8258
8259
8260
# File 'lib/syntax_tree.rb', line 8258

def child_nodes
  [contents]
end

#format(q) ⇒ Object



8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
# File 'lib/syntax_tree.rb', line 8262

def format(q)
  parent = q.parent

  if parent.is_a?(MAssign) || parent.is_a?(MLHSParen)
    q.format(contents)
  else
    q.group(0, "(", ")") do
      q.indent do
        q.breakable("")
        q.format(contents)
      end

      q.breakable("")
    end
  end
end

#pretty_print(q) ⇒ Object



8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
# File 'lib/syntax_tree.rb', line 8279

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

    q.breakable
    q.pp(contents)

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

#to_json(*opts) ⇒ Object



8290
8291
8292
8293
8294
8295
8296
8297
# File 'lib/syntax_tree.rb', line 8290

def to_json(*opts)
  {
    type: :mlhs_paren,
    cnts: contents,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end