lib/graphviz/parser.rb in ruby-graphviz-0.9.9 vs lib/graphviz/parser.rb in ruby-graphviz-0.9.10
- old
+ new
@@ -56,15 +56,19 @@
@options = o
end
end
class Graph < Treetop::Runtime::SyntaxNode
- def eval( context, hOpts )
+ def eval( context, hOpts = [] )
# puts "GRAPH TYPE = #{type.text_value}"
# puts "GRAPH NAME = #{name.text_value}"
- hOpts = hOpts[0].merge( {:type => type.text_value} )
+ begin
+ hOpts = hOpts[0].merge( {:type => type.text_value} )
+ rescue
+ hOpts = {:type => type.text_value}
+ end
# Create Graph
context.graph = GraphViz.new( name.text_value.gsub(/"/, ""), hOpts )
# Eval cluster
@@ -229,22 +233,47 @@
context.graph = saved_graph
context.options = saved_options
end
end
- class Options < Treetop::Runtime::SyntaxNode
- def eval
- options = {}
- elements[2].elements.each do |e|
- # puts " #{e.elements[0].text_value} = #{e.elements[4].text_value}"
- options[e.elements[0].text_value] = e.elements[4].text_value.gsub( /"/, "" )
+ class AnonymousSubgraph < Treetop::Runtime::SyntaxNode
+ def eval( context )
+ # puts "CREATE ANONYMOUS SUBGRAPH"
+
+ # Save options
+ saved_options = context.options.clone
+ # Save graph
+ saved_graph = context.graph
+
+ # Create Graph
+ context.graph = context.graph.add_graph( )
+ #context.options = {
+ # :node => {},
+ # :edge => {}
+ #}
+
+ # Eval cluster
+ cluster.eval( context )
+
+ # Reinitialize graph and options
+ context.graph = saved_graph
+ context.options = saved_options
+ end
end
- # puts " #{elements[3].text_value} = #{elements[7].text_value}"
- options[elements[3].text_value] = elements[7].text_value.gsub( /"/, "" )
- return options
- end
-end
+ class Options < Treetop::Runtime::SyntaxNode
+ def eval
+ options = {}
+ elements[2].elements.each do |e|
+ # puts " #{e.elements[0].text_value} = #{e.elements[4].text_value}"
+ options[e.elements[0].text_value] = e.elements[4].text_value.gsub( /"/, "" )
+ end
+ # puts " #{elements[3].text_value} = #{elements[7].text_value}"
+ options[elements[3].text_value] = elements[7].text_value.gsub( /"/, "" )
+
+ return options
+ end
+ end
def self.parse( file, *hOpts, &block )
dot = open(file).read
parser = DotParser.new()
tree = parser.parse( dot )