Class: Prism::ProgramNode

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

Overview

The top level node of any parse tree.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, locals, statements) ⇒ ProgramNode

Initialize a new ProgramNode node.



13421
13422
13423
13424
13425
13426
13427
13428
# File 'lib/prism/node.rb', line 13421

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

Instance Attribute Details

#localsObject (readonly)

attr_reader locals: Array



13464
13465
13466
# File 'lib/prism/node.rb', line 13464

def locals
  @locals
end

#statementsObject (readonly)

attr_reader statements: StatementsNode



13467
13468
13469
# File 'lib/prism/node.rb', line 13467

def statements
  @statements
end

Class Method Details

.typeObject

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



13480
13481
13482
# File 'lib/prism/node.rb', line 13480

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



13486
13487
13488
13489
13490
13491
# File 'lib/prism/node.rb', line 13486

def ===(other)
  other.is_a?(ProgramNode) &&
    (locals.length == other.locals.length) &&
    locals.zip(other.locals).all? { |left, right| left === right } &&
    (statements === other.statements)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



13431
13432
13433
# File 'lib/prism/node.rb', line 13431

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

#child_nodesObject Also known as: deconstruct

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



13436
13437
13438
# File 'lib/prism/node.rb', line 13436

def child_nodes
  [statements]
end

#comment_targetsObject

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



13446
13447
13448
# File 'lib/prism/node.rb', line 13446

def comment_targets
  [statements] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



13441
13442
13443
# File 'lib/prism/node.rb', line 13441

def compact_child_nodes
  [statements]
end

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

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?statements: StatementsNode) -> ProgramNode



13451
13452
13453
# File 'lib/prism/node.rb', line 13451

def copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, statements: self.statements)
  ProgramNode.new(source, node_id, location, flags, locals, statements)
end

#deconstruct_keys(keys) ⇒ Object

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



13459
13460
13461
# File 'lib/prism/node.rb', line 13459

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

#inspectObject

def inspect -> String



13470
13471
13472
# File 'lib/prism/node.rb', line 13470

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



13475
13476
13477
# File 'lib/prism/node.rb', line 13475

def type
  :program_node
end