DotTreeGenerator Class
Namespace: Stimulsoft.Data.Expressions.Antlr.Runtime.Tree
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);
Methods
| Method | Returns | Description |
|---|---|---|
| defineEdges | string[] | |
| defineNodes | string[] | |
| fixString | string | |
| getNodeNumber | number | |
| getNodeText | string | |
| toDot | string | |
| toDot2 | string | Generate DOT (graphviz) for a whole tree not just a node. For example, 3+45 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. |
Method Details
defineEdges
defineEdges(tree: any, adaptor: ITreeAdaptor): string[]
Parameters
- tree (any)
- adaptor (ITreeAdaptor)
Returns string[]
defineNodes
defineNodes(tree: any, adaptor: ITreeAdaptor): string[]
Parameters
- tree (any)
- adaptor (ITreeAdaptor)
Returns string[]
fixString
fixString(text: string): string
Parameters
- text (string)
Returns string
getNodeNumber
getNodeNumber(t: any): number
Parameters
- t (any)
Returns number
getNodeText
getNodeText(adaptor: ITreeAdaptor, t: any): string
Parameters
- adaptor (ITreeAdaptor)
- t (any)
Returns string
toDot
toDot(tree: ITree): string
Parameters
- tree (ITree)
Returns string
toDot2
toDot2(tree: any, adaptor: ITreeAdaptor): string
Generate DOT (graphviz) for a whole tree not just a node. For example, 3+45 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
- tree (any)
- adaptor (ITreeAdaptor)
Returns string
Fields
| Field | Type | Description |
|---|---|---|
| edgeFormat | any | |
| footer | any | |
| headerLines | string[] | |
| nodeFormat | any | |
| nodeNumber | any | Track node number so we can get unique node names |
| nodeToNumberMap | any | Track node to number mapping so we can get proper node name back |
| text | any | |
| text | any | |
| text | any | |
| text | any | |
| text | any |