ruby_ast_visualizer 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +27 -16
- data/bin/ruby_ast_visualizer +6 -3
- data/lib/ruby_ast_visualizer.rb +8 -8
- data/lib/ruby_ast_visualizer/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d69af471a20f595af80957cdb5527f8cc5d191b7
|
4
|
+
data.tar.gz: 63284a298caae3c0337bd2aef57b4aefda3a02e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c00e893fa21a2bd739761bb1bc3021fb02e917884561cdf0b9a9bbba39fa049fe1ad808c0a56fcaf2b9f600c4f4b5bbdfb28612a85ce8c294e585d70d6cca58
|
7
|
+
data.tar.gz: 1406f749c11f7230b4fae09baffa626d8ebbaef563187da06266e5dd594eb6585145ce30f6dbf261a6bbbf4e278d716b1184f99d485a396bac78f0743872165a
|
data/README.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
Ruby AST Visualizer. Based on [Parser](https://github.com/whitequark/parser).
|
4
4
|
|
5
|
+
## Install
|
6
|
+
|
7
|
+
```sh
|
8
|
+
$ gem install ruby_ast_visualizer
|
9
|
+
```
|
10
|
+
|
5
11
|
## Usage
|
6
12
|
|
7
13
|
An example `ruby_ast_visualizer` command.
|
@@ -10,12 +16,22 @@ An example `ruby_ast_visualizer` command.
|
|
10
16
|
$ cat hello.rb
|
11
17
|
puts 'hello, world'
|
12
18
|
$ ruby_ast_visualizer hello.rb
|
19
|
+
|
20
|
+
(send nil :puts
|
21
|
+
(str "hello, world"))
|
22
|
+
|
23
|
+
Wrote a.png
|
13
24
|
```
|
14
25
|
|
15
26
|
or
|
16
27
|
|
17
28
|
```sh
|
18
29
|
$ ruby_ast_visualizer -e 'puts "hello, world"'
|
30
|
+
|
31
|
+
(send nil :puts
|
32
|
+
(str "hello, world"))
|
33
|
+
|
34
|
+
Wrote a.png
|
19
35
|
```
|
20
36
|
|
21
37
|
AST image file is generated.
|
@@ -28,31 +44,26 @@ You can specify output path in the `-o` option. That value is default a.png.
|
|
28
44
|
|
29
45
|
```sh
|
30
46
|
$ ruby_ast_visualizer -o path/to/file -e 'puts "hello, world"'
|
31
|
-
```
|
32
|
-
|
33
|
-
## Requirements
|
34
|
-
|
35
|
-
* Graphviz
|
36
47
|
|
37
|
-
|
38
|
-
|
39
|
-
Add these lines to your application's Gemfile:
|
48
|
+
(send nil :puts
|
49
|
+
(str "hello, world"))
|
40
50
|
|
41
|
-
|
42
|
-
gem 'ruby_ast_visualizer'
|
51
|
+
Wrote path/to/file
|
43
52
|
```
|
44
53
|
|
45
|
-
And
|
54
|
+
And you can also specify the `-n` (`--no-image`) option if you don't need an image.
|
55
|
+
You can only get the result of S-expression by Parser gem.
|
46
56
|
|
47
57
|
```sh
|
48
|
-
$
|
58
|
+
$ ruby_ast_visualizer -n -e 'puts "hello, world"'
|
59
|
+
|
60
|
+
(send nil :puts
|
61
|
+
(str "hello, world"))
|
49
62
|
```
|
50
63
|
|
51
|
-
|
64
|
+
## Requirements
|
52
65
|
|
53
|
-
|
54
|
-
$ gem install ruby_ast_visualizer
|
55
|
-
```
|
66
|
+
* Graphviz
|
56
67
|
|
57
68
|
## Contributing
|
58
69
|
|
data/bin/ruby_ast_visualizer
CHANGED
@@ -16,9 +16,10 @@ Version = RubyAstVisualizer::VERSION
|
|
16
16
|
|
17
17
|
options = {}
|
18
18
|
|
19
|
-
opt = OptionParser.new("usage: ruby_ast_visualizer [-o output_path] [-e 'command'] [programfile]")
|
19
|
+
opt = OptionParser.new("usage: ruby_ast_visualizer [-o output_path] [-n] [-e 'command'] [programfile]")
|
20
20
|
|
21
21
|
opt.on('-e', "--eval 'command'") {|v| options[:eval] = v }
|
22
|
+
opt.on('-n', "--no-image") {|v| options[:no_image] = v }
|
22
23
|
opt.on('-o', '--output path/to/file (DEFAULT a.png)') {|v| options[:output] = v }
|
23
24
|
|
24
25
|
begin
|
@@ -36,13 +37,15 @@ begin
|
|
36
37
|
|
37
38
|
ast = Parser::CurrentRuby.parse(source)
|
38
39
|
|
39
|
-
puts "\n#{ast}\n
|
40
|
+
puts "\n#{ast}\n"
|
41
|
+
|
42
|
+
exit unless options[:no_image].nil?
|
40
43
|
|
41
44
|
result = RubyAstVisualizer::Core.new(ast).visualize
|
42
45
|
|
43
46
|
result.output(png: file_name)
|
44
47
|
|
45
|
-
puts "
|
48
|
+
puts "\nWrote #{file_name}"
|
46
49
|
rescue
|
47
50
|
puts opt.help
|
48
51
|
|
data/lib/ruby_ast_visualizer.rb
CHANGED
@@ -18,19 +18,19 @@ module RubyAstVisualizer
|
|
18
18
|
def reconfigure(g, node)
|
19
19
|
self_node = g.add_nodes(fetch_node_id(node), label: node.type)
|
20
20
|
|
21
|
-
node.children.each {|
|
22
|
-
label = case
|
23
|
-
when Integer;
|
21
|
+
node.children.each {|child|
|
22
|
+
label = case child
|
23
|
+
when Integer; child
|
24
24
|
when NilClass; 'nil'
|
25
|
-
when String; "\"#{
|
26
|
-
when Symbol; ":#{
|
25
|
+
when String; "\"#{child}\""
|
26
|
+
when Symbol; ":#{child}"
|
27
27
|
else
|
28
|
-
|
28
|
+
child.type.to_s
|
29
29
|
end
|
30
30
|
|
31
|
-
self_node << g.add_nodes(fetch_node_id(
|
31
|
+
self_node << g.add_nodes(fetch_node_id(child), label: label)
|
32
32
|
|
33
|
-
reconfigure(g,
|
33
|
+
reconfigure(g, child) if child.respond_to? :children
|
34
34
|
}
|
35
35
|
end
|
36
36
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_ast_visualizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koichi ITO
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
71
|
version: '0'
|
72
72
|
requirements: []
|
73
73
|
rubyforge_project:
|
74
|
-
rubygems_version: 2.
|
74
|
+
rubygems_version: 2.6.13
|
75
75
|
signing_key:
|
76
76
|
specification_version: 4
|
77
77
|
summary: Ruby AST Visualizer.
|