Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dot formatter (Graphviz) #31

Merged
merged 1 commit into from
Dec 29, 2018
Merged

Add dot formatter (Graphviz) #31

merged 1 commit into from
Dec 29, 2018

Conversation

pocke
Copy link
Owner

@pocke pocke commented Dec 29, 2018

Ref: https://qiita.com/Nabetani/items/7904651fae1f925129c7

Note: It is experimental, and Dot formatter supports limited parsers (Ripper.sexp, Parser, RubyParser, and RubyVM::AST).

This formatter displays Dot language for Graphviz.
For example:

$ rpr -p rubyvm_ast -e 'p 1 + 1' -f dot
digraph{graph [dpi=288;];
b -> ROOT
b[ label="SCOPE" shape=oval ]
c -> b
c[ label="[]" shape=box ]
d -> b
d[ label="nil" shape=box ]
e -> b
e[ label="FCALL" shape=oval ]
f -> e
f[ label=":p" shape=box ]
g -> e
g[ label="ARRAY" shape=oval ]
h -> g
h[ label="OPCALL" shape=oval ]
i -> h
i[ label="LIT" shape=oval ]
j -> i
j[ label="1" shape=box ]
k -> h
k[ label=":+" shape=box ]
l -> h
l[ label="ARRAY" shape=oval ]
m -> l
m[ label="LIT" shape=oval ]
n -> m
n[ label="1" shape=box ]
o -> l
o[ label="nil" shape=box ]
p -> g
p[ label="nil" shape=box ]
}

Convert to PNG

$ rpr -p rubyvm_ast -e 'p 1 + 1' -f dot | dot -Tpng -oast.png
$ open ast.png

ast

@pocke pocke merged commit d7ea841 into master Dec 29, 2018
@coveralls
Copy link

Coverage Status

Coverage remained the same at 70.588% when pulling a6bec16 on dot-formatter into 56e3ad5 on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same at 70.588% when pulling a6bec16 on dot-formatter into 56e3ad5 on master.

@pocke pocke deleted the dot-formatter branch December 29, 2018 17:40
@pocke
Copy link
Owner Author

pocke commented Dec 29, 2018

ast

Sample image for README

@pocke
Copy link
Owner Author

pocke commented Dec 29, 2018

Updated the example image
ast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants