Class: YARP::ParenthesesNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
ext/yarp/api_node.c

Overview

Represents a parenthesized expression

(10 + 34)
^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, opening_loc, closing_loc, location) ⇒ ParenthesesNode

def initialize: (body: Node?, opening_loc: Location, closing_loc: Location, location: Location) -> void



7849
7850
7851
7852
7853
7854
# File 'lib/yarp/node.rb', line 7849

def initialize(body, opening_loc, closing_loc, location)
  @body = body
  @opening_loc = opening_loc
  @closing_loc = closing_loc
  @location = location
end

Instance Attribute Details

#bodyObject (readonly)

attr_reader body: Node?



7840
7841
7842
# File 'lib/yarp/node.rb', line 7840

def body
  @body
end

#closing_locObject (readonly)

attr_reader closing_loc: Location



7846
7847
7848
# File 'lib/yarp/node.rb', line 7846

def closing_loc
  @closing_loc
end

#opening_locObject (readonly)

attr_reader opening_loc: Location



7843
7844
7845
# File 'lib/yarp/node.rb', line 7843

def opening_loc
  @opening_loc
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



7857
7858
7859
# File 'lib/yarp/node.rb', line 7857

def accept(visitor)
  visitor.visit_parentheses_node(self)
end

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



7866
7867
7868
# File 'lib/yarp/node.rb', line 7866

def child_nodes
  [body]
end

#closingObject

def closing: () -> String



7899
7900
7901
# File 'lib/yarp/node.rb', line 7899

def closing
  closing_loc.slice
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



7871
7872
7873
# File 'lib/yarp/node.rb', line 7871

def comment_targets
  [*body, opening_loc, closing_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> ParenthesesNode



7876
7877
7878
7879
7880
7881
7882
7883
# File 'lib/yarp/node.rb', line 7876

def copy(**params)
  ParenthesesNode.new(
    params.fetch(:body) { body },
    params.fetch(:opening_loc) { opening_loc },
    params.fetch(:closing_loc) { closing_loc },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



7889
7890
7891
# File 'lib/yarp/node.rb', line 7889

def deconstruct_keys(keys)
  { body: body, opening_loc: opening_loc, closing_loc: closing_loc, location: location }
end

#inspect(inspector = NodeInspector.new) ⇒ Object



7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
# File 'lib/yarp/node.rb', line 7903

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  if (body = self.body).nil?
    inspector << "├── body: ∅\n"
  else
    inspector << "├── body:\n"
    inspector << body.inspect(inspector.child_inspector("│   ")).delete_prefix(inspector.prefix)
  end
  inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n"
  inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n"
  inspector.to_str
end

#openingObject

def opening: () -> String



7894
7895
7896
# File 'lib/yarp/node.rb', line 7894

def opening
  opening_loc.slice
end

#set_newline_flag(newline_marked) ⇒ Object



7861
7862
7863
# File 'lib/yarp/node.rb', line 7861

def set_newline_flag(newline_marked)
  # Never mark ParenthesesNode with a newline flag, mark children instead
end