node_query 1.13.1 → 1.13.2
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 +2 -2
- data/lib/node_query/adapter/syntax_tree.rb +1 -1
- data/lib/node_query/compiler/comparable.rb +1 -16
- data/lib/node_query/compiler/selector.rb +4 -4
- data/lib/node_query/helper.rb +1 -1
- data/lib/node_query/node_rules.rb +10 -8
- data/lib/node_query/version.rb +1 -1
- 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: '085d3a73c288ebe609e98d5ce1e7190afa6b3b9c80751b10c9f411559758f768'
|
4
|
+
data.tar.gz: 53d0498ea483d4d199a8116337efffa1885b4cf9b74c95d760898f5aee4d442e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 469b271b62d8f3bcd6883a9d6967af1c0a2b465fe4d06aab93efd18d043fd155543905c35751606de4c9d059add2cf27695f155205c8b4874181d8882a4de081
|
7
|
+
data.tar.gz: d6cefeec1185bf80aadfd2c2147b8e8d285a4a0950eb6227955d5075747fec74991d71a3c7a60e3633a90f1bf3d8dbb18bc77ee538454fdbf65deb6be2f99c02
|
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.13.
|
4
|
+
node_query (1.13.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -67,7 +67,7 @@ GEM
|
|
67
67
|
shellany (0.0.1)
|
68
68
|
syntax_tree (6.1.1)
|
69
69
|
prettier_print (>= 1.2.0)
|
70
|
-
syntax_tree_ext (0.3.
|
70
|
+
syntax_tree_ext (0.3.1)
|
71
71
|
syntax_tree
|
72
72
|
thor (1.2.1)
|
73
73
|
|
@@ -90,22 +90,7 @@ module NodeQuery::Compiler
|
|
90
90
|
# @return the node value, could be integer, float, string, boolean, nil, range, and etc.
|
91
91
|
def actual_value(node)
|
92
92
|
if NodeQuery.adapter.is_node?(node)
|
93
|
-
|
94
|
-
when :int, :float, :str, :sym
|
95
|
-
NodeQuery.adapter.get_children(node).last
|
96
|
-
when :true
|
97
|
-
true
|
98
|
-
when :false
|
99
|
-
false
|
100
|
-
when :nil
|
101
|
-
nil
|
102
|
-
when :array
|
103
|
-
NodeQuery.adapter.get_children(node).map { |child_node| actual_value(child_node) }
|
104
|
-
when :begin
|
105
|
-
actual_value(NodeQuery.adapter.get_children(node).first)
|
106
|
-
else
|
107
|
-
node
|
108
|
-
end
|
93
|
+
node.to_value
|
109
94
|
else
|
110
95
|
node
|
111
96
|
end
|
@@ -31,8 +31,8 @@ module NodeQuery::Compiler
|
|
31
31
|
end
|
32
32
|
|
33
33
|
# Check if node matches the selector.
|
34
|
-
# @param node [
|
35
|
-
# @param base_node [
|
34
|
+
# @param node [Node] the node
|
35
|
+
# @param base_node [Node] the base node for evaluated node
|
36
36
|
def match?(node, base_node, operator = "==")
|
37
37
|
if node.is_a?(::Array)
|
38
38
|
case operator
|
@@ -153,9 +153,9 @@ module NodeQuery::Compiler
|
|
153
153
|
nodes << child_node if @rest.match?(child_node, child_node)
|
154
154
|
end
|
155
155
|
else
|
156
|
-
node.
|
156
|
+
NodeQuery.adapter.get_children(node).each do |child_node|
|
157
157
|
if NodeQuery.adapter.is_node?(child_node) && :begin == NodeQuery.adapter.get_node_type(child_node)
|
158
|
-
child_node.
|
158
|
+
NodeQuery.adapter.get_children(child_node).each do |child_child_node|
|
159
159
|
nodes << child_child_node if @rest.match?(child_child_node, child_child_node)
|
160
160
|
end
|
161
161
|
elsif @rest.match?(child_node, child_node)
|
data/lib/node_query/helper.rb
CHANGED
@@ -30,7 +30,7 @@ class NodeQuery::Helper
|
|
30
30
|
# Recursively handle child nodes.
|
31
31
|
# @param node [Node] ast node
|
32
32
|
# @yield [child] Gives a child node.
|
33
|
-
# @yieldparam child [
|
33
|
+
# @yieldparam child [Node] child node
|
34
34
|
def handle_recursive_child(node, &block)
|
35
35
|
NodeQuery.adapter.get_children(node).each do |child|
|
36
36
|
if NodeQuery.adapter.is_node?(child)
|
@@ -95,14 +95,14 @@ class NodeQuery::NodeRules
|
|
95
95
|
|
96
96
|
case expected
|
97
97
|
when Symbol
|
98
|
-
if
|
98
|
+
if NodeQuery.adapter.is_node?(actual)
|
99
99
|
actual_source = NodeQuery.adapter.get_source(actual)
|
100
100
|
actual_source == ":#{expected}" || actual_source == expected.to_s
|
101
101
|
else
|
102
102
|
actual.to_sym == expected
|
103
103
|
end
|
104
104
|
when String
|
105
|
-
if
|
105
|
+
if NodeQuery.adapter.is_node?(actual)
|
106
106
|
actual_source = NodeQuery.adapter.get_source(actual)
|
107
107
|
actual_source == expected || actual_source == unwrap_quote(expected) ||
|
108
108
|
unwrap_quote(actual_source) == expected || unwrap_quote(actual_source) == unwrap_quote(expected)
|
@@ -110,7 +110,7 @@ class NodeQuery::NodeRules
|
|
110
110
|
actual.to_s == expected || wrap_quote(actual.to_s) == expected
|
111
111
|
end
|
112
112
|
when Regexp
|
113
|
-
if
|
113
|
+
if NodeQuery.adapter.is_node?(actual)
|
114
114
|
actual.to_source =~ Regexp.new(expected.to_s, Regexp::MULTILINE)
|
115
115
|
else
|
116
116
|
actual.to_s =~ Regexp.new(expected.to_s, Regexp::MULTILINE)
|
@@ -120,13 +120,13 @@ class NodeQuery::NodeRules
|
|
120
120
|
|
121
121
|
actual.zip(expected).all? { |a, e| match_value?(a, e) }
|
122
122
|
when NilClass
|
123
|
-
if
|
123
|
+
if NodeQuery.adapter.is_node?(actual)
|
124
124
|
:nil == actual.type
|
125
125
|
else
|
126
126
|
actual.nil?
|
127
127
|
end
|
128
128
|
when Numeric
|
129
|
-
if
|
129
|
+
if NodeQuery.adapter.is_node?(actual)
|
130
130
|
actual.children[0] == expected
|
131
131
|
else
|
132
132
|
actual == expected
|
@@ -135,10 +135,12 @@ class NodeQuery::NodeRules
|
|
135
135
|
:true == actual&.type
|
136
136
|
when FalseClass
|
137
137
|
:false == actual&.type
|
138
|
-
when Parser::AST::Node
|
139
|
-
actual == expected
|
140
138
|
else
|
141
|
-
|
139
|
+
if NodeQuery.adapter.is_node?(expected)
|
140
|
+
actual == expected
|
141
|
+
else
|
142
|
+
raise NodeQuery::MethodNotSupported, "#{expected} is not supported"
|
143
|
+
end
|
142
144
|
end
|
143
145
|
end
|
144
146
|
|
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.13.
|
4
|
+
version: 1.13.2
|
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-05-
|
11
|
+
date: 2023-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ast node query language
|
14
14
|
email:
|