parser_node_ext 0.8.0 → 0.9.1

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
  SHA256:
3
- metadata.gz: 3e35bf56931447c5e56c2c88c387607230701259e1c8cbc56a347901bc7019e3
4
- data.tar.gz: 3c0dd82b73f35f2f4b61ca4d0795293102fe9f18c325f305b21b344d68367a00
3
+ metadata.gz: 04ffc05da49821ecd7354816fb0299c545cc5e290c3d5b895b9fee3f5c87429c
4
+ data.tar.gz: '0240891107821f6340ae989474421a2f55d7c3ac1fcb00df03f9dde2061bb859'
5
5
  SHA512:
6
- metadata.gz: 218616f2d89d224c5cf4f930581f5a3389e076e6cab3674c2551bd432d6928d08cfc429d3cb6ccf62b2f3d51d45927d173403311c8e20cab594f5a5230797fbe
7
- data.tar.gz: ab05bcb20c20dcc05ee88333678bf0b9df529953f80bb6bda4717b70be6c238842909bc52d465f7041df00ab6221276a776e57e5a405851a60dcc4c9914807a8
6
+ metadata.gz: a99e9eb669246a49e8efd5cc31e5035d54a929e9800c178cff63bc5472e3ccb791b69dc1b55d49e87ead173189008d879348e4e7d47d885c922ff7e4b254cb4f
7
+ data.tar.gz: 6d5137cd5e5e85dc20820f948873ebbd1648e2e410070c14c780c2ff8b483a528ed3b151ead451404d7da36046ebb1948cb22e26d99a356b5c2bcf400ab76035
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.9.1 (2023-02-01)
4
+
5
+ * Fix `module` node `body` method
6
+
7
+ ## 0.9.0 (2023-02-01)
8
+
9
+ * Support pattern match nodes, `case_match`, `in_pattern`, `hash_pattern`, `array_pattern`, `find_pattern`, `match_pattern`, `match_pattern_p`, `match_var`, `match_as`, `pin`, `match_rest`, `if_guard` and `unless_guard`
10
+
3
11
  ## 0.8.0 (2023-01-30)
4
12
 
5
13
  * Support `numblock` node
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parser_node_ext (0.8.0)
4
+ parser_node_ext (0.9.1)
5
5
  parser
6
6
 
7
7
  GEM
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ParserNodeExt
4
- VERSION = "0.8.0"
4
+ VERSION = "0.9.1"
5
5
  end
@@ -11,10 +11,13 @@ module ParserNodeExt
11
11
  TYPE_CHILDREN = {
12
12
  and: %i[left_value right_value],
13
13
  arg: %i[name],
14
+ array: %i[elements],
15
+ array_pattern: %i[elements],
14
16
  begin: %i[body],
15
17
  block: %i[caller arguments body],
16
18
  blockarg: %i[name],
17
19
  case: %i[expression when_statements else_statement],
20
+ case_match: %i[expression in_statements else_statement],
18
21
  const: %i[parent_const name],
19
22
  class: %i[name parent_class body],
20
23
  csend: %i[receiver message arguments],
@@ -24,27 +27,38 @@ module ParserNodeExt
24
27
  defined?: %i[arguments],
25
28
  defs: %i[self name arguments body],
26
29
  false: [],
30
+ find_pattern: %i[elements],
27
31
  float: %i[value],
28
32
  hash: %i[pairs],
33
+ hash_pattern: %i[pairs],
29
34
  if: %i[expression if_statement else_statement],
35
+ if_guard: %i[expression],
30
36
  int: %i[value],
37
+ in_pattern: %i[expression guard body],
31
38
  ivasgn: %i[left_value right_value],
32
39
  ivar: %i[name],
33
40
  lvar: %i[name],
34
41
  lvasgn: %i[left_value right_value],
35
42
  masgn: %i[left_value right_value],
43
+ match_as: %i[key value],
44
+ match_pattern: %i[left_value right_value],
45
+ match_pattern_p: %i[left_value right_value],
46
+ match_rest: %i[variable],
47
+ match_var: %i[name],
36
48
  module: %i[name body],
37
49
  nil: [],
38
50
  numblock: %i[caller arguments_count body],
39
51
  or: %i[left_value right_value],
40
52
  or_asgn: %i[left_value right_value],
41
53
  pair: %i[key value],
54
+ pin: %i[variable],
42
55
  restarg: %i[name],
43
56
  send: %i[receiver message arguments],
44
57
  str: %i[value],
45
58
  super: %i[arguments],
46
59
  sym: %i[value],
47
60
  true: [],
61
+ unless_guard: %i[expression],
48
62
  when: %i[expression body],
49
63
  zsuper: []
50
64
  }
@@ -145,11 +159,11 @@ module ParserNodeExt
145
159
  case type
146
160
  when :begin
147
161
  children
148
- when :when
162
+ when :when, :module
149
163
  return [] if children[1].nil?
150
164
 
151
165
  :begin == children[1].type ? children[1].body : children[1..-1]
152
- when :def, :block, :class, :module, :numblock
166
+ when :def, :block, :class, :numblock, :in_pattern
153
167
  return [] if children[2].nil?
154
168
 
155
169
  :begin == children[2].type ? children[2].body : children[2..-1]
@@ -173,6 +187,17 @@ module ParserNodeExt
173
187
  end
174
188
  end
175
189
 
190
+ # Get in statements of case_match node.
191
+ # @return [Array<Parser::AST::Node>] in statements of case node.
192
+ # @raise [MethodNotSupported] if calls on other node.
193
+ def in_statements
194
+ if :case_match == type
195
+ children[1...-1]
196
+ else
197
+ raise MethodNotSupported, "in_statements is not supported for #{self}"
198
+ end
199
+ end
200
+
176
201
  # Get else statement of case node.
177
202
  # @return [Parser::AST::Node] else statement of case node.
178
203
  # @raise [MethodNotSupported] if calls on other node.
@@ -180,25 +205,25 @@ module ParserNodeExt
180
205
  children[-1]
181
206
  end
182
207
 
183
- # Get elements of array node.
208
+ # Get elements of :array and :array_pattern node.
184
209
  # @return [Array<Parser::AST::Node>] elements of array node.
185
210
  # @raise [MethodNotSupported] if calls on other node.
186
211
  def elements
187
- if :array == type
212
+ if %i[array array_pattern find_pattern].include?(type)
188
213
  children
189
214
  else
190
215
  raise MethodNotSupported, "elements is not supported for #{self}"
191
216
  end
192
217
  end
193
218
 
194
- # Get pairs of :hash node.
219
+ # Get pairs of :hash and :hash_pattern node.
195
220
  # @example
196
221
  # node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)), s(:pair, s(:str, "foo"), s(:str, "bar")))
197
222
  # node.pairs # [s(:pair, s(:sym, :foo), s(:sym, :bar)), s(:pair, s(:str, "foo"), s(:str, "bar"))]
198
223
  # @return [Array<Parser::AST::Node>] pairs of node.
199
224
  # @raise [MethodNotSupported] if calls on other node.
200
225
  def pairs
201
- if :hash == type
226
+ if %i[hash hash_pattern].include?(type)
202
227
  children
203
228
  else
204
229
  raise MethodNotSupported, "pairs is not supported for #{self}"
@@ -10,7 +10,9 @@ module ParserNodeExt
10
10
  def else_statement: () -> Parser::AST::Node
11
11
  def expression: () -> Parser::AST::Node
12
12
  def if_statement: () -> Parser::AST::Node
13
+ def in_statements: () -> Array[Parser::AST::Node]
13
14
  def key: () -> Parser::AST::Node
15
+ def guard: () -> Parser::AST::Node
14
16
  def left_value: () -> Parser::AST::Node | Symbol
15
17
  def message: () -> Symbol
16
18
  def name: () -> Parser::AST::Node | Symbol
@@ -20,6 +22,7 @@ module ParserNodeExt
20
22
  def right_value: () -> Parser::AST::Node
21
23
  def self: () -> Parser::AST::Node
22
24
  def value: () -> Parser::AST::Node
25
+ def variable: () -> Parser::AST::Node
23
26
  def when_statements: () -> Array[Parser::AST::Node]
24
27
 
25
28
  def to_hash: () -> Hash
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.8.0
4
+ version: 0.9.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: 2023-01-30 00:00:00.000000000 Z
11
+ date: 2023-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser