parser_node_ext 1.1.3 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +4 -2
- data/lib/parser_node_ext/version.rb +1 -1
- data/lib/parser_node_ext.rb +27 -17
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90dfc73d7d6113dbf3e6c7f61de5435d537604f6dcb3c6158a59ceb87e766c50
|
4
|
+
data.tar.gz: 7f7f1376041a28248fec6b81f5d9e95d64cf408d3be8aaf4556e235dc9e2bf23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 731d405cc89bb44efe36d6035e8fb0008a23e9043b83d950fe51010032a129d00850b6bcbc22c01f6d02df8fab9c95d8fa88db7cc13dee45f2dc817d49f277bc
|
7
|
+
data.tar.gz: 59d138be84e10ceca0dc7cb6047cfa56e0df7dbe717889536a18473a61309b554cddff8e8607ef2b188e9f4276e864c6a0ae7892bf960cc0c5ac53560ccc3bd0
|
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.1
|
4
|
+
parser_node_ext (1.2.1)
|
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.1)
|
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
|
@@ -417,10 +431,6 @@ module ParserNodeExt
|
|
417
431
|
nil
|
418
432
|
when :array
|
419
433
|
children.map(&:to_value)
|
420
|
-
when :irange
|
421
|
-
(children.first.to_value..children.last.to_value)
|
422
|
-
when :erange
|
423
|
-
(children.first.to_value...children.last.to_value)
|
424
434
|
when :begin, :kwbegin
|
425
435
|
children.first.to_value
|
426
436
|
else
|
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
|
4
|
+
version: 1.2.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-
|
11
|
+
date: 2023-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: '0'
|
64
64
|
requirements: []
|
65
|
-
rubygems_version: 3.4.
|
65
|
+
rubygems_version: 3.4.18
|
66
66
|
signing_key:
|
67
67
|
specification_version: 4
|
68
68
|
summary: extend parser node
|