Browse Source

Allow to pass to lark/tree.py pydot__tree_to_png the pydot tree

shaping. For example, passing "TB" instead of "LR" makes the tree
to be draw vertically instead of horizontally.

https://stackoverflow.com/questions/29003465/pydot-graphviz-how-to-order-horizontally-nodes-in-a-cluster-while-the-rest-of-t
tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.6.5
evandrocoan 6 years ago
parent
commit
91a5a5dfcb
1 changed files with 9 additions and 3 deletions
  1. +9
    -3
      lark/tree.py

+ 9
- 3
lark/tree.py View File

@@ -128,11 +128,17 @@ class SlottedTree(Tree):
__slots__ = 'data', 'children', 'rule', '_meta'


def pydot__tree_to_png(tree, filename):
"Creates a colorful image that represents the tree (data+children, without meta)"
def pydot__tree_to_png(tree, filename, rankdir="LR"):
"""Creates a colorful image that represents the tree (data+children, without meta)

Possible values for `rankdir` are "TB", "LR", "BT", "RL", corresponding to
directed graphs drawn from top to bottom, from left to right, from bottom to
top, and from right to left, respectively. See:
https://www.graphviz.org/doc/info/attrs.html#k:rankdir
"""

import pydot
graph = pydot.Dot(graph_type='digraph', rankdir="LR")
graph = pydot.Dot(graph_type='digraph', rankdir)

i = [0]



Loading…
Cancel
Save