Class: Brainfucktt::Node

Inherits:
Treetop::Runtime::SyntaxNode
  • Object
show all
Defined in:
lib/brainfucktt/node.rb

Overview

The base class for Brainfucktt syntax nodes in the AST

Instance Method Summary collapse

Instance Method Details

#elements<Brainfucktt::Node>

The children of this Node instance.

Returns:



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

def elements
  super.find_all { |node| node.is_a?(Brainfucktt::Node) } rescue []
end

#inspect(indent = "") ⇒ String

Print out the AST of this instance node and it’s children with indentation.

Returns:

  • (String)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/brainfucktt/node.rb', line 25

def inspect(indent="")
  result = ""
  result << indent
  result << self.class.to_s.sub(/.*:/,'')
  result << " #{to_s} " unless self.is_a?(Language::Tree) || self.is_a?(Language::Loop)
  
  unless elements.empty?
    result << ":"
    elements.each do |e|
      result << "\n#{e.inspect(indent+"  ")}" rescue "\n#{indent} #{e.inspect}"
    end
  end
  
  result
end

#to_sString

Return the text value of this Node instance.

Returns:

  • (String)


18
19
20
# File 'lib/brainfucktt/node.rb', line 18

def to_s
  text_value
end