A utility class to generate DOT diagrams (graphviz) from arbitrary trees. You can pass in your own templates and can pass in any kind of tree or use Tree interface method. I wanted this separator so that you don't have to include ST just to use the org.antlr.runtime.tree.* package. This is a set of non-static methods so you can subclass to override. For example, here is an invocation:

 CharStream input = new ANTLRInputStream(System.in);
 TLexer lex = new TLexer(input);
 CommonTokenStream tokens = new CommonTokenStream(lex);
 TParser parser = new TParser(tokens);
 TParser.e_return r = parser.e();
 Tree t = (Tree)r.tree;
 System.out.println(t.toStringTree());
 DOTTreeGenerator gen = new DOTTreeGenerator();
 StringTemplate st = gen.toDOT(t);
 System.out.println(st);

Hierarchy

  • DotTreeGenerator

Index

Properties

edgeFormat

edgeFormat: string = " {0} -> {1} // "{2}" -> "{3}""

footer

footer: string = "}"

headerLines

headerLines: string[] = ["digraph {","","\tordering=out;","\tranksep=.4;","\tbgcolor=\"lightgrey\"; node [shape=box, fixedsize=false, fontsize=12, fontname=\"Helvetica-bold\", fontcolor=\"blue\"","\t\twidth=.25, height=.25, color=\"black\", fillcolor=\"white\", style=\"filled, solid, bold\"];","\tedge [arrowsize=.5, color=\"black\", style=\"bold\"]",""]

nodeFormat

nodeFormat: string = " {0} [label="{1}"];"

nodeNumber

nodeNumber: number = 0

Track node number so we can get unique node names

nodeToNumberMap

nodeToNumberMap: Dictionary<any, number> = new Dictionary<any, number>()

Track node to number mapping so we can get proper node name back

Methods

defineEdges

Protected defineNodes

Protected fixString

  • fixString(text: string): string
  • Parameters

    • text: string

    Returns string

Protected getNodeNumber

  • getNodeNumber(t: any): number
  • Parameters

    • t: any

    Returns number

Protected getNodeText

toDot

  • toDot(tree: ITree): string
  • Parameters

    Returns string

toDot2

  • Generate DOT (graphviz) for a whole tree not just a node. For example, 3+4*5 should generate:

    digraph { node [shape=plaintext, fixedsize=true, fontsize=11, fontname="Courier", width=.4, height=.2]; edge [arrowsize=.7] "+"->3 "+"->"" ""->4 "*"->5 }

    Takes a Tree interface object.

    Parameters

    Returns string

Generated using TypeDoc