Class: YARP::BreakNode

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

Overview

Represents the use of the ‘break` keyword.

break foo
^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments, keyword_loc, location) ⇒ BreakNode

def initialize: (arguments: ArgumentsNode?, keyword_loc: Location, location: Location) -> void



1157
1158
1159
1160
1161
# File 'lib/yarp/node.rb', line 1157

def initialize(arguments, keyword_loc, location)
  @arguments = arguments
  @keyword_loc = keyword_loc
  @location = location
end

Instance Attribute Details

#argumentsObject (readonly)

attr_reader arguments: ArgumentsNode?



1151
1152
1153
# File 'lib/yarp/node.rb', line 1151

def arguments
  @arguments
end

#keyword_locObject (readonly)

attr_reader keyword_loc: Location



1154
1155
1156
# File 'lib/yarp/node.rb', line 1154

def keyword_loc
  @keyword_loc
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



1164
1165
1166
# File 'lib/yarp/node.rb', line 1164

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

#child_nodesObject Also known as: deconstruct

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



1169
1170
1171
# File 'lib/yarp/node.rb', line 1169

def child_nodes
  [arguments]
end

#comment_targetsObject

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



1174
1175
1176
# File 'lib/yarp/node.rb', line 1174

def comment_targets
  [*arguments, keyword_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> BreakNode



1179
1180
1181
1182
1183
1184
1185
# File 'lib/yarp/node.rb', line 1179

def copy(**params)
  BreakNode.new(
    params.fetch(:arguments) { arguments },
    params.fetch(:keyword_loc) { keyword_loc },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

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



1191
1192
1193
# File 'lib/yarp/node.rb', line 1191

def deconstruct_keys(keys)
  { arguments: arguments, keyword_loc: keyword_loc, location: location }
end

#inspect(inspector = NodeInspector.new) ⇒ Object



1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
# File 'lib/yarp/node.rb', line 1200

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

#keywordObject

def keyword: () -> String



1196
1197
1198
# File 'lib/yarp/node.rb', line 1196

def keyword
  keyword_loc.slice
end