parser_node_ext 0.6.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +1 -1
- data/lib/parser_node_ext/version.rb +1 -1
- data/lib/parser_node_ext.rb +24 -4
- data/sig/parser_node_ext.rbs +2 -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: 3e35bf56931447c5e56c2c88c387607230701259e1c8cbc56a347901bc7019e3
|
4
|
+
data.tar.gz: 3c0dd82b73f35f2f4b61ca4d0795293102fe9f18c325f305b21b344d68367a00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 218616f2d89d224c5cf4f930581f5a3389e076e6cab3674c2551bd432d6928d08cfc429d3cb6ccf62b2f3d51d45927d173403311c8e20cab594f5a5230797fbe
|
7
|
+
data.tar.gz: ab05bcb20c20dcc05ee88333678bf0b9df529953f80bb6bda4717b70be6c238842909bc52d465f7041df00ab6221276a776e57e5a405851a60dcc4c9914807a8
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/parser_node_ext.rb
CHANGED
@@ -35,6 +35,7 @@ module ParserNodeExt
|
|
35
35
|
masgn: %i[left_value right_value],
|
36
36
|
module: %i[name body],
|
37
37
|
nil: [],
|
38
|
+
numblock: %i[caller arguments_count body],
|
38
39
|
or: %i[left_value right_value],
|
39
40
|
or_asgn: %i[left_value right_value],
|
40
41
|
pair: %i[key value],
|
@@ -119,9 +120,11 @@ module ParserNodeExt
|
|
119
120
|
def arguments
|
120
121
|
case type
|
121
122
|
when :def, :block
|
122
|
-
children[1].children
|
123
|
+
children[1].type == :args ? children[1].children : [children[1]]
|
123
124
|
when :defs
|
124
|
-
children[2].children
|
125
|
+
children[2].type == :args ? children[2].children : [children[2]]
|
126
|
+
when :block
|
127
|
+
children[1].children
|
125
128
|
when :send, :csend
|
126
129
|
children[2..-1]
|
127
130
|
when :defined?
|
@@ -132,7 +135,7 @@ module ParserNodeExt
|
|
132
135
|
end
|
133
136
|
|
134
137
|
# Get body of node.
|
135
|
-
# It supports :begin, :block, :class, :def, :defs
|
138
|
+
# It supports :begin, :block, :class, :def, :defs, :module, :numblock node.
|
136
139
|
# @example
|
137
140
|
# 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)))
|
138
141
|
# node.body # [s(:send, nil, :include, s(:const, s(:const, nil, :EmailSpec), :Helpers))]
|
@@ -146,7 +149,7 @@ module ParserNodeExt
|
|
146
149
|
return [] if children[1].nil?
|
147
150
|
|
148
151
|
:begin == children[1].type ? children[1].body : children[1..-1]
|
149
|
-
when :def, :block, :class, :module
|
152
|
+
when :def, :block, :class, :module, :numblock
|
150
153
|
return [] if children[2].nil?
|
151
154
|
|
152
155
|
:begin == children[2].type ? children[2].body : children[2..-1]
|
@@ -159,6 +162,9 @@ module ParserNodeExt
|
|
159
162
|
end
|
160
163
|
end
|
161
164
|
|
165
|
+
# Get when statements of case node.
|
166
|
+
# @return [Array<Parser::AST::Node>] when statements of case node.
|
167
|
+
# @raise [MethodNotSupported] if calls on other node.
|
162
168
|
def when_statements
|
163
169
|
if :case == type
|
164
170
|
children[1...-1]
|
@@ -167,10 +173,24 @@ module ParserNodeExt
|
|
167
173
|
end
|
168
174
|
end
|
169
175
|
|
176
|
+
# Get else statement of case node.
|
177
|
+
# @return [Parser::AST::Node] else statement of case node.
|
178
|
+
# @raise [MethodNotSupported] if calls on other node.
|
170
179
|
def else_statement
|
171
180
|
children[-1]
|
172
181
|
end
|
173
182
|
|
183
|
+
# Get elements of array node.
|
184
|
+
# @return [Array<Parser::AST::Node>] elements of array node.
|
185
|
+
# @raise [MethodNotSupported] if calls on other node.
|
186
|
+
def elements
|
187
|
+
if :array == type
|
188
|
+
children
|
189
|
+
else
|
190
|
+
raise MethodNotSupported, "elements is not supported for #{self}"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
174
194
|
# Get pairs of :hash node.
|
175
195
|
# @example
|
176
196
|
# node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)), s(:pair, s(:str, "foo"), s(:str, "bar")))
|
data/sig/parser_node_ext.rbs
CHANGED
@@ -3,8 +3,10 @@ module ParserNodeExt
|
|
3
3
|
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
|
4
4
|
|
5
5
|
def arguments: () -> Array[Parser::AST::Node]
|
6
|
+
def arguments_count: () -> Integer
|
6
7
|
def body: () -> Array[Parser::AST::Node]
|
7
8
|
def caller: () -> Parser::AST::Node
|
9
|
+
def elements: () -> Array[Parser::AST::Node]
|
8
10
|
def else_statement: () -> Parser::AST::Node
|
9
11
|
def expression: () -> Parser::AST::Node
|
10
12
|
def if_statement: () -> 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: 0.8.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-01-
|
11
|
+
date: 2023-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|