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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +4 -2
- data/lib/parser_node_ext/version.rb +1 -1
- data/lib/parser_node_ext.rb +27 -13
- 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: 50b2c36e35c4dd8b37aa4d82eb72389f550aa9733f15f9f6254dd346b9fd0e2c
|
4
|
+
data.tar.gz: 879f64142437e5021fe5c3b4a5421085020ac7117c24c57c229bfd8ece65a757
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19cc544cc2cd288872940aab7dd8a82a2a4df11d25f8c0760068955ed12ea2cb7c28e6b2bc6b35ef887ad9a451e0ff0bcc88b3c8efcc533c73b55efa6e645194
|
7
|
+
data.tar.gz: 75762b11d8e7f6d82ba7c9b788b3ef87297ac656f623b707ba22b21eee48b7394f7030dc4c9a18517b7f4bc7c1b690e6138d11a707552ea99920f5948bfb1118
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
parser_node_ext (1.
|
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.
|
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)
|
data/lib/parser_node_ext.rb
CHANGED
@@ -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
|
335
|
-
|
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
|
349
|
-
|
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
|
364
|
-
|
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
|
379
|
-
|
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
|
394
|
-
value_node =
|
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.
|
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-
|
11
|
+
date: 2023-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|