Class: Kaguya::AST::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/kaguya/ast/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, parent:) ⇒ Node

Returns a new instance of Node.

Parameters:

  • type (Symbol)
  • parent (Node)


12
13
14
15
16
17
18
# File 'lib/kaguya/ast/node.rb', line 12

def initialize(type:, parent:)
  @type = type
  @parent = parent
  @children = []

  @parent.children << self if @parent
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



7
8
9
# File 'lib/kaguya/ast/node.rb', line 7

def children
  @children
end

#parentObject (readonly)

Returns the value of attribute parent.



6
7
8
# File 'lib/kaguya/ast/node.rb', line 6

def parent
  @parent
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/kaguya/ast/node.rb', line 8

def type
  @type
end

Instance Method Details

#accept(compiler) ⇒ Array

Parameters:

Returns:

  • (Array)


22
23
24
# File 'lib/kaguya/ast/node.rb', line 22

def accept(compiler)
  compiler.visit(self)
end

#to_sString

Returns:

  • (String)


27
28
29
# File 'lib/kaguya/ast/node.rb', line 27

def to_s
  @type.to_s
end