Class: Prism::YieldNode

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

Overview

Represents the use of the ‘yield` keyword.

yield 1
^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, keyword_loc, lparen_loc, arguments, rparen_loc) ⇒ YieldNode

Initialize a new YieldNode node.



18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
# File 'lib/prism/node.rb', line 18317

def initialize(source, node_id, location, flags, keyword_loc, lparen_loc, arguments, rparen_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @keyword_loc = keyword_loc
  @lparen_loc = lparen_loc
  @arguments = arguments
  @rparen_loc = rparen_loc
end

Instance Attribute Details

#argumentsObject (readonly)

attr_reader arguments: ArgumentsNode?



18396
18397
18398
# File 'lib/prism/node.rb', line 18396

def arguments
  @arguments
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



18443
18444
18445
# File 'lib/prism/node.rb', line 18443

def self.type
  :yield_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



18449
18450
18451
18452
18453
18454
18455
# File 'lib/prism/node.rb', line 18449

def ===(other)
  other.is_a?(YieldNode) &&
    (keyword_loc.nil? == other.keyword_loc.nil?) &&
    (lparen_loc.nil? == other.lparen_loc.nil?) &&
    (arguments === other.arguments) &&
    (rparen_loc.nil? == other.rparen_loc.nil?)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



18329
18330
18331
# File 'lib/prism/node.rb', line 18329

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

#child_nodesObject Also known as: deconstruct

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



18334
18335
18336
# File 'lib/prism/node.rb', line 18334

def child_nodes
  [arguments]
end

#comment_targetsObject

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



18346
18347
18348
# File 'lib/prism/node.rb', line 18346

def comment_targets
  [keyword_loc, *lparen_loc, *arguments, *rparen_loc] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



18339
18340
18341
18342
18343
# File 'lib/prism/node.rb', line 18339

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact << arguments if arguments
  compact
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, lparen_loc: self.lparen_loc, arguments: self.arguments, rparen_loc: self.rparen_loc) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?lparen_loc: Location?, ?arguments: ArgumentsNode?, ?rparen_loc: Location?) -> YieldNode



18351
18352
18353
# File 'lib/prism/node.rb', line 18351

def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, lparen_loc: self.lparen_loc, arguments: self.arguments, rparen_loc: self.rparen_loc)
  YieldNode.new(source, node_id, location, flags, keyword_loc, lparen_loc, arguments, rparen_loc)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, keyword_loc: Location, lparen_loc: Location?, arguments: ArgumentsNode?, rparen_loc: Location? }



18359
18360
18361
# File 'lib/prism/node.rb', line 18359

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

#inspectObject

def inspect -> String



18433
18434
18435
# File 'lib/prism/node.rb', line 18433

def inspect
  InspectVisitor.compose(self)
end

#keywordObject

def keyword: () -> String



18418
18419
18420
# File 'lib/prism/node.rb', line 18418

def keyword
  keyword_loc.slice
end

#keyword_locObject

attr_reader keyword_loc: Location



18364
18365
18366
18367
18368
# File 'lib/prism/node.rb', line 18364

def keyword_loc
  location = @keyword_loc
  return location if location.is_a?(Location)
  @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#lparenObject

def lparen: () -> String?



18423
18424
18425
# File 'lib/prism/node.rb', line 18423

def lparen
  lparen_loc&.slice
end

#lparen_locObject

attr_reader lparen_loc: Location?



18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
# File 'lib/prism/node.rb', line 18377

def lparen_loc
  location = @lparen_loc
  case location
  when nil
    nil
  when Location
    location
  else
    @lparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
  end
end

#rparenObject

def rparen: () -> String?



18428
18429
18430
# File 'lib/prism/node.rb', line 18428

def rparen
  rparen_loc&.slice
end

#rparen_locObject

attr_reader rparen_loc: Location?



18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
# File 'lib/prism/node.rb', line 18399

def rparen_loc
  location = @rparen_loc
  case location
  when nil
    nil
  when Location
    location
  else
    @rparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
  end
end

#save_keyword_loc(repository) ⇒ Object

Save the keyword_loc location using the given saved source so that it can be retrieved later.



18372
18373
18374
# File 'lib/prism/node.rb', line 18372

def save_keyword_loc(repository)
  repository.enter(node_id, :keyword_loc)
end

#save_lparen_loc(repository) ⇒ Object

Save the lparen_loc location using the given saved source so that it can be retrieved later.



18391
18392
18393
# File 'lib/prism/node.rb', line 18391

def save_lparen_loc(repository)
  repository.enter(node_id, :lparen_loc) unless @lparen_loc.nil?
end

#save_rparen_loc(repository) ⇒ Object

Save the rparen_loc location using the given saved source so that it can be retrieved later.



18413
18414
18415
# File 'lib/prism/node.rb', line 18413

def save_rparen_loc(repository)
  repository.enter(node_id, :rparen_loc) unless @rparen_loc.nil?
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



18438
18439
18440
# File 'lib/prism/node.rb', line 18438

def type
  :yield_node
end