我猜dot2tex中的pyparsing语法不支持这种形式:
1,2 [style="filled"];
这行得通吗?
1 [style="filled"];
2 [style="filled"];
编辑:
您可以在自动生成的 .dot 文件上尝试使用此转换器,然后再将其提供给 dot2tex:
from pyparsing import *
sample = """\
digraph G {
node [shape="circle"];
1,2 [style="filled"];
3,4 [size = 27.1];
1 -> { 2; 3; 4 }
2 -> { 5; 6 }
4 -> { 7; 8 }
5 -> { 9; 10 }
7 -> { 11; 12 }
}"""
# just guessing on these, they are probably close
node_id = Word(alphanums+"_")
attr_id = Word(alphas, alphanums+"_")
attr_val = quotedString | pyparsing_common.fnumber
attr_spec = attr_id + '=' + attr_val
multiple_node_attr = (Group(delimitedList(node_id))("nodes")
+ originalTextFor("[" + delimitedList(attr_spec) + "]" + ";")("attrs"))
# ignore definitions that have only one node, no need to mess with them
multiple_node_attr.addCondition(lambda t: len(t.nodes) > 1)
# define parse-time callback to expand node lists to separate node definitions
def expand_multiple_node_specs(s,l,tokens):
indent = (col(l,s)-1)*" "
join_str = '\n' + indent
return join_str.join("{} {}".format(nd, tokens.attrs) for nd in tokens.nodes)
multiple_node_attr.addParseAction(expand_multiple_node_specs)
# use transformString to apply changes in parse actions
modified = multiple_node_attr.transformString(sample)
print(modified)
印刷:
digraph G {
node [shape="circle"];
1 [style="filled"];
2 [style="filled"];
3 [size = 27.1];
4 [size = 27.1];
1 -> { 2; 3; 4 }
2 -> { 5; 6 }
4 -> { 7; 8 }
5 -> { 9; 10 }
7 -> { 11; 12 }
}