node_query 1.12.0 → 1.12.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 +4 -0
- data/Gemfile.lock +4 -4
- data/README.md +5 -5
- data/lib/node_query/adapter.rb +1 -1
- data/lib/node_query/compiler/basic_selector.rb +4 -1
- data/lib/node_query/compiler/comparable.rb +7 -3
- data/lib/node_query/compiler/selector.rb +13 -2
- data/lib/node_query/helper.rb +3 -3
- data/lib/node_query/node_rules.rb +7 -6
- data/lib/node_query/version.rb +1 -1
- 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: 35243974bb269cb011bc7fb7c4ca8877ef0338cd4cfb8dc80785a06e9b40ee6f
|
4
|
+
data.tar.gz: ad100af634d93ddaa21bd37b89c3d0d542645007ee9bcd73c0f8fd28fe7211ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 656a13c7124f155c6ed96c5d39a901edd248b4ee1d4b19b2d2205c2f244ba0057dec372087b5a4ba08c5d00e784ae5655a0fee1656befe3061df780e8edc9e7b
|
7
|
+
data.tar.gz: e811b204f0cc9848b9c65a85295049e37e7f1bf2cb1897f79236093af95a941133962ae425d125c103e123da9019960d00ddf4c41850e868cf5fabd7c245f64a
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
node_query (1.12.
|
4
|
+
node_query (1.12.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -38,14 +38,14 @@ GEM
|
|
38
38
|
nenv (~> 0.1)
|
39
39
|
shellany (~> 0.0)
|
40
40
|
oedipus_lex (2.6.0)
|
41
|
-
parser (3.1.
|
41
|
+
parser (3.2.1.1)
|
42
42
|
ast (~> 2.4.1)
|
43
|
-
parser_node_ext (0.
|
43
|
+
parser_node_ext (1.0.0)
|
44
44
|
parser
|
45
45
|
pry (0.14.1)
|
46
46
|
coderay (~> 1.1)
|
47
47
|
method_source (~> 1.0)
|
48
|
-
racc (1.6.
|
48
|
+
racc (1.6.2)
|
49
49
|
rake (13.0.6)
|
50
50
|
rb-fsevent (0.11.1)
|
51
51
|
rb-inotify (0.10.1)
|
data/README.md
CHANGED
@@ -115,7 +115,7 @@ It matches class node whose parent class name is Base
|
|
115
115
|
### nql matches evaluated value
|
116
116
|
|
117
117
|
```
|
118
|
-
.ivasgn[
|
118
|
+
.ivasgn[variable="@{{value}}"]
|
119
119
|
```
|
120
120
|
|
121
121
|
It matches ivasgn node whose left value equals '@' plus the evaluated value of right value.
|
@@ -271,7 +271,7 @@ It matches send node whose parent is def node.
|
|
271
271
|
#### Adjacent sibling combinator
|
272
272
|
|
273
273
|
```
|
274
|
-
.send[
|
274
|
+
.send[variable=@id] + .send
|
275
275
|
```
|
276
276
|
|
277
277
|
It matches send node only if it is immediately follows the send node whose left value is @id.
|
@@ -279,7 +279,7 @@ It matches send node only if it is immediately follows the send node whose left
|
|
279
279
|
#### General sibling combinator
|
280
280
|
|
281
281
|
```
|
282
|
-
.send[
|
282
|
+
.send[variable=@id] ~ .send
|
283
283
|
```
|
284
284
|
|
285
285
|
It matches send node only if it is follows the send node whose left value is @id.
|
@@ -323,7 +323,7 @@ It matches the last def node.
|
|
323
323
|
### nql matches multiple expressions
|
324
324
|
|
325
325
|
```
|
326
|
-
.ivasgn[
|
326
|
+
.ivasgn[variable=@id], .ivasgn[variable=@name]
|
327
327
|
```
|
328
328
|
|
329
329
|
It matches ivasgn node whose left value is either @id or @name.
|
@@ -363,7 +363,7 @@ It matches class node whose parent class name is Base
|
|
363
363
|
### rules matches evaluated value
|
364
364
|
|
365
365
|
```
|
366
|
-
{ node_type: 'ivasgn',
|
366
|
+
{ node_type: 'ivasgn', variable: '@{{value}}' }
|
367
367
|
```
|
368
368
|
|
369
369
|
It matches ivasgn node whose left value equals '@' plus the evaluated value of right value.
|
data/lib/node_query/adapter.rb
CHANGED
@@ -18,7 +18,10 @@ module NodeQuery::Compiler
|
|
18
18
|
def match?(node, base_node, _operator = '==')
|
19
19
|
return false unless node
|
20
20
|
|
21
|
-
@node_type.to_sym == NodeQuery.adapter.get_node_type(node) && (!@attribute_list || @attribute_list.match?(
|
21
|
+
@node_type.to_sym == NodeQuery.adapter.get_node_type(node) && (!@attribute_list || @attribute_list.match?(
|
22
|
+
node,
|
23
|
+
base_node
|
24
|
+
))
|
22
25
|
end
|
23
26
|
|
24
27
|
def to_s
|
@@ -25,7 +25,9 @@ module NodeQuery::Compiler
|
|
25
25
|
when '!='
|
26
26
|
if expected.is_a?(::Array)
|
27
27
|
!actual.is_a?(::Array) || actual.size != expected.size ||
|
28
|
-
actual.zip(expected).any? { |actual_child, expected_child|
|
28
|
+
actual.zip(expected).any? { |actual_child, expected_child|
|
29
|
+
expected_child.match?(actual_child, base_node, '!=')
|
30
|
+
}
|
29
31
|
else
|
30
32
|
!is_equal?(actual, expected)
|
31
33
|
end
|
@@ -66,7 +68,9 @@ module NodeQuery::Compiler
|
|
66
68
|
else
|
67
69
|
if expected.is_a?(::Array)
|
68
70
|
actual.is_a?(::Array) && actual.size == expected.size &&
|
69
|
-
actual.zip(expected).all? { |actual_child, expected_child|
|
71
|
+
actual.zip(expected).all? { |actual_child, expected_child|
|
72
|
+
expected_child.match?(actual_child, base_node, '==')
|
73
|
+
}
|
70
74
|
else
|
71
75
|
is_equal?(actual, expected)
|
72
76
|
end
|
@@ -110,7 +114,7 @@ module NodeQuery::Compiler
|
|
110
114
|
# Get the expected value
|
111
115
|
# @param base_node [Node] the base node for evaluated value
|
112
116
|
# @return expected value, could be integer, float, string, boolean, nil, range, and etc.
|
113
|
-
def expected_value(
|
117
|
+
def expected_value(_base_node)
|
114
118
|
@value
|
115
119
|
end
|
116
120
|
|
@@ -12,7 +12,15 @@ module NodeQuery::Compiler
|
|
12
12
|
# @param attribute_list [NodeQuery::Compiler::AttributeList] the attribute list
|
13
13
|
# @param pseudo_class [String] the pseudo class, can be <code>has</code> or <code>not_has</code>
|
14
14
|
# @param pseudo_selector [NodeQuery::Compiler::Expression] the pseudo selector
|
15
|
-
def initialize(
|
15
|
+
def initialize(
|
16
|
+
goto_scope: nil,
|
17
|
+
relationship: nil,
|
18
|
+
rest: nil,
|
19
|
+
basic_selector: nil,
|
20
|
+
position: nil,
|
21
|
+
pseudo_class: nil,
|
22
|
+
pseudo_selector: nil
|
23
|
+
)
|
16
24
|
@goto_scope = goto_scope
|
17
25
|
@relationship = relationship
|
18
26
|
@rest = rest
|
@@ -36,7 +44,10 @@ module NodeQuery::Compiler
|
|
36
44
|
return false
|
37
45
|
end
|
38
46
|
end
|
39
|
-
NodeQuery.adapter.is_node?(node) && (!@basic_selector || (operator == "!=" ? !@basic_selector.match?(
|
47
|
+
NodeQuery.adapter.is_node?(node) && (!@basic_selector || (operator == "!=" ? !@basic_selector.match?(
|
48
|
+
node,
|
49
|
+
base_node
|
50
|
+
) : @basic_selector.match?(node, base_node))) && match_pseudo_class?(node)
|
40
51
|
end
|
41
52
|
|
42
53
|
# Query nodes by the selector.
|
data/lib/node_query/helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class NodeQuery::Helper
|
4
|
-
class <<self
|
4
|
+
class << self
|
5
5
|
# Get target node by the keys.
|
6
6
|
# @param node [Node] ast node
|
7
7
|
# @param keys [String|Array] keys of child node.
|
@@ -43,7 +43,7 @@ class NodeQuery::Helper
|
|
43
43
|
# Evaluate node value.
|
44
44
|
# @example
|
45
45
|
# source code of the node is @id = id
|
46
|
-
# evaluated_node_value(node, "@{{
|
46
|
+
# evaluated_node_value(node, "@{{value}}") # => @id
|
47
47
|
# @param node [Node] ast node
|
48
48
|
# @param str [String] string to be evaluated
|
49
49
|
# @return [String] evaluated string
|
@@ -63,4 +63,4 @@ class NodeQuery::Helper
|
|
63
63
|
node.to_s
|
64
64
|
end
|
65
65
|
end
|
66
|
-
end
|
66
|
+
end
|
@@ -22,7 +22,7 @@ class NodeQuery::NodeRules
|
|
22
22
|
return match_node?(node) ? [node] : []
|
23
23
|
end
|
24
24
|
|
25
|
-
matching_nodes
|
25
|
+
matching_nodes = []
|
26
26
|
if options[:including_self] && match_node?(node)
|
27
27
|
matching_nodes.push(node)
|
28
28
|
return matching_nodes if options[:stop_at_first_match]
|
@@ -51,9 +51,10 @@ class NodeQuery::NodeRules
|
|
51
51
|
def match_node?(node)
|
52
52
|
flat_hash(@rules).keys.all? do |multi_keys|
|
53
53
|
last_key = multi_keys.last
|
54
|
-
actual =
|
55
|
-
|
56
|
-
|
54
|
+
actual =
|
55
|
+
KEYWORDS.include?(last_key) ?
|
56
|
+
NodeQuery::Helper.get_target_node(node, multi_keys[0...-1].join('.')) :
|
57
|
+
NodeQuery::Helper.get_target_node(node, multi_keys.join('.'))
|
57
58
|
expected = expected_value(@rules, multi_keys)
|
58
59
|
expected = NodeQuery::Helper.evaluate_node_value(node, expected) if expected.is_a?(String)
|
59
60
|
case last_key
|
@@ -131,9 +132,9 @@ class NodeQuery::NodeRules
|
|
131
132
|
actual == expected
|
132
133
|
end
|
133
134
|
when TrueClass
|
134
|
-
:true == actual
|
135
|
+
:true == actual&.type
|
135
136
|
when FalseClass
|
136
|
-
:false == actual
|
137
|
+
:false == actual&.type
|
137
138
|
when Parser::AST::Node
|
138
139
|
actual == expected
|
139
140
|
else
|
data/lib/node_query/version.rb
CHANGED
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.12.
|
4
|
+
version: 1.12.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-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ast node query language
|
14
14
|
email:
|
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '0'
|
79
79
|
requirements: []
|
80
|
-
rubygems_version: 3.4.
|
80
|
+
rubygems_version: 3.4.10
|
81
81
|
signing_key:
|
82
82
|
specification_version: 4
|
83
83
|
summary: ast node query language
|