Class: Bade::AST::Node

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, parent = nil, lineno: nil, filename: nil) ⇒ Node

Returns a new instance of Node.



31
32
33
34
35
36
37
# File 'lib/bade/ast/node.rb', line 31

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

Instance Attribute Details

#childrenArray<Bade::AST::Node>

Returns:



19
20
21
# File 'lib/bade/ast/node.rb', line 19

def children
  @children
end

#filenameString (readonly)

Returns filename.

Returns:



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

def filename
  @filename
end

#linenoInt (readonly)

Returns line number.

Returns:

  • (Int)

    line number



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

def lineno
  @lineno
end

#parentBade::AST::Node?

Returns:



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

def parent
  @parent
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)


52
53
54
55
56
# File 'lib/bade/ast/node.rb', line 52

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

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

#inspectObject



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

def inspect
  to_s
end

#to_sObject



39
40
41
42
# File 'lib/bade/ast/node.rb', line 39

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