Coder Social home page Coder Social logo

dot_tools's Introduction

Dot Tools - Parser for Graphviz's Dot Language

by Tim Henderson ([email protected])

This module provides a parser for the dot langauge. You can use it to produce an AST of a *.dot file. It deals correctly with the language as specified on in the graphviz documentation. If you find it cannot parse your dot file open an issue and let me know.

Example:

from dot_tools import parse

tree = parse('digraph { x [label=<<b>I am an html label</b>>] x -> y }')
print tree

Output (a pre-order enumeration of the tree, deserialize with betterast)

1:Graphs
3:Graph
0:digraph
0:graph_1001
2:Stmts
1:Nodes
2:Node
0:x
1:Attrs
2:=
0:label
0:<b>I am an html label</b>
1:Edges
2:->
0:x
0:y

It also supports visualizing the AST as dot:

print tree.dotty()

Output (after running it through graphviz)

ast.png

Finally, you can use the built-in "SimpleGraph" to load the nodes and edges in a graph. Note, this format does not support all the features of the dot language (for instance, subgraphs, attributes other than label, etc...).

from dot_tools.dot_graph import SimpleGraph

g = SimpleGraph.build(tree.kid('Graph'))
print g.nodes
print g.edges

Output

{'y': 'y', 'x': '<b>I am an html label</b>'}
[('x', 'y', '')]

dot_tools's People

Contributors

timtadh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dot_tools's Issues

SyntaxError: LexToken(LCURLY,'{',11,355)

Hi,

I am trying to generate an AST of a Control Flow Graph of a simple Hello World program in C. I generated the DOT file using GCC's -fdump-tree-cfg-graph. When I tried to use the parse function, I got an error SyntaxError: LexToken(LCURLY,'{',11,355). I am assuming the problem is most likely the regex/lexer for strings(ID) in the DOT file does not include '{' or '}'.

The command to generate the DOT file

gcc HelloWorld.c -fdump-tree-cfg-graph

I am also attaching the source code and the generated DOT file

HelloWorld.zip

Problem importing dot_tools with python-3

Hello,

The module works fine if I try it out on python-2.7 using pip install dot_tools. I run ubuntu 18.4.

However it doesn't work with python3. Is there a fix for this?

I also tried out installing dot_tools using pip3, but running an example script still has import errors :

Traceback (most recent call last):
File "test.py", line 1, in
from dot_tools import parse
ImportError: cannot import name 'parse'

Any suggestions? Both pip list and pip3 list show that dot_tools installed.

Problem getting dot_tools

I just switched centos VMs and my new one fails with
pip install dot_tools
Collecting dot_tools
Could not find a version that satisfies the requirement dot_tools (from versions: )
No matching distribution found for dot_tools

I checked on pypi and didn't see dot_tools.
python -V
Python 2.7.5

uname -a
Linux bpm 3.10.0-862.2.3.el7.x86_64 #1 SMP Wed May 9 18:05:47 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

What else can I look at?

Thx,
Joe

dot_tools not accessible after installation with setup.py

I'd like to try out dot_tools. Unfortunately, I'm not able to get it working.

I installed it with the following command:

python setup.py install

pip list shows that dot-tools 0.1 is installed.

When actually trying to import it as described in the README, I'm getting the following error:

Traceback (most recent call last):
  File "dotplay.py", line 1, in <module>
    from dot_tools import parser
ImportError: cannot import name 'parser'

Am I missing something?

BTW, Pip actually reports "dot-tools" instead of "dot_tools"...

Python version: 3.6.7
pip version: 18.1
setup tools version: 40.4.2
OS: macos 10.11.6

Thank you in advance!
Max

SyntaxError: LexToken(COLON,':',4,57)

I'm getting

SyntaxError: LexToken(COLON,':',4,57)

when processing this DOT file.

The issue is probably caused by the fact that the label attribute inside of [] is spread over two lines. Putting these attributes into a single line, i.e.

"0" [label="0: BBlock(#9) idom: None"]

solves the issue.

Graphviz' dot 2.40.1 does process the unmodified file just fine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.