parser_node_ext 1.1.3 → 1.2.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: e485be85a8f56d3b4e733422f69f2d599a7eb9373fd5722e223ee66dec50e83d
4
- data.tar.gz: 575f6097c6efdf2d1eb78b4034f27113a382f232ae26adfd894dd9d899069cd1
3
+ metadata.gz: 50b2c36e35c4dd8b37aa4d82eb72389f550aa9733f15f9f6254dd346b9fd0e2c
4
+ data.tar.gz: 879f64142437e5021fe5c3b4a5421085020ac7117c24c57c229bfd8ece65a757
5
5
  SHA512:
6
- metadata.gz: dde07b7e09dd4c4fa15d951c64108e9c9b89d38b277fd9f2bad7c471cb3944cbecaa73965e9c0fa6287077050a61d99855d463412a96ef6b68d0186e9d6ba443
7
- data.tar.gz: e8f1d5199bb2f1e74128ccda223c569b194d30e6d0f43d55fb9fec98ebb5bdd3a28de3ca760ae5a451157a30b3b81e7005b0f3d905ff563dd9fd573f7826c122
6
+ metadata.gz: 19cc544cc2cd288872940aab7dd8a82a2a4df11d25f8c0760068955ed12ea2cb7c28e6b2bc6b35ef887ad9a451e0ff0bcc88b3c8efcc533c73b55efa6e645194
7
+ data.tar.gz: 75762b11d8e7f6d82ba7c9b788b3ef87297ac656f623b707ba22b21eee48b7394f7030dc4c9a18517b7f4bc7c1b690e6138d11a707552ea99920f5948bfb1118
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.2.0 (2023-06-10)
4
+
5
+ * Separate `kwsplats` from hash `pairs`
6
+
3
7
  ## 1.1.3 (2023-06-08)
4
8
 
5
9
  * `node_type` instead of `type` in `to_hash` output
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parser_node_ext (1.1.3)
4
+ parser_node_ext (1.2.0)
5
5
  parser
6
6
 
7
7
  GEM
@@ -9,8 +9,10 @@ GEM
9
9
  specs:
10
10
  ast (2.4.2)
11
11
  diff-lcs (1.5.0)
12
- parser (3.2.2.1)
12
+ parser (3.2.2.3)
13
13
  ast (~> 2.4.1)
14
+ racc
15
+ racc (1.7.0)
14
16
  rake (13.0.6)
15
17
  rspec (3.11.0)
16
18
  rspec-core (~> 3.11.0)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ParserNodeExt
4
- VERSION = "1.1.3"
4
+ VERSION = "1.2.0"
5
5
  end
@@ -47,8 +47,8 @@ module ParserNodeExt
47
47
  forward_args: [],
48
48
  gvar: %i[name],
49
49
  gvasgn: %i[variable value],
50
- hash: %i[pairs],
51
- hash_pattern: %i[pairs],
50
+ hash: %i[pairs kwsplats],
51
+ hash_pattern: %i[pairs kwsplats],
52
52
  if: %i[expression if_statement else_statement],
53
53
  iflipflop: %i[begin end],
54
54
  if_guard: %i[expression],
@@ -318,7 +318,7 @@ module ParserNodeExt
318
318
  # @raise [MethodNotSupported] if calls on other node.
319
319
  def pairs
320
320
  if %i[hash hash_pattern].include?(type)
321
- children
321
+ children.select { |child| child.type == :pair }
322
322
  else
323
323
  raise MethodNotSupported, "pairs is not supported for #{self}"
324
324
  end
@@ -331,8 +331,8 @@ module ParserNodeExt
331
331
  # @return [Array<Parser::AST::Node>] keys of node.
332
332
  # @raise [MethodNotSupported] if calls on other node.
333
333
  def keys
334
- if :hash == type
335
- children.map { |child| child.children[0] }
334
+ if %i[hash hash_pattern].include?(type)
335
+ pairs.map(&:key)
336
336
  else
337
337
  raise MethodNotSupported, "keys is not supported for #{self}"
338
338
  end
@@ -345,8 +345,8 @@ module ParserNodeExt
345
345
  # @return [Array<Parser::AST::Node>] values of node.
346
346
  # @raise [MethodNotSupported] if calls on other node.
347
347
  def values
348
- if :hash == type
349
- children.map { |child| child.children[1] }
348
+ if %i[hash hash_pattern].include?(type)
349
+ pairs.map(&:value)
350
350
  else
351
351
  raise MethodNotSupported, "keys is not supported for #{self}"
352
352
  end
@@ -360,8 +360,8 @@ module ParserNodeExt
360
360
  # @return [Boolean] true if specified key exists.
361
361
  # @raise [MethodNotSupported] if calls on other node.
362
362
  def key?(key)
363
- if :hash == type
364
- children.any? { |pair_node| pair_node.key.to_value == key }
363
+ if %i[hash hash_pattern].include?(type)
364
+ pairs.any? { |pair_node| pair_node.key.to_value == key }
365
365
  else
366
366
  raise MethodNotSupported, "key? is not supported for #{self}"
367
367
  end
@@ -375,8 +375,8 @@ module ParserNodeExt
375
375
  # @return [Parser::AST::Node] hash pair node.
376
376
  # @raise [MethodNotSupported] if calls on other node.
377
377
  def hash_pair(key)
378
- if :hash == type
379
- children.find { |pair_node| pair_node.key.to_value == key }
378
+ if %i[hash hash_pattern].include?(type)
379
+ pairs.find { |pair_node| pair_node.key.to_value == key }
380
380
  else
381
381
  raise MethodNotSupported, "hash_pair is not supported for #{self}"
382
382
  end
@@ -390,14 +390,28 @@ module ParserNodeExt
390
390
  # @return [Parser::AST::Node] hash value node.
391
391
  # @raise [MethodNotSupported] if calls on other node.
392
392
  def hash_value(key)
393
- if :hash == type
394
- value_node = children.find { |pair_node| pair_node.key.to_value == key }
393
+ if %i[hash hash_pattern].include?(type)
394
+ value_node = pairs.find { |pair_node| pair_node.key.to_value == key }
395
395
  value_node&.value
396
396
  else
397
397
  raise MethodNotSupported, "hash_value is not supported for #{self}"
398
398
  end
399
399
  end
400
400
 
401
+ # Get kwsplats of :hash and :hash_pattern node.
402
+ # @example
403
+ # node s(:hash, s(:pair, s(:int, 1), s(:int, 2)), s(:kwsplat, s(:send, nil, :bar)), s(:pair, s(:sym, :baz), s(:int, 3)))
404
+ # node.pairs # [s(:kwsplat, s(:send, nil, :bar))]
405
+ # @return [Array<Parser::AST::Node>] kwplats of node.
406
+ # @raise [MethodNotSupported] if calls on other node.
407
+ def kwsplats
408
+ if %i[hash hash_pattern].include?(type)
409
+ children.select { |child| child.type == :kwsplat }
410
+ else
411
+ raise MethodNotSupported, "kwsplats is not supported for #{self}"
412
+ end
413
+ end
414
+
401
415
  # Return the exact value of node.
402
416
  # It supports :array, :begin, :erange, :false, :float, :irange, :int, :str, :sym and :true nodes.
403
417
  # @example
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: 1.1.3
4
+ version: 1.2.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-06-08 00:00:00.000000000 Z
11
+ date: 2023-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser