node_query 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +2 -2
- data/lib/node_query/compiler/basic_selector.rb +1 -1
- data/lib/node_query/compiler/comparable.rb +6 -6
- data/lib/node_query/compiler/evaluated_value.rb +2 -2
- data/lib/node_query/compiler/identifier.rb +1 -1
- data/lib/node_query/compiler/regexp.rb +1 -1
- data/lib/node_query/helper.rb +2 -2
- data/lib/node_query/version.rb +1 -1
- data/lib/node_query.rb +6 -4
- data/lib/node_query_parser.racc.rb +1 -1
- data/lib/node_query_parser.y +2 -2
- data/sig/node_query/adapter.rbs +6 -6
- data/sig/node_query.rbs +3 -3
- 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: 6e8376d63c29cbdec1d39e74083667724b0b84e872d7a26fc281b18061e82f02
|
4
|
+
data.tar.gz: '078fc70a86d2bfca404c791c6f9466780daca529aca5e984aca4ecdc6fb4c760'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 444e804e949a7ebd40ebc10312de06bd570115995044598fe324210a60e85fd90931393f0eaa6845ec46c916101ab69e23ccd9490ffa40c99626ecc96c0acfb1
|
7
|
+
data.tar.gz: e0c5ab049ddc1f608b6559b186bd9f43b16b4d6a6b8ed906bcf261cebdb18a482768673727644797dc8f29465d423fc3148c722db001904439d1890cd80541db
|
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.
|
4
|
+
node_query (1.2.0)
|
5
5
|
activesupport
|
6
6
|
|
7
7
|
GEM
|
@@ -50,7 +50,7 @@ GEM
|
|
50
50
|
oedipus_lex (2.6.0)
|
51
51
|
parser (3.1.2.0)
|
52
52
|
ast (~> 2.4.1)
|
53
|
-
parser_node_ext (0.
|
53
|
+
parser_node_ext (0.2.0)
|
54
54
|
parser
|
55
55
|
pry (0.14.1)
|
56
56
|
coderay (~> 1.1)
|
@@ -17,7 +17,7 @@ module NodeQuery::Compiler
|
|
17
17
|
def match?(node, _operator = '==')
|
18
18
|
return false unless node
|
19
19
|
|
20
|
-
@node_type.to_sym == NodeQuery.
|
20
|
+
@node_type.to_sym == NodeQuery.adapter.get_node_type(node) && (!@attribute_list || @attribute_list.match?(node))
|
21
21
|
end
|
22
22
|
|
23
23
|
def to_s
|
@@ -75,9 +75,9 @@ module NodeQuery::Compiler
|
|
75
75
|
# @return the node value, could be integer, float, string, boolean, nil, range, and etc.
|
76
76
|
def actual_value(node)
|
77
77
|
if node.is_a?(::Parser::AST::Node)
|
78
|
-
case NodeQuery.
|
78
|
+
case NodeQuery.adapter.get_node_type(node)
|
79
79
|
when :int, :float, :str, :sym
|
80
|
-
NodeQuery.
|
80
|
+
NodeQuery.adapter.get_children(node).last
|
81
81
|
when :true
|
82
82
|
true
|
83
83
|
when :false
|
@@ -85,13 +85,13 @@ module NodeQuery::Compiler
|
|
85
85
|
when :nil
|
86
86
|
nil
|
87
87
|
when :array
|
88
|
-
NodeQuery.
|
88
|
+
NodeQuery.adapter.get_children(node).map { |child_node| actual_value(child_node) }
|
89
89
|
when :irange
|
90
|
-
actual_value(NodeQuery.
|
90
|
+
actual_value(NodeQuery.adapter.get_children(node).first)..actual_value(NodeQuery.adapter.get_children(node).last)
|
91
91
|
when :erange
|
92
|
-
actual_value(NodeQuery.
|
92
|
+
actual_value(NodeQuery.adapter.get_children(node).first)...actual_value(NodeQuery.adapter.get_children(node).last)
|
93
93
|
when :begin
|
94
|
-
actual_value(NodeQuery.
|
94
|
+
actual_value(NodeQuery.adapter.get_children(node).first)
|
95
95
|
else
|
96
96
|
node
|
97
97
|
end
|
@@ -20,7 +20,7 @@ module NodeQuery::Compiler
|
|
20
20
|
# @return [String] if node is a {Node}, return the node source code, otherwise return the node itself.
|
21
21
|
def actual_value(node)
|
22
22
|
if node.is_a?(::Parser::AST::Node)
|
23
|
-
NodeQuery.
|
23
|
+
NodeQuery.adapter.get_source(node)
|
24
24
|
else
|
25
25
|
node
|
26
26
|
end
|
@@ -31,7 +31,7 @@ module NodeQuery::Compiler
|
|
31
31
|
def expected_value
|
32
32
|
node = NodeQuery::Helper.get_target_node(base_node, @value)
|
33
33
|
if node.is_a?(::Parser::AST::Node)
|
34
|
-
NodeQuery.
|
34
|
+
NodeQuery.adapter.get_source(node)
|
35
35
|
else
|
36
36
|
node
|
37
37
|
end
|
@@ -20,7 +20,7 @@ module NodeQuery::Compiler
|
|
20
20
|
# otherwise, return the String value.
|
21
21
|
def actual_value(node)
|
22
22
|
if node.is_a?(::Parser::AST::Node)
|
23
|
-
NodeQuery.
|
23
|
+
NodeQuery.adapter.get_source(node)
|
24
24
|
elsif node.is_a?(::Array)
|
25
25
|
node.map { |n| actual_value(n) }
|
26
26
|
else
|
@@ -18,7 +18,7 @@ module NodeQuery::Compiler
|
|
18
18
|
def match?(node, operator = '=~')
|
19
19
|
match =
|
20
20
|
if node.is_a?(::Parser::AST::Node)
|
21
|
-
@value.match(NodeQuery.
|
21
|
+
@value.match(NodeQuery.adapter.get_source(node))
|
22
22
|
else
|
23
23
|
@value.match(node.to_s)
|
24
24
|
end
|
data/lib/node_query/helper.rb
CHANGED
@@ -30,8 +30,8 @@ class NodeQuery::Helper
|
|
30
30
|
# @yield [child] Gives a child node.
|
31
31
|
# @yieldparam child [Parser::AST::Node] child node
|
32
32
|
def self.handle_recursive_child(node, &block)
|
33
|
-
NodeQuery.
|
34
|
-
if NodeQuery.
|
33
|
+
NodeQuery.adapter.get_children(node).each do |child|
|
34
|
+
if NodeQuery.adapter.is_node?(child)
|
35
35
|
block.call(child)
|
36
36
|
handle_recursive_child(child, &block)
|
37
37
|
end
|
data/lib/node_query/version.rb
CHANGED
data/lib/node_query.rb
CHANGED
@@ -3,13 +3,15 @@
|
|
3
3
|
require 'active_support/core_ext/array'
|
4
4
|
|
5
5
|
require_relative "node_query/version"
|
6
|
-
require_relative "node_query/parser_adapter"
|
7
|
-
require_relative "node_query/compiler"
|
8
|
-
require_relative "node_query/helper"
|
9
6
|
require_relative "./node_query_lexer.rex"
|
10
7
|
require_relative "./node_query_parser.racc"
|
11
8
|
|
12
9
|
class NodeQuery
|
10
|
+
autoload :Adapter, "node_query/adapter"
|
11
|
+
autoload :ParserAdapter, "node_query/parser_adapter"
|
12
|
+
autoload :Compiler, "node_query/compiler"
|
13
|
+
autoload :Helper, "node_query/helper"
|
14
|
+
|
13
15
|
# Configure NodeQuery
|
14
16
|
# @param [Hash] options options to configure
|
15
17
|
# @option options [NodeQuery::Adapter] :adapter the adpater
|
@@ -19,7 +21,7 @@ class NodeQuery
|
|
19
21
|
|
20
22
|
# Get the adapter
|
21
23
|
# @return [NodeQuery::Adapter] current adapter, by default is {NodeQuery::ParserAdapter}
|
22
|
-
def self.
|
24
|
+
def self.adapter
|
23
25
|
@adapter ||= ParserAdapter.new
|
24
26
|
end
|
25
27
|
|
@@ -249,7 +249,7 @@ def _reduce_13(val, _values)
|
|
249
249
|
end
|
250
250
|
|
251
251
|
def _reduce_14(val, _values)
|
252
|
-
NodeQuery::Compiler::Attribute.new(key: val[0], value: NodeQuery::Compiler::
|
252
|
+
NodeQuery::Compiler::Attribute.new(key: val[0], value: NodeQuery::Compiler::ArrayValue.new, operator: val[1])
|
253
253
|
end
|
254
254
|
|
255
255
|
def _reduce_15(val, _values)
|
data/lib/node_query_parser.y
CHANGED
@@ -28,7 +28,7 @@ rule
|
|
28
28
|
|
29
29
|
attribute
|
30
30
|
: tKEY tOPERATOR value { NodeQuery::Compiler::Attribute.new(key: val[0], value: val[2], operator: val[1]) }
|
31
|
-
| tKEY tOPERATOR tOPEN_ARRAY tCLOSE_ARRAY { NodeQuery::Compiler::Attribute.new(key: val[0], value: NodeQuery::Compiler::
|
31
|
+
| tKEY tOPERATOR tOPEN_ARRAY tCLOSE_ARRAY { NodeQuery::Compiler::Attribute.new(key: val[0], value: NodeQuery::Compiler::ArrayValue.new, operator: val[1]) }
|
32
32
|
| tKEY tOPERATOR tOPEN_ARRAY array_value tCLOSE_ARRAY { NodeQuery::Compiler::Attribute.new(key: val[0], value: val[3], operator: val[1]) }
|
33
33
|
|
34
34
|
array_value
|
@@ -60,4 +60,4 @@ end
|
|
60
60
|
|
61
61
|
def next_token
|
62
62
|
@lexer.next_token
|
63
|
-
end
|
63
|
+
end
|
data/sig/node_query/adapter.rbs
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
class NodeQuery::Adapter
|
2
|
-
def is_node?: (node:
|
1
|
+
class NodeQuery::Adapter[T]
|
2
|
+
def is_node?: (node: T) -> bool
|
3
3
|
|
4
|
-
def get_node_type: (node:
|
4
|
+
def get_node_type: (node: T) -> String
|
5
5
|
|
6
|
-
def get_source: (node:
|
6
|
+
def get_source: (node: T) -> String
|
7
7
|
|
8
|
-
def get_children: (node:
|
8
|
+
def get_children: (node: T) -> Array[T]
|
9
9
|
|
10
|
-
def get_siblings: (node:
|
10
|
+
def get_siblings: (node: T) -> Array[T]
|
11
11
|
end
|
data/sig/node_query.rbs
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
class NodeQuery
|
1
|
+
class NodeQuery[T]
|
2
2
|
VERSION: String
|
3
3
|
|
4
4
|
def self.configure: (options: { adapter: NodeQuery::Adapter }) -> void
|
5
5
|
|
6
|
-
def self.
|
6
|
+
def self.adapter: () -> NodeQuery::Adapter
|
7
7
|
|
8
8
|
def initialize: (nql: String) -> NodeQuery
|
9
9
|
|
10
|
-
def parse: (node:
|
10
|
+
def parse: (node: T) -> Array[T]
|
11
11
|
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.2.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: 2022-
|
11
|
+
date: 2022-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|