Class: RDG::Tree::AST
- Inherits:
-
Object
- Object
- RDG::Tree::AST
- Defined in:
- lib/rdg/tree/ast.rb
Defined Under Namespace
Classes: Node
Class Method Summary collapse
- .from_path(path, parser = Parser::CurrentRuby) ⇒ Object
- .from_source(source, parser = Parser::CurrentRuby) ⇒ Object
Instance Method Summary collapse
-
#initialize(ast) ⇒ AST
constructor
A new instance of AST.
- #post_order_iterator ⇒ Object
- #pre_order_iterator ⇒ Object
- #root ⇒ Object
- #write_to_graphic_file(format = 'png', filename = "ast") ⇒ Object
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_iterator ⇒ Object
30 31 32 |
# File 'lib/rdg/tree/ast.rb', line 30 def post_order_iterator RGL::PostOrderIterator.new(@graph) end |
#pre_order_iterator ⇒ Object
26 27 28 |
# File 'lib/rdg/tree/ast.rb', line 26 def pre_order_iterator RGL::PreOrderIterator.new(@graph) end |
#root ⇒ Object
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 |