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



8258
8259
8260
8261
8262
# File 'lib/yarp/node.rb', line 8258

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

Instance Attribute Details

#localsObject (readonly)

attr_reader locals: Array



8252
8253
8254
# File 'lib/yarp/node.rb', line 8252

def locals
  @locals
end

#statementsObject (readonly)

attr_reader statements: StatementsNode



8255
8256
8257
# File 'lib/yarp/node.rb', line 8255

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



8265
8266
8267
# File 'lib/yarp/node.rb', line 8265

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

#child_nodesObject Also known as: deconstruct

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



8270
8271
8272
# File 'lib/yarp/node.rb', line 8270

def child_nodes
  [statements]
end

#comment_targetsObject

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



8275
8276
8277
# File 'lib/yarp/node.rb', line 8275

def comment_targets
  [statements]
end

#copy(**params) ⇒ Object

def copy: (**params) -> ProgramNode



8280
8281
8282
8283
8284
8285
8286
# File 'lib/yarp/node.rb', line 8280

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]



8292
8293
8294
# File 'lib/yarp/node.rb', line 8292

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

#inspect(inspector = NodeInspector.new) ⇒ Object



8296
8297
8298
8299
8300
8301
8302
# File 'lib/yarp/node.rb', line 8296

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  inspector << "├── locals: #{locals.inspect}\n"
  inspector << "└── statements:\n"
  inspector << inspector.child_node(statements, "    ")
  inspector.to_str
end