node_query 1.14.1 → 1.15.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 +10 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +11 -7
- data/README.md +1 -1
- data/lib/node_query/adapter/prism.rb +51 -0
- data/lib/node_query/adapter/syntax_tree.rb +10 -10
- data/lib/node_query/compiler/selector.rb +3 -3
- data/lib/node_query/version.rb +1 -1
- data/lib/node_query.rb +3 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b7a968afbfc580614cb1647fd59933e29ca42a51f16bd94d83bfdd2ff6d76f3
|
4
|
+
data.tar.gz: a58361e9a486604fd35e5645528ddb3ad1bf49f314ed704e57954678dfac9d78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2468e0e6e5fc5b2fe8d9f93e9169394552991a6813af79428d14d6740b206a4f8e4b1eb37c8b7bbea826daf96157bd571d57ac0afdb302b0271ea2be8ffe088c
|
7
|
+
data.tar.gz: feecda8504d3b2477a3152b2993cd8b18a301d9f2e07f09e523b2a4cbed8791369ddffcf3c727dd5b059b34cf52aeec83b507451d14c9f4129aef177552022aa
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 1.15.1 (2024-02-16)
|
4
|
+
|
5
|
+
* Use `deconstruct_keys` to get prism children
|
6
|
+
* Get `PrismAdapter`
|
7
|
+
* Read prism node type
|
8
|
+
|
9
|
+
## 1.15.0 (2024-02-10)
|
10
|
+
|
11
|
+
* Support `prism`
|
12
|
+
|
3
13
|
## 1.14.1 (2023-11-27)
|
4
14
|
|
5
15
|
* Fix `ArrayValue` with `adapter` parameter
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
node_query (1.
|
4
|
+
node_query (1.15.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -38,16 +38,19 @@ GEM
|
|
38
38
|
nenv (~> 0.1)
|
39
39
|
shellany (~> 0.0)
|
40
40
|
oedipus_lex (2.6.0)
|
41
|
-
parser (3.
|
41
|
+
parser (3.3.0.5)
|
42
42
|
ast (~> 2.4.1)
|
43
43
|
racc
|
44
|
-
parser_node_ext (1.2.
|
44
|
+
parser_node_ext (1.2.2)
|
45
45
|
parser
|
46
46
|
prettier_print (1.2.1)
|
47
|
+
prism (0.22.0)
|
48
|
+
prism_ext (0.2.0)
|
49
|
+
prism
|
47
50
|
pry (0.14.1)
|
48
51
|
coderay (~> 1.1)
|
49
52
|
method_source (~> 1.0)
|
50
|
-
racc (1.
|
53
|
+
racc (1.7.3)
|
51
54
|
rake (13.0.6)
|
52
55
|
rb-fsevent (0.11.1)
|
53
56
|
rb-inotify (0.10.1)
|
@@ -66,15 +69,16 @@ GEM
|
|
66
69
|
rspec-support (~> 3.11.0)
|
67
70
|
rspec-support (3.11.0)
|
68
71
|
shellany (0.0.1)
|
69
|
-
syntax_tree (6.
|
72
|
+
syntax_tree (6.2.0)
|
70
73
|
prettier_print (>= 1.2.0)
|
71
|
-
syntax_tree_ext (0.
|
74
|
+
syntax_tree_ext (0.7.0)
|
72
75
|
syntax_tree
|
73
76
|
thor (1.2.1)
|
74
77
|
|
75
78
|
PLATFORMS
|
76
79
|
x86_64-darwin-21
|
77
80
|
x86_64-darwin-22
|
81
|
+
x86_64-darwin-23
|
78
82
|
x86_64-linux
|
79
83
|
|
80
84
|
DEPENDENCIES
|
@@ -83,8 +87,8 @@ DEPENDENCIES
|
|
83
87
|
guard-rspec
|
84
88
|
node_query!
|
85
89
|
oedipus_lex
|
86
|
-
parser
|
87
90
|
parser_node_ext
|
91
|
+
prism_ext
|
88
92
|
racc
|
89
93
|
rake (~> 13.0)
|
90
94
|
rspec (~> 3.0)
|
data/README.md
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'prism'
|
4
|
+
require 'prism_ext'
|
5
|
+
|
6
|
+
class NodeQuery::PrismAdapter
|
7
|
+
def is_node?(node)
|
8
|
+
node.is_a?(Prism::Node)
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_node_type(node)
|
12
|
+
node.type
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_source(node)
|
16
|
+
node.slice
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_children(node)
|
20
|
+
keys = []
|
21
|
+
children = []
|
22
|
+
node.deconstruct_keys([]).each do |key, value|
|
23
|
+
next if [:flags, :location].include?(key)
|
24
|
+
|
25
|
+
if key.to_s.end_with?('_loc')
|
26
|
+
new_key = key.to_s[0..-5]
|
27
|
+
unless keys.include?(new_key)
|
28
|
+
keys << new_key
|
29
|
+
children << node.send(new_key)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
unless keys.include?(key.to_s)
|
33
|
+
keys << key.to_s
|
34
|
+
children << value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
children
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_siblings(node)
|
42
|
+
child_nodes = get_children(node.parent_node)
|
43
|
+
if child_nodes.is_a?(Array) && child_nodes.size == 1 && child_nodes.first.is_a?(Array)
|
44
|
+
index = child_nodes.first.index(node)
|
45
|
+
return child_nodes.first[index + 1...]
|
46
|
+
end
|
47
|
+
|
48
|
+
index = child_nodes.index(node)
|
49
|
+
child_nodes[index + 1...]
|
50
|
+
end
|
51
|
+
end
|
@@ -3,14 +3,6 @@
|
|
3
3
|
require 'syntax_tree'
|
4
4
|
require 'syntax_tree_ext'
|
5
5
|
|
6
|
-
if RUBY_VERSION.to_i < 3
|
7
|
-
class Hash
|
8
|
-
def except(*keys)
|
9
|
-
self.reject { |k, _| keys.include?(k) }
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
6
|
class NodeQuery::SyntaxTreeAdapter
|
15
7
|
def is_node?(node)
|
16
8
|
node.is_a?(SyntaxTree::Node)
|
@@ -25,10 +17,18 @@ class NodeQuery::SyntaxTreeAdapter
|
|
25
17
|
end
|
26
18
|
|
27
19
|
def get_children(node)
|
28
|
-
node.deconstruct_keys([]).
|
20
|
+
node.deconstruct_keys([]).filter { |key, _value| ![:location, :comments].include?(key) }
|
21
|
+
.values
|
29
22
|
end
|
30
23
|
|
31
24
|
def get_siblings(node)
|
32
|
-
node.
|
25
|
+
child_nodes = node.parent_node.deconstruct_keys([]).except(:location, :comments).values
|
26
|
+
if child_nodes.is_a?(Array) && child_nodes.size == 1 && child_nodes.first.is_a?(Array)
|
27
|
+
index = child_nodes.first.index(node)
|
28
|
+
return child_nodes.first[index + 1...]
|
29
|
+
end
|
30
|
+
|
31
|
+
index = child_nodes.index(node)
|
32
|
+
child_nodes[index + 1...]
|
33
33
|
end
|
34
34
|
end
|
@@ -93,7 +93,7 @@ module NodeQuery::Compiler
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
else
|
96
|
-
|
96
|
+
@adapter.get_children(node).each do |child_node|
|
97
97
|
if match?(child_node, child_node)
|
98
98
|
nodes << child_node
|
99
99
|
break if options[:stop_at_first_match]
|
@@ -171,10 +171,10 @@ module NodeQuery::Compiler
|
|
171
171
|
end
|
172
172
|
end
|
173
173
|
when '+'
|
174
|
-
next_sibling = node.
|
174
|
+
next_sibling = @adapter.get_siblings(node).first
|
175
175
|
nodes << next_sibling if @rest.match?(next_sibling, next_sibling)
|
176
176
|
when '~'
|
177
|
-
node.
|
177
|
+
@adapter.get_siblings(node).each do |sibling_node|
|
178
178
|
nodes << sibling_node if @rest.match?(sibling_node, sibling_node)
|
179
179
|
end
|
180
180
|
end
|
data/lib/node_query/version.rb
CHANGED
data/lib/node_query.rb
CHANGED
@@ -11,6 +11,7 @@ class NodeQuery
|
|
11
11
|
autoload :Adapter, "node_query/adapter"
|
12
12
|
autoload :ParserAdapter, "node_query/adapter/parser"
|
13
13
|
autoload :SyntaxTreeAdapter, "node_query/adapter/syntax_tree"
|
14
|
+
autoload :PrismAdapter, "node_query/adapter/prism"
|
14
15
|
autoload :Compiler, "node_query/compiler"
|
15
16
|
autoload :Helper, "node_query/helper"
|
16
17
|
autoload :NodeRules, "node_query/node_rules"
|
@@ -65,6 +66,8 @@ class NodeQuery
|
|
65
66
|
ParserAdapter.new
|
66
67
|
when :syntax_tree
|
67
68
|
SyntaxTreeAdapter.new
|
69
|
+
when :prism
|
70
|
+
PrismAdapter.new
|
68
71
|
else
|
69
72
|
raise InvalidAdapterError, "adapter #{adapter} is not supported"
|
70
73
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: node_query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.15.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:
|
11
|
+
date: 2024-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ast node query language
|
14
14
|
email:
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- lib/node_query.rb
|
28
28
|
- lib/node_query/adapter.rb
|
29
29
|
- lib/node_query/adapter/parser.rb
|
30
|
+
- lib/node_query/adapter/prism.rb
|
30
31
|
- lib/node_query/adapter/syntax_tree.rb
|
31
32
|
- lib/node_query/compiler.rb
|
32
33
|
- lib/node_query/compiler/array_value.rb
|
@@ -78,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
79
|
- !ruby/object:Gem::Version
|
79
80
|
version: '0'
|
80
81
|
requirements: []
|
81
|
-
rubygems_version: 3.
|
82
|
+
rubygems_version: 3.5.3
|
82
83
|
signing_key:
|
83
84
|
specification_version: 4
|
84
85
|
summary: ast node query language
|