Class: Prism::EmbeddedStatementsNode

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

Overview

Represents an interpolated set of statements.

"foo #{bar}"
     ^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, opening_loc, statements, closing_loc) ⇒ EmbeddedStatementsNode

Initialize a new EmbeddedStatementsNode node.



6417
6418
6419
6420
6421
6422
6423
6424
6425
# File 'lib/prism/node.rb', line 6417

def initialize(source, node_id, location, flags, opening_loc, statements, closing_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @opening_loc = opening_loc
  @statements = statements
  @closing_loc = closing_loc
end

Instance Attribute Details

#statementsObject (readonly)

attr_reader statements: StatementsNode?



6476
6477
6478
# File 'lib/prism/node.rb', line 6476

def statements
  @statements
end

Class Method Details

.typeObject

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



6512
6513
6514
# File 'lib/prism/node.rb', line 6512

def self.type
  :embedded_statements_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.



6518
6519
6520
6521
6522
6523
# File 'lib/prism/node.rb', line 6518

def ===(other)
  other.is_a?(EmbeddedStatementsNode) &&
    (opening_loc.nil? == other.opening_loc.nil?) &&
    (statements === other.statements) &&
    (closing_loc.nil? == other.closing_loc.nil?)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



6428
6429
6430
# File 'lib/prism/node.rb', line 6428

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

#child_nodesObject Also known as: deconstruct

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



6433
6434
6435
# File 'lib/prism/node.rb', line 6433

def child_nodes
  [statements]
end

#closingObject

def closing: () -> String



6497
6498
6499
# File 'lib/prism/node.rb', line 6497

def closing
  closing_loc.slice
end

#closing_locObject

attr_reader closing_loc: Location



6479
6480
6481
6482
6483
# File 'lib/prism/node.rb', line 6479

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

#comment_targetsObject

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



6445
6446
6447
# File 'lib/prism/node.rb', line 6445

def comment_targets
  [opening_loc, *statements, closing_loc] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



6438
6439
6440
6441
6442
# File 'lib/prism/node.rb', line 6438

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

#copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, statements: self.statements, closing_loc: self.closing_loc) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location, ?statements: StatementsNode?, ?closing_loc: Location) -> EmbeddedStatementsNode



6450
6451
6452
# File 'lib/prism/node.rb', line 6450

def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, statements: self.statements, closing_loc: self.closing_loc)
  EmbeddedStatementsNode.new(source, node_id, location, flags, opening_loc, statements, closing_loc)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, opening_loc: Location, statements: StatementsNode?, closing_loc: Location }



6458
6459
6460
# File 'lib/prism/node.rb', line 6458

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

#inspectObject

def inspect -> String



6502
6503
6504
# File 'lib/prism/node.rb', line 6502

def inspect
  InspectVisitor.compose(self)
end

#openingObject

def opening: () -> String



6492
6493
6494
# File 'lib/prism/node.rb', line 6492

def opening
  opening_loc.slice
end

#opening_locObject

attr_reader opening_loc: Location



6463
6464
6465
6466
6467
# File 'lib/prism/node.rb', line 6463

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

#save_closing_loc(repository) ⇒ Object

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



6487
6488
6489
# File 'lib/prism/node.rb', line 6487

def save_closing_loc(repository)
  repository.enter(node_id, :closing_loc)
end

#save_opening_loc(repository) ⇒ Object

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



6471
6472
6473
# File 'lib/prism/node.rb', line 6471

def save_opening_loc(repository)
  repository.enter(node_id, :opening_loc)
end

#typeObject

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



6507
6508
6509
# File 'lib/prism/node.rb', line 6507

def type
  :embedded_statements_node
end