ripper_tree 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32e723df924fac02d663df047f40ea67ab760e23
4
- data.tar.gz: 10838e66ce8303381411cb0bb455c58bfb58e79c
3
+ metadata.gz: efb38adab6fad648b10c3c7fb100c6c7443f40f3
4
+ data.tar.gz: 271b928334b81a47a0734cc2188841a2630d5e06
5
5
  SHA512:
6
- metadata.gz: 44bd022c7d118863e4126cea39d3714bfcfa4d0981b7e2cd5c7b5f1bfa1aa670be73d17e6f5332a02de5db25e610418c10ab735db4cffcfed5c66dca50261716
7
- data.tar.gz: 0db04716450e29710c0fce7a6adac01a5d8f9cd73760f4f575f60c77b8158eaa49f45ccbf4b0c225bd5f21f7e8d7fca75d4b1b177ad494757ac23a7e883add04
6
+ metadata.gz: a8528a1c45506f517620fe3226cf9293ee4ef8e31a772e51a8dce83ee9e77ae02d3fea3a1d4be80c180f34df2bf782a15ee93c7258052a59bcab93e4802bddc2
7
+ data.tar.gz: ef0b256a981a8d95ed08acbf1aa848e9488274d4fee84bbdab193c0325816a2f72ce94afef84652d852cf85577cc0c08696d88d98afe5fd2ad7e6cb85207ff41
data/README.md CHANGED
@@ -31,9 +31,9 @@ result
31
31
  ```ruby
32
32
  :program
33
33
  └──── :binary
34
- ├──── :@int [1] 1:0
34
+ ├──── :@int ["1"] 1:0
35
35
  ├──── :+
36
- └──── :@int [1] 1:4
36
+ └──── :@int ["1"] 1:4
37
37
  ```
38
38
 
39
39
  if use in ruby code.
@@ -64,7 +64,7 @@ result
64
64
 
65
65
  :program
66
66
  └──── :command
67
- ├──── :@ident [puts] 1:0
67
+ ├──── :@ident ["puts"] 1:0
68
68
  └──── :args_add_block
69
69
  ├──── :string_literal
70
70
  │ └──── :string_content
@@ -83,12 +83,12 @@ result
83
83
  ```ruby
84
84
  :program
85
85
  └──── :binary
86
- ├──── :@int [1] 1:0
86
+ ├──── :@int ["1"] 1:0
87
87
  ├──── :+
88
88
  └──── :binary
89
- ├──── :@int [2] 1:2
89
+ ├──── :@int ["2"] 1:2
90
90
  ├──── :*
91
- └──── :@int [3] 1:4
91
+ └──── :@int ["3"] 1:4
92
92
  ```
93
93
 
94
94
  ## Contributing
@@ -1,3 +1,3 @@
1
1
  class RipperTree
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
data/lib/ripper_tree.rb CHANGED
@@ -6,11 +6,11 @@ class RipperTree
6
6
  T_LINE = '├────'
7
7
  I_LINE = '│'
8
8
  L_LINE = '└────'
9
- VALUE_TOKEN = /@CHAR|@ident|@kw|@regexp_end|@period|@op|@int|@float|@rational|@label|@ivar|@imaginary|@const|@cvar|@gvar/.freeze
9
+ SCANNER_EVENT = /^(@CHAR|@const|@cvar|@float|@gvar|@ident|@imaginary|@int|@ivar|@kw|@label|@op|@period|@rational|@regexp_end|@tstring_content)$/
10
10
 
11
- def self.create(src)
11
+ def self.create(code)
12
12
  new.tap do |rtree|
13
- rtree.parse(Ripper.sexp(src))
13
+ rtree.parse(Ripper.sexp(code))
14
14
  end
15
15
  end
16
16
 
@@ -30,22 +30,18 @@ class RipperTree
30
30
  end_line ? ' ' * RipperTree::OPTIONS[:space_size] : I_LINE + ' ' * (RipperTree::OPTIONS[:space_size]-1)
31
31
  end
32
32
 
33
- def output_id(id)
33
+ def output_event_id(id)
34
34
  "#{id.inspect}\n".colorize(:magenta)
35
35
  end
36
36
 
37
- def output_string_node(node)
38
- "#{node[0].inspect.colorize(:blue)} [#{node[1].inspect.colorize(:red)}] #{node[2].join(':')}\n"
39
- end
40
-
41
37
  def output_value_node(node)
42
- "#{node[0].inspect.colorize(:blue)} [#{node[1]}] #{node[2].join(':')}\n"
38
+ "#{node[0].inspect.colorize(:blue)} [#{node[1].inspect.colorize(:red)}] #{node[2].join(':')}\n"
43
39
  end
44
40
 
45
41
  def parse_method_arguments(parent, space: ' ')
46
42
  id = parent.first
47
43
 
48
- @queue << output_id(id)
44
+ @queue << output_event_id(id)
49
45
 
50
46
  params = parent[1..-1].zip(%i(pars opts rest pars2 kws kwrest blk))
51
47
 
@@ -55,7 +51,7 @@ class RipperTree
55
51
  @queue << get_line(end_line: params.empty?, space: space)
56
52
 
57
53
  if param.instance_of?(Array)
58
- @queue << output_id(arg_type)
54
+ @queue << output_event_id(arg_type)
59
55
 
60
56
  if arg_type == :kwrest
61
57
  s = space + get_space(end_line: params.empty? && param.empty?)
@@ -112,31 +108,28 @@ class RipperTree
112
108
  end
113
109
 
114
110
  def parse(parent, space: ' ')
115
- if parent.first.instance_of?(Array)
111
+ event_id, *nodes = parent
112
+
113
+ if event_id.instance_of?(Array)
116
114
  parse(parent.first, space: space)
117
115
  return
118
116
  end
119
117
 
120
- id = parent.first
121
-
122
- case id
123
- when /@tstring_content/
124
- @queue << output_string_node(parent)
125
- return
126
- when VALUE_TOKEN
118
+ case event_id
119
+ when SCANNER_EVENT
127
120
  @queue << output_value_node(parent)
128
121
  return
129
122
  when /array/
130
- @queue << output_id(id)
131
- children = parent[1].nil? ? [] : parent[1]
123
+ @queue << output_event_id(event_id)
124
+ nodes = parent[1].nil? ? [] : parent[1]
132
125
 
133
- until children.empty?
134
- child = children.shift
135
- next if child == :args_add_star
136
- next if child == []
126
+ until nodes.empty?
127
+ node = nodes.shift
128
+ next if node == :args_add_star
129
+ next if node == []
137
130
 
138
- @queue << get_line(end_line: children.empty?, space: space)
139
- parse(child, space: space + get_space(end_line: children.empty?))
131
+ @queue << get_line(end_line: nodes.empty?, space: space)
132
+ parse(node, space: space + get_space(end_line: nodes.empty?))
140
133
  end
141
134
 
142
135
  return
@@ -144,40 +137,30 @@ class RipperTree
144
137
  parse_method_arguments(parent, space: space)
145
138
  return
146
139
  when /void_stmt/
147
- @queue << output_id(id)
140
+ @queue << output_event_id(event_id)
148
141
  return
149
142
  else
150
- @queue << output_id(id)
151
- end
143
+ @queue << output_event_id(event_id)
152
144
 
153
- child_count = parent[1..-1].count { |e| e.instance_of?(Array) }
145
+ until nodes.empty?
146
+ node = nodes.shift
154
147
 
155
- if child_count.zero?
156
- unless parent[1..-1].all?(&:nil?)
157
- @queue << "#{space}#{parent[1..-1].map(&:inspect).join(', ')}"
158
- end
159
- else
160
- children = parent[1..-1]
161
-
162
- until children.empty?
163
- child = children.shift
164
-
165
- if child.instance_of?(Array)
166
- if child.all? { |e| e.instance_of?(Array) }
167
- until child.empty?
168
- node = child.shift
169
- @queue << get_line(end_line: children.empty? && child.empty?, space: space)
170
- parse(node, space: space + get_space(end_line: children.empty? && child.empty?))
148
+ if node.instance_of?(Array) && !node.empty?
149
+ if node.all? { |e| e.instance_of?(Array) }
150
+ until node.empty?
151
+ event = node.shift
152
+ @queue << get_line(end_line: nodes.empty? && node.empty?, space: space)
153
+ parse(event, space: space + get_space(end_line: nodes.empty? && node.empty?))
154
+ end
155
+ else
156
+ @queue << get_line(end_line: nodes.empty?, space: space)
157
+ parse(node, space: space + get_space(end_line: nodes.empty?))
171
158
  end
172
159
  else
173
- @queue << get_line(end_line: children.empty?, space: space)
174
- parse(child, space: space + get_space(end_line: children.empty?))
160
+ @queue << get_line(end_line: nodes.empty?, space: space)
161
+ @queue << "#{node.inspect}\n"
175
162
  end
176
- else
177
- @queue << get_line(end_line: children.empty?, space: space)
178
- @queue << "#{child.inspect}\n"
179
163
  end
180
- end
181
164
  end
182
165
  end
183
166
  end
data/ripper_tree.gemspec CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
10
10
  spec.authors = ["siman-man"]
11
11
  spec.email = ["k128585@ie.u-ryukyu.ac.jp"]
12
12
 
13
- spec.summary = %q{tree command like viewer}
14
- spec.description = %q{tree command like viewer}
13
+ spec.summary = %q{RipperTree is like tree command for Ripper#sexp.}
14
+ spec.description = %q{RipperTree is like tree command for Ripper#sexp.}
15
15
  spec.homepage = "https://github.com/siman-man/ripper_tree"
16
16
  spec.license = "MIT"
17
17
  spec.required_ruby_version = '>= 2.1.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ripper_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - siman-man
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-24 00:00:00.000000000 Z
11
+ date: 2017-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
- description: tree command like viewer
69
+ description: RipperTree is like tree command for Ripper#sexp.
70
70
  email:
71
71
  - k128585@ie.u-ryukyu.ac.jp
72
72
  executables:
@@ -111,5 +111,5 @@ rubyforge_project:
111
111
  rubygems_version: 2.6.10
112
112
  signing_key:
113
113
  specification_version: 4
114
- summary: tree command like viewer
114
+ summary: RipperTree is like tree command for Ripper#sexp.
115
115
  test_files: []