From 91a5a5dfcb94b92dd68e8b95d05cb22eb3b149bf Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Mon, 1 Oct 2018 14:28:44 -0300 Subject: [PATCH 1/2] 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 --- lark/tree.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lark/tree.py b/lark/tree.py index 719ac81..fb40aa2 100644 --- a/lark/tree.py +++ b/lark/tree.py @@ -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] From d8c9e1b5e13bcb43b408ffe8fabb8554fd1c28e6 Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Mon, 1 Oct 2018 14:35:34 -0300 Subject: [PATCH 2/2] Fixed SyntaxError: positional argument follows keyword argument on lark/tree.py --- lark/tree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lark/tree.py b/lark/tree.py index fb40aa2..c406f45 100644 --- a/lark/tree.py +++ b/lark/tree.py @@ -138,7 +138,7 @@ def pydot__tree_to_png(tree, filename, rankdir="LR"): """ import pydot - graph = pydot.Dot(graph_type='digraph', rankdir) + graph = pydot.Dot(graph_type='digraph', rankdir=rankdir) i = [0]