node_query 1.13.7 → 1.13.9

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: 9d3c978851b309269c480384d94e9df4d8f217c3c277cb26992fda3d52c29a9c
4
- data.tar.gz: 88aff1c87c8b0383176b9821baae9997314ceee2993fecba4470614e4b2b48d6
3
+ metadata.gz: 215ae99bb6d5fddf440256e3982a06f8795ab484008dcc736679151f0b1c963a
4
+ data.tar.gz: 0e69083c8350bc90058d0b5d62e90046d612a4e26e59141bd7722b8657ec6f06
5
5
  SHA512:
6
- metadata.gz: 90be84a8b0200d32b5996251a657474053fa95bb265c3b9403334c161a374ba54fd8ac4e64c77d15bccae65a9651539522300ba8a9c0c92fb9fde7d51696625f
7
- data.tar.gz: 9fa294dfc8e0f1ab399aa21e6dfffdd3b2356e37674d287ba21d3e4c38ffc52727fd48a2edbcce4ca9b03016df322ac52d46b80518dbffb2022b01bdd0c163a3
6
+ metadata.gz: 561dff60b719e9596343e4f667939b06ffec1078b0802c1236dba472d7051672e1203d610d0e5b4685fcc936728355b69935f1fdf2d2166f85910afa7f484485
7
+ data.tar.gz: c08f454ba9300e0401d08cff16f269348e9913a6bb1d5b52d237cd0abe45cbb15f5b7dade4f49bdb0b24c279843f954dbf2b4d5ef200533109c14df8a00a9b35
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.13.9 (2023-08-02)
4
+
5
+ * Add `OPERATOR` macro
6
+ * Use operator `=` instead of `==`
7
+
8
+ ## 1.13.8 (2023-06-28)
9
+
10
+ * Check `.to_value` instead of `.type`
11
+
3
12
  ## 1.13.7 (2023-06-26)
4
13
 
5
14
  * Revert "Flatten syntax_tree children"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_query (1.13.7)
4
+ node_query (1.13.9)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -7,7 +7,7 @@ module NodeQuery::Compiler
7
7
  # @param key [String] the key
8
8
  # @param value the value can be any class implement {NodeQuery::Compiler::Comparable}
9
9
  # @param operator [String] the operator
10
- def initialize(key:, value:, operator: '==')
10
+ def initialize(key:, value:, operator: '=')
11
11
  @key = key
12
12
  @value = value
13
13
  @operator = operator
@@ -15,7 +15,7 @@ module NodeQuery::Compiler
15
15
  # @param node [Node] the node
16
16
  # @param base_node [Node] the base node for evaluated value
17
17
  # @return [Boolean]
18
- def match?(node, base_node, _operator = '==')
18
+ def match?(node, base_node, _operator = '=')
19
19
  return false unless node
20
20
 
21
21
  @node_type.to_sym == NodeQuery.adapter.get_node_type(node) && (!@attribute_list || @attribute_list.match?(
@@ -3,17 +3,17 @@
3
3
  module NodeQuery::Compiler
4
4
  # Compare acutal value with expected value.
5
5
  module Comparable
6
- SIMPLE_VALID_OPERATORS = ['==', '!=', 'includes', 'not_includes']
7
- STRING_VALID_OPERATORS = ['==', '!=', '^=', '$=', '*=', 'includes', 'not_includes']
8
- NUMBER_VALID_OPERATORS = ['==', '!=', '>', '>=', '<', '<=', 'includes', 'not_includes']
9
- ARRAY_VALID_OPERATORS = ['==', '!=', 'in', 'not_in']
6
+ SIMPLE_VALID_OPERATORS = ['=', '!=', 'includes', 'not_includes']
7
+ STRING_VALID_OPERATORS = ['=', '!=', '^=', '$=', '*=', 'includes', 'not_includes']
8
+ NUMBER_VALID_OPERATORS = ['=', '!=', '>', '>=', '<', '<=', 'includes', 'not_includes']
9
+ ARRAY_VALID_OPERATORS = ['=', '!=', 'in', 'not_in']
10
10
  REGEXP_VALID_OPERATORS = ['=~', '!~']
11
11
 
12
12
  # Check if the actual value matches the expected value.
13
13
  #
14
14
  # @param node [Node] node to calculate actual value
15
15
  # @param base_node [Node] the base node for evaluated value
16
- # @param operator [String] operator to compare with expected value, operator can be <code>'=='</code>, <code>'!='</code>, <code>'>'</code>, <code>'>='</code>, <code>'<'</code>, <code>'<='</code>, <code>'includes'</code>, <code>'in'</code>, <code>'not_in'</code>, <code>'=~'</code>, <code>'!~'</code>
16
+ # @param operator [String] operator to compare with expected value, operator can be <code>'='</code>, <code>'!='</code>, <code>'>'</code>, <code>'>='</code>, <code>'<'</code>, <code>'<='</code>, <code>'includes'</code>, <code>'in'</code>, <code>'not_in'</code>, <code>'=~'</code>, <code>'!~'</code>
17
17
  # @return [Boolean] true if actual value matches the expected value
18
18
  # @raise [NodeQuery::Compiler::InvalidOperatorError] if operator is invalid
19
19
  def match?(node, base_node, operator)
@@ -51,9 +51,9 @@ module NodeQuery::Compiler
51
51
  actual <= expected
52
52
  when 'in'
53
53
  if node.is_a?(Array)
54
- node.all? { |child| expected.any? { |expected_child| expected_child.match?(child, base_node, '==') } }
54
+ node.all? { |child| expected.any? { |expected_child| expected_child.match?(child, base_node, '=') } }
55
55
  else
56
- expected.any? { |expected_child| expected_child.match?(node, base_node, '==') }
56
+ expected.any? { |expected_child| expected_child.match?(node, base_node, '=') }
57
57
  end
58
58
  when 'not_in'
59
59
  if node.is_a?(Array)
@@ -69,7 +69,7 @@ module NodeQuery::Compiler
69
69
  if expected.is_a?(::Array)
70
70
  actual.is_a?(::Array) && actual.size == expected.size &&
71
71
  actual.zip(expected).all? { |actual_child, expected_child|
72
- expected_child.match?(actual_child, base_node, '==')
72
+ expected_child.match?(actual_child, base_node, '=')
73
73
  }
74
74
  else
75
75
  is_equal?(actual, expected)
@@ -33,7 +33,7 @@ module NodeQuery::Compiler
33
33
  # Check if node matches the selector.
34
34
  # @param node [Node] the node
35
35
  # @param base_node [Node] the base node for evaluated node
36
- def match?(node, base_node, operator = "==")
36
+ def match?(node, base_node, operator = "=")
37
37
  if node.is_a?(::Array)
38
38
  case operator
39
39
  when "not_includes"
@@ -121,7 +121,7 @@ class NodeQuery::NodeRules
121
121
  actual.zip(expected).all? { |a, e| match_value?(a, e) }
122
122
  when NilClass
123
123
  if NodeQuery.adapter.is_node?(actual)
124
- :nil == actual.type
124
+ actual.to_value.nil?
125
125
  else
126
126
  actual.nil?
127
127
  end
@@ -132,9 +132,9 @@ class NodeQuery::NodeRules
132
132
  actual == expected
133
133
  end
134
134
  when TrueClass
135
- :true == actual&.type
135
+ true == actual&.to_value
136
136
  when FalseClass
137
- :false == actual&.type
137
+ false == actual&.to_value
138
138
  else
139
139
  if NodeQuery.adapter.is_node?(expected)
140
140
  actual == expected
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeQuery
4
- VERSION = "1.13.7"
4
+ VERSION = "1.13.9"
5
5
  end
@@ -10,6 +10,7 @@ macros
10
10
  NODE_TYPE /\.[a-zA-Z]+/
11
11
  IDENTIFIER /[@\*\-\.\w]*\w/
12
12
  IDENTIFIER_VALUE /[@\.\w!&:\?<>=]+/
13
+ OPERATOR /(\^=|\$=|\*=|!=|=~|!~|>=|<=|>|<|=|not includes|includes|not in|in)/i
13
14
  FALSE /false/
14
15
  FLOAT /\-?\d+\.\d+/
15
16
  INTEGER /\-?\d+/
@@ -39,21 +40,7 @@ rules
39
40
  /#{CLOSE_SELECTOR}/ { [:tCLOSE_SELECTOR, text] }
40
41
  /#{OPEN_ATTRIBUTE}/ { @nested_count += 1; @state = :KEY; [:tOPEN_ATTRIBUTE, text] }
41
42
  :KEY /\s+/
42
- :KEY /\^=/ { @state = :VALUE; [:tOPERATOR, '^='] }
43
- :KEY /\$=/ { @state = :VALUE; [:tOPERATOR, '$='] }
44
- :KEY /\*=/ { @state = :VALUE; [:tOPERATOR, '*='] }
45
- :KEY /!=/ { @state = :VALUE; [:tOPERATOR, '!='] }
46
- :KEY /=~/ { @state = :VALUE; [:tOPERATOR, '=~'] }
47
- :KEY /!~/ { @state = :VALUE; [:tOPERATOR, '!~'] }
48
- :KEY />=/ { @state = :VALUE; [:tOPERATOR, '>='] }
49
- :KEY /<=/ { @state = :VALUE; [:tOPERATOR, '<='] }
50
- :KEY />/ { @state = :VALUE; [:tOPERATOR, '>'] }
51
- :KEY /</ { @state = :VALUE; [:tOPERATOR, '<'] }
52
- :KEY /=/ { @state = :VALUE; [:tOPERATOR, '=='] }
53
- :KEY /not includes/i { @state = :VALUE; [:tOPERATOR, 'not_includes'] }
54
- :KEY /includes/i { @state = :VALUE; [:tOPERATOR, 'includes'] }
55
- :KEY /not in/i { @state = :VALUE; [:tOPERATOR, 'not_in'] }
56
- :KEY /in/i { @state = :VALUE; [:tOPERATOR, 'in'] }
43
+ :KEY /#{OPERATOR}/ { @state = :VALUE; [:tOPERATOR, text.downcase.sub(' ', '_')] }
57
44
  :KEY /#{IDENTIFIER}/ { [:tKEY, text] }
58
45
  :VALUE /\s+/
59
46
  :VALUE /\[\]=/ { [:tIDENTIFIER_VALUE, text] }
@@ -23,6 +23,7 @@ class NodeQueryLexer
23
23
  NODE_TYPE = /\.[a-zA-Z]+/
24
24
  IDENTIFIER = /[@\*\-\.\w]*\w/
25
25
  IDENTIFIER_VALUE = /[@\.\w!&:\?<>=]+/
26
+ OPERATOR = /(\^=|\$=|\*=|!=|=~|!~|>=|<=|>|<|=|not includes|includes|not in|in)/i
26
27
  FALSE = /false/
27
28
  FLOAT = /\-?\d+\.\d+/
28
29
  INTEGER = /\-?\d+/
@@ -157,36 +158,8 @@ class NodeQueryLexer
157
158
  case
158
159
  when ss.skip(/\s+/) then
159
160
  # do nothing
160
- when ss.skip(/\^=/) then
161
- action { @state = :VALUE; [:tOPERATOR, '^='] }
162
- when ss.skip(/\$=/) then
163
- action { @state = :VALUE; [:tOPERATOR, '$='] }
164
- when ss.skip(/\*=/) then
165
- action { @state = :VALUE; [:tOPERATOR, '*='] }
166
- when ss.skip(/!=/) then
167
- action { @state = :VALUE; [:tOPERATOR, '!='] }
168
- when ss.skip(/=~/) then
169
- action { @state = :VALUE; [:tOPERATOR, '=~'] }
170
- when ss.skip(/!~/) then
171
- action { @state = :VALUE; [:tOPERATOR, '!~'] }
172
- when ss.skip(/>=/) then
173
- action { @state = :VALUE; [:tOPERATOR, '>='] }
174
- when ss.skip(/<=/) then
175
- action { @state = :VALUE; [:tOPERATOR, '<='] }
176
- when ss.skip(/>/) then
177
- action { @state = :VALUE; [:tOPERATOR, '>'] }
178
- when ss.skip(/</) then
179
- action { @state = :VALUE; [:tOPERATOR, '<'] }
180
- when ss.skip(/=/) then
181
- action { @state = :VALUE; [:tOPERATOR, '=='] }
182
- when ss.skip(/not includes/i) then
183
- action { @state = :VALUE; [:tOPERATOR, 'not_includes'] }
184
- when ss.skip(/includes/i) then
185
- action { @state = :VALUE; [:tOPERATOR, 'includes'] }
186
- when ss.skip(/not in/i) then
187
- action { @state = :VALUE; [:tOPERATOR, 'not_in'] }
188
- when ss.skip(/in/i) then
189
- action { @state = :VALUE; [:tOPERATOR, 'in'] }
161
+ when text = ss.scan(/#{OPERATOR}/) then
162
+ action { @state = :VALUE; [:tOPERATOR, text.downcase.sub(' ', '_')] }
190
163
  when text = ss.scan(/#{IDENTIFIER}/) then
191
164
  action { [:tKEY, text] }
192
165
  else
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.7
4
+ version: 1.13.9
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-06-26 00:00:00.000000000 Z
11
+ date: 2023-08-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ast node query language
14
14
  email:
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  - !ruby/object:Gem::Version
79
79
  version: '0'
80
80
  requirements: []
81
- rubygems_version: 3.4.13
81
+ rubygems_version: 3.4.17
82
82
  signing_key:
83
83
  specification_version: 4
84
84
  summary: ast node query language