Class: Prism::ProgramNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
sig/generated/prism/node.rbs,
ext/prism/api_node.c

Overview

The top level node of any parse tree.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, locals, statements) ⇒ ProgramNode

Initialize a new ProgramNode node.

: (Source source, Integer node_id, Location location, Integer flags, Array locals, StatementsNode statements) -> void

Parameters:



27458
27459
27460
27461
27462
27463
27464
27465
# File 'lib/prism/node.rb', line 27458

def initialize(source, node_id, location, flags, locals, statements)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @locals = locals
  @statements = statements
end

Class Method Details

.type ⇒ :program_node

See Node.type.

: () -> :program_node

Returns:

  • (:program_node)


27545
27546
27547
# File 'lib/prism/node.rb', line 27545

def self.type
  :program_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


27581
27582
27583
27584
27585
27586
# File 'lib/prism/node.rb', line 27581

def ===(other) # :nodoc:
  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

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


27481
27482
27483
# File 'lib/prism/node.rb', line 27481

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

#child_nodes ⇒ Array[node?] Also known as: deconstruct

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


27488
27489
27490
# File 'lib/prism/node.rb', line 27488

def child_nodes
  [statements]
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


27505
27506
27507
# File 'lib/prism/node.rb', line 27505

def compact_child_nodes
  [statements]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, statements: self.statements) ⇒ ProgramNode

:call-seq:

copy(**fields) -> ProgramNode

Creates a copy of self with the given fields, using self as the template.

: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?statements: StatementsNode) -> ProgramNode

Parameters:

  • node_id: (Integer) (defaults to: self.node_id)
  • location: (Location) (defaults to: self.location)
  • flags: (Integer) (defaults to: self.flags)
  • locals: (Array[Symbol]) (defaults to: self.locals)
  • statements: (StatementsNode) (defaults to: self.statements)

Returns:



27515
27516
27517
# File 'lib/prism/node.rb', line 27515

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) ⇒ Hash[Symbol, untyped]

: (Array? keys) -> Hash[Symbol, untyped]

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


27522
27523
27524
27525
27526
27527
27528
27529
27530
27531
27532
27533
# File 'lib/prism/node.rb', line 27522

def deconstruct_keys(keys) # :nodoc:
  (keys || i[node_id location locals statements]).each_with_object(
    {} #: Hash[Symbol, untyped]
  ) do |key, deconstructed|
    case key
    when :node_id                 then deconstructed[:node_id] = self.node_id
    when :location                then deconstructed[:location] = self.location
    when :locals                  then deconstructed[:locals] = self.locals
    when :statements              then deconstructed[:statements] = self.statements
    end
  end
end

#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void

See Node.each_child_node.

: () -> Enumerator[node, void] : () { (node) -> void } -> void

Overloads:

  • #each_child_node ⇒ Enumerator[node, void]

    Returns:

    • (Enumerator[node, void])
  • #each_child_node ⇒ void

    This method returns an undefined value.

Yields:

Yield Parameters:

  • arg0 (node)

Yield Returns:

  • (void)


27496
27497
27498
27499
27500
# File 'lib/prism/node.rb', line 27496

def each_child_node(&blk)
  return to_enum(:each_child_node) unless block_given?

  yield statements
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


27550
27551
27552
# File 'lib/prism/node.rb', line 27550

def inspect # :nodoc:
  InspectVisitor.compose(self)
end

#locals ⇒ Array[Symbol]

:call-seq:

locals -> Array[Symbol]

Returns the locals attribute.

: () -> Array

Returns:

  • (Array[Symbol])


27562
27563
27564
# File 'lib/prism/node.rb', line 27562

def locals
  @locals
end

#statements ⇒ StatementsNode

:call-seq:

statements -> StatementsNode

Returns the statements attribute.

: () -> StatementsNode

Returns:



27572
27573
27574
# File 'lib/prism/node.rb', line 27572

def statements
  @statements
end

#type ⇒ :program_node

See Node#type.

: () -> :program_node

Returns:

  • (:program_node)


27538
27539
27540
# File 'lib/prism/node.rb', line 27538

def type
  :program_node
end