use dot_parser::ast;
use dot_parser::canonical;
static DOT_STR: &str = "graph {
A [label=A][color=grey]
B [label=B][color=grey]
C [label=C]
D [label=D]
A -- B -- subgraph { C D }
}";
fn main() {
let ast_graph = ast::Graph::try_from(DOT_STR).unwrap();
let canonical_graph = canonical::Graph::from(ast_graph.clone());
println!("Showing all attributes using ast::Graph:");
for stmt in ast_graph.stmts {
if let ast::Stmt::NodeStmt(n) = stmt {
if let Some(attr_list) = n.attr {
for alist in attr_list {
for (attr, val) in alist {
println!("({}, {})", attr, val);
}
}
}
}
}
println!("\nShowing all attributes using canonical::Graph:");
for node in canonical_graph.nodes.set.values() {
for (attr, val) in &node.attr {
println!("({}, {})", attr, val);
}
}
println!("\nShowing all edges using canonical::Graph:");
for edge in canonical_graph.edges.set {
println!("{} -- {}", edge.from, edge.to);
}
}