Class: Prism::ProgramNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ProgramNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
The top level node of any parse tree.
Instance Attribute Summary collapse
-
#locals ⇒ Object
readonly
attr_reader locals: Array.
-
#statements ⇒ Object
readonly
attr_reader statements: StatementsNode.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#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.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(source, node_id, location, flags, locals, statements) ⇒ ProgramNode
constructor
Initialize a new ProgramNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#type ⇒ Object
Return a symbol representation of this node type.
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
#locals ⇒ Object (readonly)
attr_reader locals: Array
14915 14916 14917 |
# File 'lib/prism/node.rb', line 14915 def locals @locals end |
#statements ⇒ Object (readonly)
attr_reader statements: StatementsNode
14918 14919 14920 |
# File 'lib/prism/node.rb', line 14918 def statements @statements end |
Class Method Details
.type ⇒ Object
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_nodes ⇒ Object 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_targets ⇒ Object
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_nodes ⇒ Object
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
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 |
#inspect ⇒ Object
def inspect -> String
14921 14922 14923 |
# File 'lib/prism/node.rb', line 14921 def inspect InspectVisitor.compose(self) end |
#type ⇒ Object
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 |