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.



15983
15984
15985
15986
15987
15988
15989
15990
# File 'lib/prism/node.rb', line 15983

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



16033
16034
16035
# File 'lib/prism/node.rb', line 16033

def locals
  @locals
end

#statementsObject (readonly)

attr_reader statements: StatementsNode



16036
16037
16038
# File 'lib/prism/node.rb', line 16036

def statements
  @statements
end

Class Method Details

.typeObject

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



16049
16050
16051
# File 'lib/prism/node.rb', line 16049

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.



16055
16056
16057
16058
16059
16060
# File 'lib/prism/node.rb', line 16055

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



15993
15994
15995
# File 'lib/prism/node.rb', line 15993

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



15998
15999
16000
# File 'lib/prism/node.rb', line 15998

def child_nodes
  [statements]
end

#comment_targetsObject

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



16015
16016
16017
# File 'lib/prism/node.rb', line 16015

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



16010
16011
16012
# File 'lib/prism/node.rb', line 16010

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



16020
16021
16022
# File 'lib/prism/node.rb', line 16020

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 }



16028
16029
16030
# File 'lib/prism/node.rb', line 16028

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

#each_child_node {|statements| ... } ⇒ Object

def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator

Yields:



16003
16004
16005
16006
16007
# File 'lib/prism/node.rb', line 16003

def each_child_node
  return to_enum(:each_child_node) unless block_given?

  yield statements
end

#inspectObject

def inspect -> String



16039
16040
16041
# File 'lib/prism/node.rb', line 16039

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



16044
16045
16046
# File 'lib/prism/node.rb', line 16044

def type
  :program_node
end