0

I want to create a graph of Ant tasks and dependencies using the dot file format and Graphviz. Like many Ant scripts, these use "private targets". That is, target names starting with a dash (-).

I am taking a list of tasks like

<target name="foo" depends="-init">
<target name="-init">

And creating a dot file like this (it's a little verbose, but that's not a problem).

digraph {
  foo;
  foo -> -init;
  -init;
}

I try to run that through the dot program to create a .PNG and it complains about the dash in the node_id!

> dot -Tpng -o graph.png graph.gv
Error: graph.gv:3: syntax error near line 3
context:  >>> - <<< init;

I can replace all the dashes with underscores or something, but that messes up searchability back to the source file. Is there some way to escape or encode dashes so I can keep the source information correct?


I'm having trouble finding a comprehensive dot file format or language description. This describes the AST, but doesn't define valid values of node_id.

http://www.graphviz.org/content/dot-language

Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
  • possible duplicate of [Node name with dash and dot and < and >](http://stackoverflow.com/questions/18444406/node-name-with-dash-and-dot-and-and) – marapet Mar 18 '15 at 21:23

1 Answers1

1

simply

digraph {
  foo;
  foo -> "-init";
  "-init";
}

or

digraph {
  foo;
  foo -> init;
  init [label="-init"];
}

which allows nice short names for edges

stefan
  • 3,681
  • 15
  • 25