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.



18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
# File 'lib/prism/node.rb', line 18285

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?



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

def arguments
  @arguments
end

Class Method Details

.typeObject

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



18411
18412
18413
# File 'lib/prism/node.rb', line 18411

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.



18417
18418
18419
18420
18421
18422
18423
# File 'lib/prism/node.rb', line 18417

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



18297
18298
18299
# File 'lib/prism/node.rb', line 18297

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

#child_nodesObject Also known as: deconstruct

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



18302
18303
18304
# File 'lib/prism/node.rb', line 18302

def child_nodes
  [arguments]
end

#comment_targetsObject

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



18314
18315
18316
# File 'lib/prism/node.rb', line 18314

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



18307
18308
18309
18310
18311
# File 'lib/prism/node.rb', line 18307

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



18319
18320
18321
# File 'lib/prism/node.rb', line 18319

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? }



18327
18328
18329
# File 'lib/prism/node.rb', line 18327

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



18401
18402
18403
# File 'lib/prism/node.rb', line 18401

def inspect
  InspectVisitor.compose(self)
end

#keywordObject

def keyword: () -> String



18386
18387
18388
# File 'lib/prism/node.rb', line 18386

def keyword
  keyword_loc.slice
end

#keyword_locObject

attr_reader keyword_loc: Location



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

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?



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

def lparen
  lparen_loc&.slice
end

#lparen_locObject

attr_reader lparen_loc: Location?



18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
# File 'lib/prism/node.rb', line 18345

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?



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

def rparen
  rparen_loc&.slice
end

#rparen_locObject

attr_reader rparen_loc: Location?



18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
# File 'lib/prism/node.rb', line 18367

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.



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

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.



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

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.



18381
18382
18383
# File 'lib/prism/node.rb', line 18381

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`.



18406
18407
18408
# File 'lib/prism/node.rb', line 18406

def type
  :yield_node
end