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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f0ea7e92fbee3e2c0c28554dd021b1e2a07fd4c64b9dd7f1a6b5acbc7d8385f
4
- data.tar.gz: cc317efc39dd07bc30c1cd54cd03eded67c82a92a37b809340add4c8372e77ea
3
+ metadata.gz: '085d3a73c288ebe609e98d5ce1e7190afa6b3b9c80751b10c9f411559758f768'
4
+ data.tar.gz: 53d0498ea483d4d199a8116337efffa1885b4cf9b74c95d760898f5aee4d442e
5
5
  SHA512:
6
- metadata.gz: b7bb08d7bacc6da4232f7e16a9397e565ae4b4523b8d177068672441aecdcaa49a01be8b3e614aeef138e365ad210bd1e121857690061324f889e8486105c79a
7
- data.tar.gz: 2736927c6b34ee327b02e4230bc4b8879f8582f8a9840740c99bd122a9d53eecd5c099dc2e3b2407629047a88e3477e253d878fe56e835264e38a405ede78bc2
6
+ metadata.gz: 469b271b62d8f3bcd6883a9d6967af1c0a2b465fe4d06aab93efd18d043fd155543905c35751606de4c9d059add2cf27695f155205c8b4874181d8882a4de081
7
+ data.tar.gz: d6cefeec1185bf80aadfd2c2147b8e8d285a4a0950eb6227955d5075747fec74991d71a3c7a60e3633a90f1bf3d8dbb18bc77ee538454fdbf65deb6be2f99c02
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.13.2 (2023-05-18)
4
+
5
+ * Replace `Parser` specific code
6
+
3
7
  ## 1.13.1 (2023-05-16)
4
8
 
5
9
  * Require `parser` and `syntax_tree` in adapter
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_query (1.13.1)
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.0)
70
+ syntax_tree_ext (0.3.1)
71
71
  syntax_tree
72
72
  thor (1.2.1)
73
73
 
@@ -13,7 +13,7 @@ class NodeQuery::SyntaxTreeAdapter
13
13
  end
14
14
 
15
15
  def get_source(node)
16
- node.source
16
+ node.to_source
17
17
  end
18
18
 
19
19
  def get_children(node)
@@ -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
- case NodeQuery.adapter.get_node_type(node)
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 [Parser::AST::Node] the node
35
- # @param base_node [Parser::AST::Node] the base node for evaluated 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.children.each do |child_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.children.each do |child_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)
@@ -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 [Parser::AST::Node] child node
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 actual.is_a?(Parser::AST::Node)
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 actual.is_a?(Parser::AST::Node)
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 actual.is_a?(Parser::AST::Node)
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 actual.is_a?(Parser::AST::Node)
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 actual.is_a?(Parser::AST::Node)
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
- raise NodeQuery::MethodNotSupported, "#{expected} is not supported"
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeQuery
4
- VERSION = "1.13.1"
4
+ VERSION = "1.13.2"
5
5
  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.13.1
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-15 00:00:00.000000000 Z
11
+ date: 2023-05-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ast node query language
14
14
  email: