Class: RDG::Tree::AST

Inherits:
Object
  • Object
show all
Defined in:
lib/rdg/tree/ast.rb

Defined Under Namespace

Classes: Node

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast) ⇒ AST

Returns a new instance of AST.



17
18
19
20
# File 'lib/rdg/tree/ast.rb', line 17

def initialize(ast)
  @graph = Graph::BidirectedAdjacencyGraph.new
  import(ast)
end

Class Method Details

.from_path(path, parser = Parser::CurrentRuby) ⇒ Object



9
10
11
# File 'lib/rdg/tree/ast.rb', line 9

def self.from_path(path, parser = Parser::CurrentRuby)
  from_source(File.read(path), parser)
end

.from_source(source, parser = Parser::CurrentRuby) ⇒ Object



13
14
15
# File 'lib/rdg/tree/ast.rb', line 13

def self.from_source(source, parser = Parser::CurrentRuby)
  new(parser.parse(source))
end

Instance Method Details

#post_order_iteratorObject



30
31
32
# File 'lib/rdg/tree/ast.rb', line 30

def post_order_iterator
  RGL::PostOrderIterator.new(@graph)
end

#pre_order_iteratorObject



26
27
28
# File 'lib/rdg/tree/ast.rb', line 26

def pre_order_iterator
  RGL::PreOrderIterator.new(@graph)
end

#rootObject



22
23
24
# File 'lib/rdg/tree/ast.rb', line 22

def root
  @graph.each_vertex.first
end

#write_to_graphic_file(format = 'png', filename = "ast") ⇒ Object



34
35
36
# File 'lib/rdg/tree/ast.rb', line 34

def write_to_graphic_file(format = 'png', filename = "ast")
  @graph.write_to_graphic_file(format, filename)
end