Class: Bade::AST::Node

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, lineno: nil) ⇒ Node

Returns a new instance of Node.



23
24
25
26
27
28
# File 'lib/bade/ast/node.rb', line 23

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

  @lineno = lineno
end

Instance Attribute Details

#childrenArray<Bade::Node>

Returns:



15
16
17
# File 'lib/bade/ast/node.rb', line 15

def children
  @children
end

#linenoInt (readonly)

Returns line number.

Returns:

  • (Int)

    line number



21
22
23
# File 'lib/bade/ast/node.rb', line 21

def lineno
  @lineno
end

#typeSymbol (readonly)

Returns type of this node.

Returns:

  • (Symbol)

    type of this node



11
12
13
# File 'lib/bade/ast/node.rb', line 11

def type
  @type
end

Instance Method Details

#==(other) ⇒ Bool

Parameters:

Returns:

  • (Bool)


43
44
45
46
47
# File 'lib/bade/ast/node.rb', line 43

def ==(other)
  return false unless self.class == other.class

  type == other.type && children == other.children
end

#inspectObject



35
36
37
# File 'lib/bade/ast/node.rb', line 35

def inspect
  to_s
end

#to_sObject



30
31
32
33
# File 'lib/bade/ast/node.rb', line 30

def to_s
  require_relative 'string_serializer'
  StringSerializer.new(self).to_s
end