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.



15086
15087
15088
15089
15090
15091
15092
15093
# File 'lib/prism/node.rb', line 15086

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



15129
15130
15131
# File 'lib/prism/node.rb', line 15129

def locals
  @locals
end

#statementsObject (readonly)

attr_reader statements: StatementsNode



15132
15133
15134
# File 'lib/prism/node.rb', line 15132

def statements
  @statements
end

Class Method Details

.typeObject

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



15145
15146
15147
# File 'lib/prism/node.rb', line 15145

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.



15151
15152
15153
15154
15155
15156
# File 'lib/prism/node.rb', line 15151

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



15096
15097
15098
# File 'lib/prism/node.rb', line 15096

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



15101
15102
15103
# File 'lib/prism/node.rb', line 15101

def child_nodes
  [statements]
end

#comment_targetsObject

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



15111
15112
15113
# File 'lib/prism/node.rb', line 15111

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



15106
15107
15108
# File 'lib/prism/node.rb', line 15106

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



15116
15117
15118
# File 'lib/prism/node.rb', line 15116

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 }



15124
15125
15126
# File 'lib/prism/node.rb', line 15124

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

#inspectObject

def inspect -> String



15135
15136
15137
# File 'lib/prism/node.rb', line 15135

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



15140
15141
15142
# File 'lib/prism/node.rb', line 15140

def type
  :program_node
end