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.



7915
7916
7917
7918
7919
# File 'lib/syntax_tree.rb', line 7915

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



7913
7914
7915
# File 'lib/syntax_tree.rb', line 7913

def comments
  @comments
end

#contentsObject (readonly)

MLHS | MLHSParen

the contents inside of the parentheses



7907
7908
7909
# File 'lib/syntax_tree.rb', line 7907

def contents
  @contents
end

#locationObject (readonly)

Location

the location of this node



7910
7911
7912
# File 'lib/syntax_tree.rb', line 7910

def location
  @location
end

Instance Method Details

#child_nodesObject



7921
7922
7923
# File 'lib/syntax_tree.rb', line 7921

def child_nodes
  [contents]
end

#format(q) ⇒ Object



7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
# File 'lib/syntax_tree.rb', line 7925

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)
        q.text(",") if contents.is_a?(MLHS) && contents.comma?
      end

      q.breakable("")
    end
  end
end

#pretty_print(q) ⇒ Object



7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
# File 'lib/syntax_tree.rb', line 7943

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



7954
7955
7956
7957
7958
7959
7960
7961
# File 'lib/syntax_tree.rb', line 7954

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