parser_node_ext 0.10.0 → 1.0.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/CHANGELOG.md +9 -1
- data/Gemfile.lock +2 -2
- data/lib/parser_node_ext/version.rb +1 -1
- data/lib/parser_node_ext.rb +128 -36
- data/sig/parser_node_ext.rbs +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9650ac2c4cec4440ffc72ee28d8904f0583c6d9dfef3890060f5b52adeb28553
|
|
4
|
+
data.tar.gz: e3b0dc597dfeca91c977646ced5398673483de2161311bb3f7b9077d29802d9e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9bd6453cfbe47d33bd9326368d6ff8741178980aaa15e34ed9f5cccbfbd900fa70b007b825802ee36de49ba324ac22d13f38138f4639653d236af4b7347138c3
|
|
7
|
+
data.tar.gz: 8c477d4181a64b667a317c8d12924bd504604465f32381a9265f9604c4759b73b2fbffff70c8db5de9cabc27a93f54c5a94d212daa9d79cc3bf9f66b4784eda9
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 1.0.0 (2023-02-12)
|
|
4
|
+
|
|
5
|
+
* Support almost all of nodes
|
|
6
|
+
|
|
7
|
+
## 0.11.0 (2023-02-12)
|
|
8
|
+
|
|
9
|
+
* Support `self` node
|
|
10
|
+
|
|
3
11
|
## 0.10.0 (2023-02-01)
|
|
4
12
|
|
|
5
13
|
* Support `erange` and `irange` nodes
|
|
@@ -60,4 +68,4 @@
|
|
|
60
68
|
|
|
61
69
|
## 0.1.0 (2022-06-26)
|
|
62
70
|
|
|
63
|
-
* Abstract from synvert-core
|
|
71
|
+
* Abstract from synvert-core
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
parser_node_ext (0.
|
|
4
|
+
parser_node_ext (1.0.0)
|
|
5
5
|
parser
|
|
6
6
|
|
|
7
7
|
GEM
|
|
@@ -9,7 +9,7 @@ GEM
|
|
|
9
9
|
specs:
|
|
10
10
|
ast (2.4.2)
|
|
11
11
|
diff-lcs (1.5.0)
|
|
12
|
-
parser (3.2.
|
|
12
|
+
parser (3.2.1.0)
|
|
13
13
|
ast (~> 2.4.1)
|
|
14
14
|
rake (13.0.6)
|
|
15
15
|
rspec (3.11.0)
|
data/lib/parser_node_ext.rb
CHANGED
|
@@ -9,59 +9,111 @@ module ParserNodeExt
|
|
|
9
9
|
# Your code goes here...
|
|
10
10
|
|
|
11
11
|
TYPE_CHILDREN = {
|
|
12
|
+
alias: %i[new_name old_name],
|
|
12
13
|
and: %i[left_value right_value],
|
|
14
|
+
and_asgn: %i[variable value],
|
|
13
15
|
arg: %i[name],
|
|
14
16
|
array: %i[elements],
|
|
15
17
|
array_pattern: %i[elements],
|
|
18
|
+
array_pattern_with_tail: %i[elements],
|
|
19
|
+
back_ref: %i[name],
|
|
16
20
|
begin: %i[body],
|
|
17
21
|
block: %i[caller arguments body],
|
|
18
22
|
blockarg: %i[name],
|
|
23
|
+
block_pass: %i[name],
|
|
24
|
+
break: %i[expression],
|
|
19
25
|
case: %i[expression when_statements else_statement],
|
|
20
26
|
case_match: %i[expression in_statements else_statement],
|
|
27
|
+
casgn: %i[parent_const name value],
|
|
28
|
+
cbase: %i[],
|
|
29
|
+
complex: %i[value],
|
|
21
30
|
const: %i[parent_const name],
|
|
22
31
|
class: %i[name parent_class body],
|
|
23
32
|
csend: %i[receiver message arguments],
|
|
24
|
-
cvasgn: %i[
|
|
33
|
+
cvasgn: %i[variable value],
|
|
25
34
|
cvar: %i[name],
|
|
26
35
|
def: %i[name arguments body],
|
|
27
36
|
defined?: %i[arguments],
|
|
28
37
|
defs: %i[self name arguments body],
|
|
38
|
+
dstr: %i[elements],
|
|
39
|
+
dsym: %i[elements],
|
|
40
|
+
eflipflop: %i[begin end],
|
|
41
|
+
ensure: %i[body ensure_body],
|
|
29
42
|
erange: %i[begin end],
|
|
30
43
|
false: [],
|
|
31
44
|
find_pattern: %i[elements],
|
|
32
45
|
float: %i[value],
|
|
46
|
+
for: %i[variable expression body],
|
|
47
|
+
forward_args: [],
|
|
48
|
+
gvar: %i[name],
|
|
49
|
+
gvasgn: %i[variable value],
|
|
33
50
|
hash: %i[pairs],
|
|
34
51
|
hash_pattern: %i[pairs],
|
|
35
52
|
if: %i[expression if_statement else_statement],
|
|
53
|
+
iflipflop: %i[begin end],
|
|
36
54
|
if_guard: %i[expression],
|
|
37
55
|
int: %i[value],
|
|
38
56
|
in_pattern: %i[expression guard body],
|
|
39
57
|
irange: %i[begin end],
|
|
40
|
-
ivasgn: %i[
|
|
58
|
+
ivasgn: %i[variable value],
|
|
41
59
|
ivar: %i[name],
|
|
60
|
+
kwarg: %i[name],
|
|
61
|
+
kwbody: %i[body],
|
|
62
|
+
kwnilarg: [],
|
|
63
|
+
kwoptarg: %i[name value],
|
|
64
|
+
kwrestarg: %i[name],
|
|
65
|
+
kwsplat: %i[name],
|
|
42
66
|
lvar: %i[name],
|
|
43
|
-
lvasgn: %i[
|
|
44
|
-
masgn: %i[
|
|
67
|
+
lvasgn: %i[variable value],
|
|
68
|
+
masgn: %i[variable value],
|
|
45
69
|
match_as: %i[key value],
|
|
70
|
+
match_nil_pattern: [],
|
|
46
71
|
match_pattern: %i[left_value right_value],
|
|
47
72
|
match_pattern_p: %i[left_value right_value],
|
|
48
73
|
match_rest: %i[variable],
|
|
49
74
|
match_var: %i[name],
|
|
75
|
+
match_with_lvasgn: %i[left_value right_value],
|
|
76
|
+
mlhs: %i[elements],
|
|
50
77
|
module: %i[name body],
|
|
78
|
+
next: %i[expression],
|
|
51
79
|
nil: [],
|
|
80
|
+
nth_ref: %i[name],
|
|
52
81
|
numblock: %i[caller arguments_count body],
|
|
82
|
+
optarg: %i[name value],
|
|
83
|
+
op_asgn: %i[variable operator value],
|
|
53
84
|
or: %i[left_value right_value],
|
|
54
|
-
or_asgn: %i[
|
|
85
|
+
or_asgn: %i[variable value],
|
|
55
86
|
pair: %i[key value],
|
|
56
|
-
pin: %i[
|
|
87
|
+
pin: %i[expression],
|
|
88
|
+
postexe: %i[body],
|
|
89
|
+
preexe: %i[body],
|
|
90
|
+
rational: %i[value],
|
|
91
|
+
redo: [],
|
|
92
|
+
regexp: %i[elements options],
|
|
93
|
+
regopt: %i[elements],
|
|
94
|
+
resbody: %i[exceptions variable body],
|
|
95
|
+
rescue: %i[body rescue_bodies else_statement],
|
|
57
96
|
restarg: %i[name],
|
|
97
|
+
retry: [],
|
|
98
|
+
return: %i[expression],
|
|
99
|
+
sclass: %i[name body],
|
|
100
|
+
self: [],
|
|
101
|
+
shadowarg: %i[name],
|
|
58
102
|
send: %i[receiver message arguments],
|
|
103
|
+
splat: %i[name],
|
|
59
104
|
str: %i[value],
|
|
60
105
|
super: %i[arguments],
|
|
61
106
|
sym: %i[value],
|
|
62
107
|
true: [],
|
|
108
|
+
undef: %i[elements],
|
|
63
109
|
unless_guard: %i[expression],
|
|
110
|
+
until: %i[expression body],
|
|
111
|
+
until_post: %i[expression body],
|
|
64
112
|
when: %i[expression body],
|
|
113
|
+
while: %i[expression body],
|
|
114
|
+
while_post: %i[expression body],
|
|
115
|
+
xstr: %i[elements],
|
|
116
|
+
yield: %i[arguments],
|
|
65
117
|
zsuper: []
|
|
66
118
|
}
|
|
67
119
|
|
|
@@ -110,24 +162,8 @@ module ParserNodeExt
|
|
|
110
162
|
end
|
|
111
163
|
end
|
|
112
164
|
|
|
113
|
-
# Return the left value of node.
|
|
114
|
-
# It supports :and, :cvagn, :lvasgn, :masgn, :or and :or_asgn nodes.
|
|
115
|
-
# @example
|
|
116
|
-
# node # s(:or_asgn, s(:lvasgn, :a), s(:int, 1))
|
|
117
|
-
# node.left_value # :a
|
|
118
|
-
# @return [Parser::AST::Node] left value of node.
|
|
119
|
-
# @raise [MethodNotSupported] if calls on other node.
|
|
120
|
-
def left_value
|
|
121
|
-
return children[0].children[0] if type == :or_asgn
|
|
122
|
-
|
|
123
|
-
index = TYPE_CHILDREN[type]&.index(:left_value)
|
|
124
|
-
return children[index] if index
|
|
125
|
-
|
|
126
|
-
raise MethodNotSupported, "#{left_value} is not supported for #{self}"
|
|
127
|
-
end
|
|
128
|
-
|
|
129
165
|
# Get arguments of node.
|
|
130
|
-
# It supports :block, :csend, :def, :defined?, :defs
|
|
166
|
+
# It supports :block, :csend, :def, :defined?, :defs, :send, :yeild nodes.
|
|
131
167
|
# @example
|
|
132
168
|
# node # s(:send, s(:const, nil, :FactoryGirl), :create, s(:sym, :post), s(:hash, s(:pair, s(:sym, :title), s(:str, "post"))))
|
|
133
169
|
# node.arguments # [s(:sym, :post), s(:hash, s(:pair, s(:sym, :title), s(:str, "post")))]
|
|
@@ -143,7 +179,7 @@ module ParserNodeExt
|
|
|
143
179
|
children[1].children
|
|
144
180
|
when :send, :csend
|
|
145
181
|
children[2..-1]
|
|
146
|
-
when :defined
|
|
182
|
+
when :defined?, :yield
|
|
147
183
|
children
|
|
148
184
|
else
|
|
149
185
|
raise MethodNotSupported, "arguments is not supported for #{self}"
|
|
@@ -151,7 +187,7 @@ module ParserNodeExt
|
|
|
151
187
|
end
|
|
152
188
|
|
|
153
189
|
# Get body of node.
|
|
154
|
-
# It supports :begin, :block, :class, :def, :defs, :module, :numblock node.
|
|
190
|
+
# It supports :begin, :block, :class, :def, :defs, :ensure, :for, :module, :numblock, resbody, :sclass, :until, :until_post, :while and :while_post node.
|
|
155
191
|
# @example
|
|
156
192
|
# node # s(:block, s(:send, s(:const, nil, :RSpec), :configure), s(:args, s(:arg, :config)), s(:send, nil, :include, s(:const, s(:const, nil, :EmailSpec), :Helpers)))
|
|
157
193
|
# node.body # [s(:send, nil, :include, s(:const, s(:const, nil, :EmailSpec), :Helpers))]
|
|
@@ -159,20 +195,24 @@ module ParserNodeExt
|
|
|
159
195
|
# @raise [MethodNotSupported] if calls on other node.
|
|
160
196
|
def body
|
|
161
197
|
case type
|
|
162
|
-
when :begin
|
|
198
|
+
when :begin, :kwbegin
|
|
163
199
|
children
|
|
164
|
-
when :
|
|
200
|
+
when :rescue, :ensure, :preexe, :postexe
|
|
201
|
+
return [] if children[0].nil?
|
|
202
|
+
|
|
203
|
+
[:begin, :kwbegin].include?(children[0].type) ? children[0].body : [children[0]]
|
|
204
|
+
when :when, :module, :sclass, :until, :until_post, :while, :while_post
|
|
165
205
|
return [] if children[1].nil?
|
|
166
206
|
|
|
167
|
-
:begin
|
|
168
|
-
when :def, :block, :class, :numblock, :
|
|
207
|
+
[:begin, :kwbegin].include?(children[1].type) ? children[1].body : children[1..-1]
|
|
208
|
+
when :def, :block, :class, :for, :in_pattern, :numblock, :resbody
|
|
169
209
|
return [] if children[2].nil?
|
|
170
210
|
|
|
171
|
-
:begin
|
|
211
|
+
[:begin, :kwbegin].include?(children[2].type) ? children[2].body : children[2..-1]
|
|
172
212
|
when :defs
|
|
173
213
|
return [] if children[3].nil?
|
|
174
214
|
|
|
175
|
-
:begin
|
|
215
|
+
[:begin, :kwbegin].include?(children[3].type) ? children[3].body : children[3..-1]
|
|
176
216
|
else
|
|
177
217
|
raise MethodNotSupported, "body is not supported for #{self}"
|
|
178
218
|
end
|
|
@@ -189,6 +229,28 @@ module ParserNodeExt
|
|
|
189
229
|
end
|
|
190
230
|
end
|
|
191
231
|
|
|
232
|
+
# Get rescue bodies of resuce node.
|
|
233
|
+
# @return [Array<Parser::AST::Node>] rescue statements of rescue node.
|
|
234
|
+
# @raise [MethodNotSupported] if calls on other node.
|
|
235
|
+
def rescue_bodies
|
|
236
|
+
if :rescue == type
|
|
237
|
+
children[1...-1]
|
|
238
|
+
else
|
|
239
|
+
raise MethodNotSupported, "rescue_bodies is not supported for #{self}"
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
# Get ensure body of ensure node.
|
|
244
|
+
# @return [Array<Parser::AST::Node>] ensure body of ensure node.
|
|
245
|
+
# @raise [MethodNotSupported] if calls on other node.
|
|
246
|
+
def ensure_body
|
|
247
|
+
if :ensure == type
|
|
248
|
+
children[1..-1]
|
|
249
|
+
else
|
|
250
|
+
raise MethodNotSupported, "ensure_body is not supported for #{self}"
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
192
254
|
# Get in statements of case_match node.
|
|
193
255
|
# @return [Array<Parser::AST::Node>] in statements of case node.
|
|
194
256
|
# @raise [MethodNotSupported] if calls on other node.
|
|
@@ -200,24 +262,54 @@ module ParserNodeExt
|
|
|
200
262
|
end
|
|
201
263
|
end
|
|
202
264
|
|
|
203
|
-
# Get else statement of
|
|
204
|
-
# @return [Parser::AST::Node] else statement of
|
|
265
|
+
# Get else statement of node.
|
|
266
|
+
# @return [Parser::AST::Node] else statement of node.
|
|
205
267
|
# @raise [MethodNotSupported] if calls on other node.
|
|
206
268
|
def else_statement
|
|
207
269
|
children[-1]
|
|
208
270
|
end
|
|
209
271
|
|
|
210
|
-
# Get elements of :array and :
|
|
272
|
+
# Get elements of :array, :array_pattern, :array_pattern_with_tail, :find_pattern, :dstr, :dsym, :xstr, :regopt, :mlhs and :undef node.
|
|
211
273
|
# @return [Array<Parser::AST::Node>] elements of array node.
|
|
212
274
|
# @raise [MethodNotSupported] if calls on other node.
|
|
213
275
|
def elements
|
|
214
|
-
if %i[array array_pattern find_pattern].include?(type)
|
|
276
|
+
if %i[array array_pattern array_pattern_with_tail find_pattern dstr dsym xstr regopt mlhs undef].include?(type)
|
|
215
277
|
children
|
|
278
|
+
elsif type == :regexp
|
|
279
|
+
children[0...-1]
|
|
216
280
|
else
|
|
217
281
|
raise MethodNotSupported, "elements is not supported for #{self}"
|
|
218
282
|
end
|
|
219
283
|
end
|
|
220
284
|
|
|
285
|
+
# Get options of :regexp node.
|
|
286
|
+
# @example
|
|
287
|
+
# node # s(:regexp, s(:str, "foo"), s(:regopt, :i, :m))
|
|
288
|
+
# node.options # s(:regopt, :i, :m)
|
|
289
|
+
# @return [Parser::AST::Node] options of regexp node.
|
|
290
|
+
# @raise [MethodNotSupported] if calls on other node.
|
|
291
|
+
def options
|
|
292
|
+
if :regexp == type
|
|
293
|
+
children[-1]
|
|
294
|
+
else
|
|
295
|
+
raise MethodNotSupported, "options is not supported for #{self}"
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
# Get exceptions of :resbody node.
|
|
300
|
+
# @example
|
|
301
|
+
# node # s(:resbody, s(:array, (:const nil :Exception), (:const nil :A)), s(:lvasgn :bar), s(:int 1))
|
|
302
|
+
# node.exceptions # s(:array, (:const nil :Exception), (:const nil :A))
|
|
303
|
+
# @return [Parser::AST::Node] exceptions of resbody node.
|
|
304
|
+
# @raise [MethodNotSupported] if calls on other node.
|
|
305
|
+
def exceptions
|
|
306
|
+
if :resbody == type
|
|
307
|
+
children[0]
|
|
308
|
+
else
|
|
309
|
+
raise MethodNotSupported, "exceptions is not supported for #{self}"
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
|
|
221
313
|
# Get pairs of :hash and :hash_pattern node.
|
|
222
314
|
# @example
|
|
223
315
|
# node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)), s(:pair, s(:str, "foo"), s(:str, "bar")))
|
|
@@ -314,7 +406,7 @@ module ParserNodeExt
|
|
|
314
406
|
(children.first.to_value..children.last.to_value)
|
|
315
407
|
when :erange
|
|
316
408
|
(children.first.to_value...children.last.to_value)
|
|
317
|
-
when :begin
|
|
409
|
+
when :begin, :kwbegin
|
|
318
410
|
children.first.to_value
|
|
319
411
|
else
|
|
320
412
|
self
|
data/sig/parser_node_ext.rbs
CHANGED
|
@@ -9,8 +9,13 @@ module ParserNodeExt
|
|
|
9
9
|
def caller: () -> Parser::AST::Node
|
|
10
10
|
def elements: () -> Array[Parser::AST::Node]
|
|
11
11
|
def else_statement: () -> Parser::AST::Node
|
|
12
|
+
def exceptions: () -> Array[Parser::AST::Node]
|
|
12
13
|
def end: () -> Parser::AST::Node
|
|
14
|
+
def ensure_body: () -> Array[Parser::AST::Node]
|
|
13
15
|
def expression: () -> Parser::AST::Node
|
|
16
|
+
def old_name: () -> Symbol
|
|
17
|
+
def options: () -> Parser::AST::Node
|
|
18
|
+
def operator: () -> Symbol
|
|
14
19
|
def if_statement: () -> Parser::AST::Node
|
|
15
20
|
def in_statements: () -> Array[Parser::AST::Node]
|
|
16
21
|
def key: () -> Parser::AST::Node
|
|
@@ -18,9 +23,11 @@ module ParserNodeExt
|
|
|
18
23
|
def left_value: () -> Parser::AST::Node | Symbol
|
|
19
24
|
def message: () -> Symbol
|
|
20
25
|
def name: () -> Parser::AST::Node | Symbol
|
|
26
|
+
def new_name: () -> Symbol
|
|
21
27
|
def pairs: () -> Array[Parser::AST::Node]
|
|
22
28
|
def parent_class: () -> Parser::AST::Node
|
|
23
29
|
def receiver: () -> Parser::AST::Node
|
|
30
|
+
def rescue_bodies: () -> Array[Parser::AST::Node]
|
|
24
31
|
def right_value: () -> Parser::AST::Node
|
|
25
32
|
def self: () -> Parser::AST::Node
|
|
26
33
|
def value: () -> Parser::AST::Node
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: parser_node_ext
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Richard Huang
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-02-
|
|
11
|
+
date: 2023-02-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: parser
|