Class: YARP::ProgramNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
ext/yarp/api_node.c

Overview

The top level node of any parse tree.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locals, statements, location) ⇒ ProgramNode

def initialize: (locals: Array, statements: StatementsNode, location: Location) -> void



6167
6168
6169
6170
6171
# File 'lib/yarp/node.rb', line 6167

def initialize(locals, statements, location)
  @locals = locals
  @statements = statements
  @location = location
end

Instance Attribute Details

#localsObject (readonly)

attr_reader locals: Array



6161
6162
6163
# File 'lib/yarp/node.rb', line 6161

def locals
  @locals
end

#statementsObject (readonly)

attr_reader statements: StatementsNode



6164
6165
6166
# File 'lib/yarp/node.rb', line 6164

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



6174
6175
6176
# File 'lib/yarp/node.rb', line 6174

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

#child_nodesObject Also known as: deconstruct

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



6179
6180
6181
# File 'lib/yarp/node.rb', line 6179

def child_nodes
  [statements]
end

#copy(**params) ⇒ Object

def copy: (**params) -> ProgramNode



6184
6185
6186
6187
6188
6189
6190
# File 'lib/yarp/node.rb', line 6184

def copy(**params)
  ProgramNode.new(
    params.fetch(:locals) { locals },
    params.fetch(:statements) { statements },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



6196
6197
6198
# File 'lib/yarp/node.rb', line 6196

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