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.



18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
# File 'lib/prism/node.rb', line 18527

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?



18606
18607
18608
# File 'lib/prism/node.rb', line 18606

def arguments
  @arguments
end

Class Method Details

.typeObject

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



18653
18654
18655
# File 'lib/prism/node.rb', line 18653

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.



18659
18660
18661
18662
18663
18664
18665
# File 'lib/prism/node.rb', line 18659

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



18539
18540
18541
# File 'lib/prism/node.rb', line 18539

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



18544
18545
18546
# File 'lib/prism/node.rb', line 18544

def child_nodes
  [arguments]
end

#comment_targetsObject

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



18556
18557
18558
# File 'lib/prism/node.rb', line 18556

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



18549
18550
18551
18552
18553
# File 'lib/prism/node.rb', line 18549

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



18561
18562
18563
# File 'lib/prism/node.rb', line 18561

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



18569
18570
18571
# File 'lib/prism/node.rb', line 18569

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



18643
18644
18645
# File 'lib/prism/node.rb', line 18643

def inspect
  InspectVisitor.compose(self)
end

#keywordObject

def keyword: () -> String



18628
18629
18630
# File 'lib/prism/node.rb', line 18628

def keyword
  keyword_loc.slice
end

#keyword_locObject

attr_reader keyword_loc: Location



18574
18575
18576
18577
18578
# File 'lib/prism/node.rb', line 18574

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?



18633
18634
18635
# File 'lib/prism/node.rb', line 18633

def lparen
  lparen_loc&.slice
end

#lparen_locObject

attr_reader lparen_loc: Location?



18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
# File 'lib/prism/node.rb', line 18587

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?



18638
18639
18640
# File 'lib/prism/node.rb', line 18638

def rparen
  rparen_loc&.slice
end

#rparen_locObject

attr_reader rparen_loc: Location?



18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
# File 'lib/prism/node.rb', line 18609

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.



18582
18583
18584
# File 'lib/prism/node.rb', line 18582

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.



18601
18602
18603
# File 'lib/prism/node.rb', line 18601

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.



18623
18624
18625
# File 'lib/prism/node.rb', line 18623

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



18648
18649
18650
# File 'lib/prism/node.rb', line 18648

def type
  :yield_node
end