parser_node_ext 0.7.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09b9c1f0df70d2a83780b534cb42635c55b0dfb68165b40fa07247f251d6e344'
4
- data.tar.gz: 0ef177a30d4fdacf17d9c36dfcf9e42b4ea7e94142422c9d064dc1cd41a8674d
3
+ metadata.gz: 8fb070ea09b73310d3bb9acdcae0cbc06c6e3120b7d1bd69de94045c48cabcfa
4
+ data.tar.gz: 4014d1088f929cb56e5865b11500f58242263685ba64a140b29d9f9166fdeaf6
5
5
  SHA512:
6
- metadata.gz: 5825839d2153c0d21fc96ba7ee3e6b2c30490966255bb6331cac40224ceb31a426ef86c36cfb3c8ad93d69f14e4a6eb096b582bb731ad69dda0c25467a9acda8
7
- data.tar.gz: b664575b41717991f2fc7c2a562990c876fa2239cb3d982a1ce9dea9d2bb7316bab755a6c1e3b5e380c39a2b5ccc53fe0d62c38fa3c3c019cf5f52cc724ced75
6
+ metadata.gz: 77c947f3bfc188aef814ec8214cf46af0d76d7aabe9c5c99af2c63c7838073bf9c8cd3bdae71e248238cb5c16690d71e91afefc9f23ce791284a46eac7957946
7
+ data.tar.gz: 5afac291cda433af31d1965c023fcc0662cf07e6cdd6c80a9932b23f2851978b501b09fa0a61b128e325bc7eb714d1e5efb09024ac06c802bade0656715e01cf
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.9.0 (2023-02-01)
4
+
5
+ * 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`
6
+
7
+ ## 0.8.0 (2023-01-30)
8
+
9
+ * Support `numblock` node
10
+
3
11
  ## 0.7.0 (2023-01-28)
4
12
 
5
13
  * Support `elements` for `array` node
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parser_node_ext (0.7.0)
4
+ parser_node_ext (0.9.0)
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.7.0"
4
+ VERSION = "0.9.0"
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,26 +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: [],
50
+ numblock: %i[caller arguments_count body],
38
51
  or: %i[left_value right_value],
39
52
  or_asgn: %i[left_value right_value],
40
53
  pair: %i[key value],
54
+ pin: %i[variable],
41
55
  restarg: %i[name],
42
56
  send: %i[receiver message arguments],
43
57
  str: %i[value],
44
58
  super: %i[arguments],
45
59
  sym: %i[value],
46
60
  true: [],
61
+ unless_guard: %i[expression],
47
62
  when: %i[expression body],
48
63
  zsuper: []
49
64
  }
@@ -134,7 +149,7 @@ module ParserNodeExt
134
149
  end
135
150
 
136
151
  # Get body of node.
137
- # It supports :begin, :block, :class, :def, :defs and :module node.
152
+ # It supports :begin, :block, :class, :def, :defs, :module, :numblock node.
138
153
  # @example
139
154
  # 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)))
140
155
  # node.body # [s(:send, nil, :include, s(:const, s(:const, nil, :EmailSpec), :Helpers))]
@@ -148,7 +163,7 @@ module ParserNodeExt
148
163
  return [] if children[1].nil?
149
164
 
150
165
  :begin == children[1].type ? children[1].body : children[1..-1]
151
- when :def, :block, :class, :module
166
+ when :def, :block, :class, :module, :numblock, :in_pattern
152
167
  return [] if children[2].nil?
153
168
 
154
169
  :begin == children[2].type ? children[2].body : children[2..-1]
@@ -172,6 +187,17 @@ module ParserNodeExt
172
187
  end
173
188
  end
174
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
+
175
201
  # Get else statement of case node.
176
202
  # @return [Parser::AST::Node] else statement of case node.
177
203
  # @raise [MethodNotSupported] if calls on other node.
@@ -179,25 +205,25 @@ module ParserNodeExt
179
205
  children[-1]
180
206
  end
181
207
 
182
- # Get elements of array node.
208
+ # Get elements of :array and :array_pattern node.
183
209
  # @return [Array<Parser::AST::Node>] elements of array node.
184
210
  # @raise [MethodNotSupported] if calls on other node.
185
211
  def elements
186
- if :array == type
212
+ if %i[array array_pattern find_pattern].include?(type)
187
213
  children
188
214
  else
189
215
  raise MethodNotSupported, "elements is not supported for #{self}"
190
216
  end
191
217
  end
192
218
 
193
- # Get pairs of :hash node.
219
+ # Get pairs of :hash and :hash_pattern node.
194
220
  # @example
195
221
  # node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)), s(:pair, s(:str, "foo"), s(:str, "bar")))
196
222
  # node.pairs # [s(:pair, s(:sym, :foo), s(:sym, :bar)), s(:pair, s(:str, "foo"), s(:str, "bar"))]
197
223
  # @return [Array<Parser::AST::Node>] pairs of node.
198
224
  # @raise [MethodNotSupported] if calls on other node.
199
225
  def pairs
200
- if :hash == type
226
+ if %i[hash hash_pattern].include?(type)
201
227
  children
202
228
  else
203
229
  raise MethodNotSupported, "pairs is not supported for #{self}"
@@ -3,13 +3,16 @@ 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
8
9
  def elements: () -> Array[Parser::AST::Node]
9
10
  def else_statement: () -> Parser::AST::Node
10
11
  def expression: () -> Parser::AST::Node
11
12
  def if_statement: () -> Parser::AST::Node
13
+ def in_statements: () -> Array[Parser::AST::Node]
12
14
  def key: () -> Parser::AST::Node
15
+ def guard: () -> Parser::AST::Node
13
16
  def left_value: () -> Parser::AST::Node | Symbol
14
17
  def message: () -> Symbol
15
18
  def name: () -> Parser::AST::Node | Symbol
@@ -19,6 +22,7 @@ module ParserNodeExt
19
22
  def right_value: () -> Parser::AST::Node
20
23
  def self: () -> Parser::AST::Node
21
24
  def value: () -> Parser::AST::Node
25
+ def variable: () -> Parser::AST::Node
22
26
  def when_statements: () -> Array[Parser::AST::Node]
23
27
 
24
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.7.0
4
+ version: 0.9.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-27 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