Anthony Mastrean
Anthony Mastrean

Reputation: 22384

How do I use Ant private target names as node_ids in the Graphviz/dot file format?

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

Upvotes: 0

Views: 109

Answers (1)

stefan
stefan

Reputation: 3749

simply

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

or

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

which allows nice short names for edges

Upvotes: 1

Related Questions