parser_node_ext 0.8.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: 3e35bf56931447c5e56c2c88c387607230701259e1c8cbc56a347901bc7019e3
4
- data.tar.gz: 3c0dd82b73f35f2f4b61ca4d0795293102fe9f18c325f305b21b344d68367a00
3
+ metadata.gz: 8fb070ea09b73310d3bb9acdcae0cbc06c6e3120b7d1bd69de94045c48cabcfa
4
+ data.tar.gz: 4014d1088f929cb56e5865b11500f58242263685ba64a140b29d9f9166fdeaf6
5
5
  SHA512:
6
- metadata.gz: 218616f2d89d224c5cf4f930581f5a3389e076e6cab3674c2551bd432d6928d08cfc429d3cb6ccf62b2f3d51d45927d173403311c8e20cab594f5a5230797fbe
7
- data.tar.gz: ab05bcb20c20dcc05ee88333678bf0b9df529953f80bb6bda4717b70be6c238842909bc52d465f7041df00ab6221276a776e57e5a405851a60dcc4c9914807a8
6
+ metadata.gz: 77c947f3bfc188aef814ec8214cf46af0d76d7aabe9c5c99af2c63c7838073bf9c8cd3bdae71e248238cb5c16690d71e91afefc9f23ce791284a46eac7957946
7
+ data.tar.gz: 5afac291cda433af31d1965c023fcc0662cf07e6cdd6c80a9932b23f2851978b501b09fa0a61b128e325bc7eb714d1e5efb09024ac06c802bade0656715e01cf
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
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
+
3
7
  ## 0.8.0 (2023-01-30)
4
8
 
5
9
  * 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.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.8.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,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
  }
@@ -149,7 +163,7 @@ module ParserNodeExt
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, :module, :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.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-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