parser_node_ext 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +3 -3
- data/lib/parser_node_ext/version.rb +1 -1
- data/lib/parser_node_ext.rb +7 -46
- 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: 22a93ba0be1ba11d2ad229213f3d23cdced0a9ddcd7c0bfc7ca5554477309f1a
|
4
|
+
data.tar.gz: f7ee7d6199fbf215e4edc131f05bf6f8029e830a4aba46f41d9003fd4dd34639
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ed6775dcbf7b3da276c8bbaf7d10be7da230d3ad46ea92aa9f25f7b150f4b73fb4b2fe8db0c53f6354db6ff6cb58494817907074dec159152cf54fcbb9a5e17
|
7
|
+
data.tar.gz: 625449de48bc393ae3eec749d6a1c3753161deb2224742962b588e6ae128f50f1f0b68619f95e356c89c9f0ac647a68e083eea0334d8bba6e5ac6be2bbbc5c4e
|
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.4.0)
|
5
5
|
parser
|
6
6
|
|
7
7
|
GEM
|
@@ -9,10 +9,10 @@ GEM
|
|
9
9
|
specs:
|
10
10
|
ast (2.4.2)
|
11
11
|
diff-lcs (1.5.0)
|
12
|
-
parser (3.3.0
|
12
|
+
parser (3.3.4.0)
|
13
13
|
ast (~> 2.4.1)
|
14
14
|
racc
|
15
|
-
racc (1.
|
15
|
+
racc (1.8.0)
|
16
16
|
rake (13.0.6)
|
17
17
|
rspec (3.11.0)
|
18
18
|
rspec-core (~> 3.11.0)
|
data/lib/parser_node_ext.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative "parser_node_ext/version"
|
4
4
|
|
5
5
|
require 'parser'
|
6
|
+
require_relative "parser_node_ext/parent_node_ext"
|
6
7
|
|
7
8
|
module ParserNodeExt
|
8
9
|
class MethodNotSupported < StandardError; end
|
@@ -319,37 +320,6 @@ module ParserNodeExt
|
|
319
320
|
end
|
320
321
|
end
|
321
322
|
|
322
|
-
# Get :hash pair node according to specified key.
|
323
|
-
# @example
|
324
|
-
# node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)))
|
325
|
-
# node.hash_pair(:foo) # s(:pair, s(:sym, :foo), s(:sym, :bar))
|
326
|
-
# @param [Symbol, String] key value.
|
327
|
-
# @return [Parser::AST::Node] hash pair node.
|
328
|
-
# @raise [MethodNotSupported] if calls on other node.
|
329
|
-
def hash_pair(key)
|
330
|
-
if %i[hash hash_pattern].include?(type)
|
331
|
-
pairs.find { |pair_node| pair_node.key.to_value == key }
|
332
|
-
else
|
333
|
-
raise MethodNotSupported, "hash_pair is not supported for #{self}"
|
334
|
-
end
|
335
|
-
end
|
336
|
-
|
337
|
-
# Get :hash value node according to specified key.
|
338
|
-
# @example
|
339
|
-
# node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)))
|
340
|
-
# node.hash_value(:foo) # s(:sym, :bar)
|
341
|
-
# @param [Symbol, String] key value.
|
342
|
-
# @return [Parser::AST::Node] hash value node.
|
343
|
-
# @raise [MethodNotSupported] if calls on other node.
|
344
|
-
def hash_value(key)
|
345
|
-
if %i[hash hash_pattern].include?(type)
|
346
|
-
value_node = pairs.find { |pair_node| pair_node.key.to_value == key }
|
347
|
-
value_node&.value
|
348
|
-
else
|
349
|
-
raise MethodNotSupported, "hash_value is not supported for #{self}"
|
350
|
-
end
|
351
|
-
end
|
352
|
-
|
353
323
|
# Get kwsplats of :hash and :hash_pattern node.
|
354
324
|
# @example
|
355
325
|
# 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)))
|
@@ -407,22 +377,13 @@ module ParserNodeExt
|
|
407
377
|
return children.send(method_name, *args, &block)
|
408
378
|
elsif :hash == type && method_name.to_s.end_with?('_pair')
|
409
379
|
key = method_name.to_s[0..-6]
|
410
|
-
return
|
411
|
-
return hash_pair(key.to_s) if keys.map(&:to_value).include?(key.to_s)
|
412
|
-
|
413
|
-
return nil
|
380
|
+
return pairs.find { |pair| pair.key.to_value.to_s == key }
|
414
381
|
elsif :hash == type && method_name.to_s.end_with?('_value')
|
415
382
|
key = method_name.to_s[0..-7]
|
416
|
-
return
|
417
|
-
return hash_value(key.to_s) if keys.map(&:to_value).include?(key.to_s)
|
418
|
-
|
419
|
-
return nil
|
383
|
+
return pairs.find { |pair| pair.key.to_value.to_s == key }&.value
|
420
384
|
elsif :hash == type && method_name.to_s.end_with?('_source')
|
421
385
|
key = method_name.to_s[0..-8]
|
422
|
-
return
|
423
|
-
return hash_value(key.to_s)&.to_source if keys.map(&:to_value).include?(key.to_s)
|
424
|
-
|
425
|
-
return ''
|
386
|
+
return pairs.find { |pair| pair.key.to_value.to_s == key }&.value&.to_source || ''
|
426
387
|
end
|
427
388
|
|
428
389
|
super
|
@@ -433,13 +394,13 @@ module ParserNodeExt
|
|
433
394
|
return true
|
434
395
|
elsif :hash == type && method_name.to_s.end_with?('_pair')
|
435
396
|
key = method_name.to_s[0..-6]
|
436
|
-
return
|
397
|
+
return !!pairs.find { |pair| pair.key.to_value.to_s == key }
|
437
398
|
elsif :hash == type && method_name.to_s.end_with?('_value')
|
438
399
|
key = method_name.to_s[0..-7]
|
439
|
-
return
|
400
|
+
return !!pairs.find { |pair| pair.key.to_value.to_s == key }
|
440
401
|
elsif :hash == type && method_name.to_s.end_with?('_source')
|
441
402
|
key = method_name.to_s[0..-8]
|
442
|
-
return
|
403
|
+
return !!pairs.find { |pair| pair.key.to_value.to_s == key }
|
443
404
|
end
|
444
405
|
|
445
406
|
super
|
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.4.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: 2024-
|
11
|
+
date: 2024-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
63
|
- !ruby/object:Gem::Version
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
|
-
rubygems_version: 3.5.
|
66
|
+
rubygems_version: 3.5.14
|
67
67
|
signing_key:
|
68
68
|
specification_version: 4
|
69
69
|
summary: extend parser node
|