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.



8329
8330
8331
8332
8333
# File 'lib/syntax_tree.rb', line 8329

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



8327
8328
8329
# File 'lib/syntax_tree.rb', line 8327

def comments
  @comments
end

#contentsObject (readonly)

MLHS | MLHSParen

the contents inside of the parentheses



8321
8322
8323
# File 'lib/syntax_tree.rb', line 8321

def contents
  @contents
end

#locationObject (readonly)

Location

the location of this node



8324
8325
8326
# File 'lib/syntax_tree.rb', line 8324

def location
  @location
end

Instance Method Details

#child_nodesObject



8335
8336
8337
# File 'lib/syntax_tree.rb', line 8335

def child_nodes
  [contents]
end

#format(q) ⇒ Object



8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
# File 'lib/syntax_tree.rb', line 8339

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



8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
# File 'lib/syntax_tree.rb', line 8356

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



8367
8368
8369
8370
8371
8372
8373
8374
# File 'lib/syntax_tree.rb', line 8367

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