parser_node_ext 0.3.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +2 -2
- data/lib/parser_node_ext/version.rb +1 -1
- data/lib/parser_node_ext.rb +18 -18
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07a901b2c76fb4f39403891f6191fcb865beeb0847108522765cde0fe06bc6cd
|
4
|
+
data.tar.gz: c4720a3f2df5c08ef3a6f3ef2f18c33a5cf02aac1ef94c351d5ac37eaa9f1af1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f10a88ff6c89658b50e6b2d36f433a88595816f0c36dabdf18f16c29c2096bbb5de80045791f436ac77d9d781baf5ed9e5205a5928fade062add8efc0c9a2fe1
|
7
|
+
data.tar.gz: 88bb4871e94a2d1c3924f3787108242d7c1ac7048c3820a751365bc0c4af7f02784262dc8c07bd3e26ed8a9cd95a1b2c095c046dfb4c48f262fb3ab226394c0a
|
data/CHANGELOG.md
CHANGED
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 (0.4.1)
|
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.1.2.
|
12
|
+
parser (3.1.2.1)
|
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
@@ -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 supported for #{self}"
|
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 supported for #{self}"
|
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 supported for #{self}"
|
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 supported for #{self}"
|
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 supported for #{self}"
|
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 supported for #{self}"
|
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 supported for #{self}"
|
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 supported for #{self}"
|
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 supported for #{self}"
|
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
|
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.1
|
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-
|
11
|
+
date: 2022-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
63
|
- !ruby/object:Gem::Version
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
|
-
rubygems_version: 3.3.
|
66
|
+
rubygems_version: 3.3.22
|
67
67
|
signing_key:
|
68
68
|
specification_version: 4
|
69
69
|
summary: extend parser node
|