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.



14878
14879
14880
14881
14882
14883
14884
14885
# File 'lib/prism/node.rb', line 14878

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



14921
14922
14923
# File 'lib/prism/node.rb', line 14921

def locals
  @locals
end

#statementsObject (readonly)

attr_reader statements: StatementsNode



14924
14925
14926
# File 'lib/prism/node.rb', line 14924

def statements
  @statements
end

Class Method Details

.typeObject

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



14937
14938
14939
# File 'lib/prism/node.rb', line 14937

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.



14943
14944
14945
14946
14947
14948
# File 'lib/prism/node.rb', line 14943

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



14888
14889
14890
# File 'lib/prism/node.rb', line 14888

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

#child_nodesObject Also known as: deconstruct

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



14893
14894
14895
# File 'lib/prism/node.rb', line 14893

def child_nodes
  [statements]
end

#comment_targetsObject

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



14903
14904
14905
# File 'lib/prism/node.rb', line 14903

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



14898
14899
14900
# File 'lib/prism/node.rb', line 14898

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



14908
14909
14910
# File 'lib/prism/node.rb', line 14908

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 }



14916
14917
14918
# File 'lib/prism/node.rb', line 14916

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

#inspectObject

def inspect -> String



14927
14928
14929
# File 'lib/prism/node.rb', line 14927

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



14932
14933
14934
# File 'lib/prism/node.rb', line 14932

def type
  :program_node
end