rust_dot Code
RustDOT is mostly the Graphviz DOT language, lightly rustified.
Brought to you by:
pfeiffer
File | Date | Author | Commit |
---|---|---|---|
src | 2024-05-03 |
![]() |
[55bb28] v0.6.0: Implement html ids. |
.gitignore | 2024-02-18 |
![]() |
[4a66bf] Initial working release v0.1.0 |
Cargo.toml | 2024-05-03 |
![]() |
[55bb28] v0.6.0: Implement html ids. |
ChangeLog | 2024-05-03 |
![]() |
[55bb28] v0.6.0: Implement html ids. |
README.md | 2024-05-03 |
![]() |
[55bb28] v0.6.0: Implement html ids. |
RustDOT is mostly the Graphviz DOT language, lightly rustified.
It can be embedded as a macro or parsed from a string or file.
The purpose is extracting the stucture. Layout hints are currently out of scope.
let g1 = rust_dot! {
graph {
A -- B -- C; /* semicolon is optional */
"B" -- D // quotes not needed here
}
};
println!("{} {} \"{}\" {:?} {:?}", g1.strict, g1.directed, g1.name, g1.nodes, g1.edges);
// false false "" ["A", "B", "C", "D"] [(0, 1), (1, 2), (1, 3)]
let g2 = parse_string("digraph Didi { -1 -> 2 -> .3 2 -> 4.2 }");
println!("{} {} \"{}\" {:?} {:?}", g2.strict, g2.directed, g2.name, g2.nodes, g2.edges);
// false true "Didi" ["-1", "2", ".3", "4.2"] [(0, 1), (1, 2), (1, 3)]
The return values can be fed to crates petgraph
:
let mut petgraph = petgraph::graph::Graph::new();
let nodes: Vec<_> = rust_dot_graph.nodes
.iter()
.map(|node| petgraph
.add_node(node))
.collect();
for edge in rust_dot_graph.edges {
petgraph
.add_edge(nodes[edge.0], nodes[edge.1], ());
};
or graph
/graph_builder
:
use graph::prelude::*;
let graph: DirectedCsrGraph<usize> = GraphBuilder::new()
.csr_layout(CsrLayout::Sorted)
.edges(rust_dot_graph.edges)
.build();
This is work in progress. Nothing is stabilised!
strict
, it is currently ignored/skippedParser
, which should be internal)Deal with graph attributes, with and without keyword graph
Reimplement rust_dot
as a proc-macro, transforming its input as const at compile time
Rust macros are tokenised by the Rust lexer, which is subtly different from Graphviz. For consistency (and ease of
implementation) the parse_*
functions use the same lexer. These are the consequences:
parse_*
functions may also be UTF-16 or Latin-1.graphviz
<<I>"</I> <B> )}] [{( </B> \\>
<<I>"<!--"--></I> <B><!--"--> )}] [{( <!--"--></B> <!--"-->\\<!--"-->>
[,;.:!?]
(incomplete and wrong for some languages.)parse_*
rust_dot!
] you must use raw strings like r"\N"
when they contain unrusty#
on the same line is also discarded. Unlike real comments, these arerust_dot!
] you must use //
instead! (Only the nightly compiler gives access to line numbers in macros.)rust_dot!
]) confusable letters like cyrillic ‘о’ or