parser_node_ext 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/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/parser_node_ext/version.rb +1 -1
- data/lib/parser_node_ext.rb +31 -18
- 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: 54f47aa3cbd58cec27d151340e935bf687be7c9cb63c523cdd8174869aebaf7e
|
4
|
+
data.tar.gz: e3e940453872b9bd0abd24a2b11b8d07c59e35613717b365b9810b0461cd1f28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 573b0ae05b18d25c04bc1efeac3f763c3872eee302d1b23fa11c054d32a1ea84afc86e7984e3ae6892f55bc39c4b0c8faadf133da1d53af6b387b8a57f55f685
|
7
|
+
data.tar.gz: b8b718a0dec190ce6b563fa9edd842d38869a58f7bc43799297e6ed88268f2fd5427315791c5b4cec62046d510056165b60683d36709d86790675eb19b14b655
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/parser_node_ext.rb
CHANGED
@@ -93,7 +93,7 @@ module ParserNodeExt
|
|
93
93
|
index = TYPE_CHILDREN[type]&.index(method_name)
|
94
94
|
return children[index] if index
|
95
95
|
|
96
|
-
raise
|
96
|
+
raise MethodNotSupported, "#{method_name} is not handled for #{debug_info}"
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
@@ -103,14 +103,14 @@ module ParserNodeExt
|
|
103
103
|
# node # s(:or_asgn, s(:lvasgn, :a), s(:int, 1))
|
104
104
|
# node.left_value # :a
|
105
105
|
# @return [Parser::AST::Node] left value of node.
|
106
|
-
# @raise [
|
106
|
+
# @raise [MethodNotSupported] if calls on other node.
|
107
107
|
def left_value
|
108
108
|
return children[0].children[0] if type == :or_asgn
|
109
109
|
|
110
110
|
index = TYPE_CHILDREN[type]&.index(:left_value)
|
111
111
|
return children[index] if index
|
112
112
|
|
113
|
-
raise
|
113
|
+
raise MethodNotSupported, "#{left_value} is not handled for #{debug_info}"
|
114
114
|
end
|
115
115
|
|
116
116
|
# Get arguments of node.
|
@@ -119,7 +119,7 @@ module ParserNodeExt
|
|
119
119
|
# node # s(:send, s(:const, nil, :FactoryGirl), :create, s(:sym, :post), s(:hash, s(:pair, s(:sym, :title), s(:str, "post"))))
|
120
120
|
# node.arguments # [s(:sym, :post), s(:hash, s(:pair, s(:sym, :title), s(:str, "post")))]
|
121
121
|
# @return [Array<Parser::AST::Node>] arguments of node.
|
122
|
-
# @raise [
|
122
|
+
# @raise [MethodNotSupported] if calls on other node.
|
123
123
|
def arguments
|
124
124
|
case type
|
125
125
|
when :def, :block
|
@@ -131,7 +131,7 @@ module ParserNodeExt
|
|
131
131
|
when :defined?
|
132
132
|
children
|
133
133
|
else
|
134
|
-
raise
|
134
|
+
raise MethodNotSupported, "arguments is not handled for #{debug_info}"
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
@@ -141,7 +141,7 @@ module ParserNodeExt
|
|
141
141
|
# 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)))
|
142
142
|
# node.body # [s(:send, nil, :include, s(:const, s(:const, nil, :EmailSpec), :Helpers))]
|
143
143
|
# @return [Array<Parser::AST::Node>] body of node.
|
144
|
-
# @raise [
|
144
|
+
# @raise [MethodNotSupported] if calls on other node.
|
145
145
|
def body
|
146
146
|
case type
|
147
147
|
when :begin
|
@@ -155,7 +155,7 @@ module ParserNodeExt
|
|
155
155
|
|
156
156
|
:begin == children[3].type ? children[3].body : children[3..-1]
|
157
157
|
else
|
158
|
-
raise
|
158
|
+
raise MethodNotSupported, "body is not handled for #{debug_info}"
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
@@ -165,12 +165,12 @@ module ParserNodeExt
|
|
165
165
|
# node # s(:if, s(:defined?, s(:const, nil, :Bundler)), nil, nil)
|
166
166
|
# node.condition # s(:defined?, s(:const, nil, :Bundler))
|
167
167
|
# @return [Parser::AST::Node] condition of node.
|
168
|
-
# @raise [
|
168
|
+
# @raise [MethodNotSupported] if calls on other node.
|
169
169
|
def condition
|
170
170
|
if :if == type
|
171
171
|
children[0]
|
172
172
|
else
|
173
|
-
raise
|
173
|
+
raise MethodNotSupported, "condition is not handled for #{debug_info}"
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
@@ -179,12 +179,12 @@ module ParserNodeExt
|
|
179
179
|
# node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)), s(:pair, s(:str, "foo"), s(:str, "bar")))
|
180
180
|
# node.keys # [s(:sym, :foo), s(:str, "foo")]
|
181
181
|
# @return [Array<Parser::AST::Node>] keys of node.
|
182
|
-
# @raise [
|
182
|
+
# @raise [MethodNotSupported] if calls on other node.
|
183
183
|
def keys
|
184
184
|
if :hash == type
|
185
185
|
children.map { |child| child.children[0] }
|
186
186
|
else
|
187
|
-
raise
|
187
|
+
raise MethodNotSupported, "keys is not handled for #{debug_info}"
|
188
188
|
end
|
189
189
|
end
|
190
190
|
|
@@ -193,12 +193,12 @@ module ParserNodeExt
|
|
193
193
|
# node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)), s(:pair, s(:str, "foo"), s(:str, "bar")))
|
194
194
|
# node.values # [s(:sym, :bar), s(:str, "bar")]
|
195
195
|
# @return [Array<Parser::AST::Node>] values of node.
|
196
|
-
# @raise [
|
196
|
+
# @raise [MethodNotSupported] if calls on other node.
|
197
197
|
def values
|
198
198
|
if :hash == type
|
199
199
|
children.map { |child| child.children[1] }
|
200
200
|
else
|
201
|
-
raise
|
201
|
+
raise MethodNotSupported, "keys is not handled for #{debug_info}"
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
@@ -208,12 +208,12 @@ module ParserNodeExt
|
|
208
208
|
# node.key?(:foo) # true
|
209
209
|
# @param [Symbol, String] key value.
|
210
210
|
# @return [Boolean] true if specified key exists.
|
211
|
-
# @raise [
|
211
|
+
# @raise [MethodNotSupported] if calls on other node.
|
212
212
|
def key?(key)
|
213
213
|
if :hash == type
|
214
214
|
children.any? { |pair_node| pair_node.key.to_value == key }
|
215
215
|
else
|
216
|
-
raise
|
216
|
+
raise MethodNotSupported, "key? is not handled for #{debug_info}"
|
217
217
|
end
|
218
218
|
end
|
219
219
|
|
@@ -223,13 +223,13 @@ module ParserNodeExt
|
|
223
223
|
# node.hash_value(:foo) # s(:sym, :bar)
|
224
224
|
# @param [Symbol, String] key value.
|
225
225
|
# @return [Parser::AST::Node] hash value of node.
|
226
|
-
# @raise [
|
226
|
+
# @raise [MethodNotSupported] if calls on other node.
|
227
227
|
def hash_value(key)
|
228
228
|
if :hash == type
|
229
229
|
value_node = children.find { |pair_node| pair_node.key.to_value == key }
|
230
230
|
value_node&.value
|
231
231
|
else
|
232
|
-
raise
|
232
|
+
raise MethodNotSupported, "hash_value is not handled for #{debug_info}"
|
233
233
|
end
|
234
234
|
end
|
235
235
|
|
@@ -239,7 +239,7 @@ module ParserNodeExt
|
|
239
239
|
# node # s(:array, s(:str, "str"), s(:sym, :str))
|
240
240
|
# node.to_value # ['str', :str]
|
241
241
|
# @return [Object] exact value.
|
242
|
-
# @raise [
|
242
|
+
# @raise [MethodNotSupported] if calls on other node.
|
243
243
|
def to_value
|
244
244
|
case type
|
245
245
|
when :int, :float, :str, :sym
|
@@ -330,6 +330,19 @@ module ParserNodeExt
|
|
330
330
|
|
331
331
|
super
|
332
332
|
end
|
333
|
+
|
334
|
+
# Return the debug info.
|
335
|
+
#
|
336
|
+
# @return [String] file, line, source and node.
|
337
|
+
def debug_info
|
338
|
+
"\n" +
|
339
|
+
[
|
340
|
+
"file: #{loc.expression.source_buffer.name}",
|
341
|
+
"line: #{loc.expression.line}",
|
342
|
+
"source: #{to_source}",
|
343
|
+
"node: #{inspect}"
|
344
|
+
].join("\n")
|
345
|
+
end
|
333
346
|
end
|
334
347
|
end
|
335
348
|
end
|
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: 0.4.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: 2022-07-
|
11
|
+
date: 2022-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|