0

Passing the following dot file as input to dot2tex results in a parse exception. If I remove the ",2", the error disappears.

  digraph G {
    node [shape="circle"];
    1,2 [style="filled"];
    1 -> { 2; 3; 4 }
    2 -> { 5; 6 }
    4 -> { 7; 8 }
    5 -> { 9; 10 }
    7 -> { 11; 12 }
  }

I have seen it work in the past under Ubuntu. Currently I'm using cygwin64, with Python 2.7.10 and dot2tex 2.9.0. I'm no Python expert, but it seems that installing dot2tex from source, using python setup.py install, also installed a version of PyParsing. After running dot2tex with the --debug switch, it seems from dot2tex.log that I now have version 2.0.7 of PyParsing:

File "/usr/lib/python2.7/site-packages/pyparsing-2.0.7-py2.7.egg/pyparsing.py", line 1129, in parseString
    raise exc
ParseException: Expected "}" (at char 46), (line:3, col:6)

Where is the problem coming from?

PaulMcG
  • 62,419
  • 16
  • 94
  • 130
user2023370
  • 10,488
  • 6
  • 50
  • 83

1 Answers1

1

I'm guessing that the pyparsing grammar in dot2tex does not support this form:

1,2 [style="filled"];

Would this work?

1 [style="filled"];
2 [style="filled"];

EDIT:

You can try this converter on your auto-generated .dot file before feeding it to 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)

prints:

  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 }
  }
PaulMcG
  • 62,419
  • 16
  • 94
  • 130