class RDG::Tree::AST
Public Class Methods
from_path(path, parser = Parser::CurrentRuby)
click to toggle source
# 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)
click to toggle source
# File lib/rdg/tree/ast.rb, line 13 def self.from_source(source, parser = Parser::CurrentRuby) new(parser.parse(source)) end
new(ast)
click to toggle source
# File lib/rdg/tree/ast.rb, line 17 def initialize(ast) @graph = Graph::BidirectedAdjacencyGraph.new import(ast) end
Public Instance Methods
post_order_iterator()
click to toggle source
# File lib/rdg/tree/ast.rb, line 30 def post_order_iterator RGL::PostOrderIterator.new(@graph) end
pre_order_iterator()
click to toggle source
# File lib/rdg/tree/ast.rb, line 26 def pre_order_iterator RGL::PreOrderIterator.new(@graph) end
root()
click to toggle source
# File lib/rdg/tree/ast.rb, line 22 def root @graph.each_vertex.first end
write_to_graphic_file(format = 'png', filename = "ast")
click to toggle source
# 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
Private Instance Methods
import(ast)
click to toggle source
# File lib/rdg/tree/ast.rb, line 40 def import(ast) Node.new(ast, @graph).tap do |current_node| @graph.add_vertex(current_node) if ast.respond_to?(:children) ast.children.each do |child| @graph.add_edge(current_node, import(child)) end end end end