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.



14872
14873
14874
14875
14876
14877
14878
14879
# File 'lib/prism/node.rb', line 14872

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



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

def locals
  @locals
end

#statementsObject (readonly)

attr_reader statements: StatementsNode



14918
14919
14920
# File 'lib/prism/node.rb', line 14918

def statements
  @statements
end

Class Method Details

.typeObject

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



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

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.



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

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



14882
14883
14884
# File 'lib/prism/node.rb', line 14882

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

#child_nodesObject Also known as: deconstruct

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



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

def child_nodes
  [statements]
end

#comment_targetsObject

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



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

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



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

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



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

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 }



14910
14911
14912
# File 'lib/prism/node.rb', line 14910

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

#inspectObject

def inspect -> String



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

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



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

def type
  :program_node
end