Skip to content

Commit

Permalink
fix(dot): add start state automate convention
Browse files Browse the repository at this point in the history
  • Loading branch information
Joxit committed Oct 11, 2023
1 parent 699176f commit a67ed4d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/fst/dot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ pub fn dot_write_file<W: Write>(fst: &TaskFst, writer: &mut W) -> std::io::Resul
let node = iter.next().unwrap();
let label = node.label.replace("\"", "\\\"");
let id = format_id(&node.label);

let shape = if node.next.len() == 0 {
"doublecircle"
} else {
"circle"
};

if node.prev.len() == 0 {
writeln!(writer, r#" init_{}[label="", shape=point]"#, id)?;
writeln!(writer, r#" init_{} -> {0}"#, id)?;
}

writeln!(writer, r#" {}[label="{}" shape={}]"#, id, label, shape)?;
for next in node.next {
writeln!(writer, " {} -> {}", id, format_id(&fst.states[next].label))?;
Expand Down Expand Up @@ -83,9 +90,13 @@ mod test {
assert_eq!(
result,
r#"digraph {
init_a[label="", shape=point]
init_a -> a
a[label="\"a\"" shape=circle]
a -> b_a_ba
a -> c
init_e[label="", shape=point]
init_e -> e
e[label="e" shape=circle]
e -> ds
b_a_ba[label="b a ba" shape=circle]
Expand Down

0 comments on commit a67ed4d

Please sign in to comment.