node_query 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,86 +22,85 @@ class NodeQueryParser < Racc::Parser
22
22
  ##### State transition tables begin ###
23
23
 
24
24
  racc_action_table = [
25
- 8, 8, 7, 9, 10, 37, 12, 5, 6, 16,
25
+ 8, 8, 7, 9, 10, 36, 12, 5, 6, 16,
26
26
  27, 17, 21, 22, 23, 24, 29, 30, 31, 32,
27
- 33, 34, 35, 36, 8, 16, 41, 8, 7, 37,
28
- nil, nil, 8, 5, 6, 38, nil, 37, nil, nil,
29
- 29, 30, 31, 32, 33, 34, 35, 36, 29, 30,
30
- 31, 32, 33, 34, 35, 36, 8, 7, 8, 7,
31
- 8, 7, 5, 6, 5, 6, 5, 6, 8, 7,
32
- nil, nil, nil, nil, 5, 6 ]
27
+ 33, 34, 35, 8, 16, 8, 7, 40, 36, nil,
28
+ 8, 5, 6, nil, 37, 36, nil, nil, nil, 29,
29
+ 30, 31, 32, 33, 34, 35, 29, 30, 31, 32,
30
+ 33, 34, 35, 8, 7, 8, 7, 8, 7, 5,
31
+ 6, 5, 6, 5, 6, 8, 7, nil, nil, nil,
32
+ nil, 5, 6 ]
33
33
 
34
34
  racc_action_check = [
35
35
  24, 0, 0, 1, 2, 24, 5, 0, 0, 8,
36
36
  24, 9, 16, 19, 20, 21, 24, 24, 24, 24,
37
- 24, 24, 24, 24, 27, 23, 39, 3, 3, 27,
38
- nil, nil, 40, 3, 3, 27, nil, 40, nil, nil,
39
- 27, 27, 27, 27, 27, 27, 27, 27, 40, 40,
40
- 40, 40, 40, 40, 40, 40, 6, 6, 7, 7,
41
- 10, 10, 6, 6, 7, 7, 10, 10, 12, 12,
42
- nil, nil, nil, nil, 12, 12 ]
37
+ 24, 24, 24, 27, 23, 3, 3, 38, 27, nil,
38
+ 39, 3, 3, nil, 27, 39, nil, nil, nil, 27,
39
+ 27, 27, 27, 27, 27, 27, 39, 39, 39, 39,
40
+ 39, 39, 39, 6, 6, 7, 7, 10, 10, 6,
41
+ 6, 7, 7, 10, 10, 12, 12, nil, nil, nil,
42
+ nil, 12, 12 ]
43
43
 
44
44
  racc_action_pointer = [
45
- -2, 3, 2, 24, nil, -9, 53, 55, -2, 11,
46
- 57, nil, 65, nil, nil, nil, 6, nil, nil, -3,
47
- 2, -2, nil, 14, -3, nil, nil, 21, nil, nil,
48
- nil, nil, nil, nil, nil, nil, nil, nil, nil, 12,
49
- 29, nil, nil ]
45
+ -2, 3, 2, 22, nil, -9, 50, 52, -2, 11,
46
+ 54, nil, 62, nil, nil, nil, 6, nil, nil, -3,
47
+ 2, -2, nil, 13, -3, nil, nil, 20, nil, nil,
48
+ nil, nil, nil, nil, nil, nil, nil, nil, 13, 27,
49
+ nil, nil ]
50
50
 
51
51
  racc_action_default = [
52
- -28, -28, -2, -4, -5, -28, -28, -28, -9, -28,
53
- -28, -3, -28, -7, -8, -10, -28, 43, -1, -28,
54
- -28, -28, -6, -12, -28, -11, -13, -28, -18, -19,
55
- -20, -21, -22, -23, -24, -25, -26, -27, -14, -28,
56
- -17, -15, -16 ]
52
+ -27, -27, -2, -4, -5, -27, -27, -27, -9, -27,
53
+ -27, -3, -27, -7, -8, -10, -27, 42, -1, -27,
54
+ -27, -27, -6, -12, -27, -11, -13, -27, -18, -19,
55
+ -20, -21, -22, -23, -24, -25, -26, -14, -27, -17,
56
+ -15, -16 ]
57
57
 
58
58
  racc_goto_table = [
59
- 28, 39, 15, 28, 11, 1, 13, 14, 20, 26,
60
- nil, nil, 19, nil, 42, 18, 28, 25 ]
59
+ 28, 15, 38, 28, 13, 14, 11, 1, 20, 26,
60
+ 19, nil, nil, nil, 41, 28, 25, 18 ]
61
61
 
62
62
  racc_goto_check = [
63
- 4, 8, 5, 4, 2, 1, 3, 3, 6, 7,
64
- nil, nil, 3, nil, 8, 1, 4, 5 ]
63
+ 4, 5, 8, 4, 3, 3, 2, 1, 6, 7,
64
+ 3, nil, nil, nil, 8, 4, 5, 1 ]
65
65
 
66
66
  racc_goto_pointer = [
67
- nil, 5, 1, 0, -24, -6, -8, -15, -26 ]
67
+ nil, 7, 3, -2, -24, -7, -8, -15, -25 ]
68
68
 
69
69
  racc_goto_default = [
70
- nil, nil, 2, 3, 4, nil, nil, 40, nil ]
70
+ nil, nil, 2, 3, 4, nil, nil, 39, nil ]
71
71
 
72
72
  racc_reduce_table = [
73
73
  0, 0, :racc_error,
74
- 3, 28, :_reduce_1,
75
- 1, 28, :_reduce_2,
76
- 2, 29, :_reduce_3,
77
- 1, 29, :_reduce_4,
78
- 1, 30, :_reduce_5,
79
- 4, 30, :_reduce_6,
80
- 2, 30, :_reduce_7,
81
- 2, 30, :_reduce_8,
82
- 1, 31, :_reduce_9,
83
- 2, 31, :_reduce_10,
84
- 4, 32, :_reduce_11,
85
- 3, 32, :_reduce_12,
86
- 3, 33, :_reduce_13,
87
- 4, 33, :_reduce_14,
88
- 5, 33, :_reduce_15,
89
- 2, 35, :_reduce_16,
90
- 1, 35, :_reduce_17,
91
- 1, 34, :_reduce_none,
92
- 1, 34, :_reduce_19,
93
- 1, 34, :_reduce_20,
94
- 1, 34, :_reduce_21,
95
- 1, 34, :_reduce_22,
96
- 1, 34, :_reduce_23,
97
- 1, 34, :_reduce_24,
98
- 1, 34, :_reduce_25,
99
- 1, 34, :_reduce_26,
100
- 1, 34, :_reduce_27 ]
101
-
102
- racc_reduce_n = 28
103
-
104
- racc_shift_n = 43
74
+ 3, 27, :_reduce_1,
75
+ 1, 27, :_reduce_2,
76
+ 2, 28, :_reduce_3,
77
+ 1, 28, :_reduce_4,
78
+ 1, 29, :_reduce_5,
79
+ 4, 29, :_reduce_6,
80
+ 2, 29, :_reduce_7,
81
+ 2, 29, :_reduce_8,
82
+ 1, 30, :_reduce_9,
83
+ 2, 30, :_reduce_10,
84
+ 4, 31, :_reduce_11,
85
+ 3, 31, :_reduce_12,
86
+ 3, 32, :_reduce_13,
87
+ 4, 32, :_reduce_14,
88
+ 5, 32, :_reduce_15,
89
+ 2, 34, :_reduce_16,
90
+ 1, 34, :_reduce_17,
91
+ 1, 33, :_reduce_none,
92
+ 1, 33, :_reduce_19,
93
+ 1, 33, :_reduce_20,
94
+ 1, 33, :_reduce_21,
95
+ 1, 33, :_reduce_22,
96
+ 1, 33, :_reduce_23,
97
+ 1, 33, :_reduce_24,
98
+ 1, 33, :_reduce_25,
99
+ 1, 33, :_reduce_26 ]
100
+
101
+ racc_reduce_n = 27
102
+
103
+ racc_shift_n = 42
105
104
 
106
105
  racc_token_table = {
107
106
  false => 0,
@@ -123,16 +122,15 @@ racc_token_table = {
123
122
  :tCLOSE_SELECTOR => 16,
124
123
  :tOPERATOR => 17,
125
124
  :tARRAY_VALUE => 18,
126
- :tDYNAMIC_ATTRIBUTE => 19,
127
- :tBOOLEAN => 20,
128
- :tFLOAT => 21,
129
- :tINTEGER => 22,
130
- :tNIL => 23,
131
- :tREGEXP => 24,
132
- :tSTRING => 25,
133
- :tSYMBOL => 26 }
125
+ :tBOOLEAN => 19,
126
+ :tFLOAT => 20,
127
+ :tINTEGER => 21,
128
+ :tNIL => 22,
129
+ :tREGEXP => 23,
130
+ :tSTRING => 24,
131
+ :tSYMBOL => 25 }
134
132
 
135
- racc_nt_base = 27
133
+ racc_nt_base = 26
136
134
 
137
135
  racc_use_result_var = false
138
136
 
@@ -172,7 +170,6 @@ Racc_token_to_s_table = [
172
170
  "tCLOSE_SELECTOR",
173
171
  "tOPERATOR",
174
172
  "tARRAY_VALUE",
175
- "tDYNAMIC_ATTRIBUTE",
176
173
  "tBOOLEAN",
177
174
  "tFLOAT",
178
175
  "tINTEGER",
@@ -267,38 +264,34 @@ end
267
264
  # reduce 18 omitted
268
265
 
269
266
  def _reduce_19(val, _values)
270
- NodeQuery::Compiler::EvaluatedValue.new(value: val[0])
271
- end
272
-
273
- def _reduce_20(val, _values)
274
267
  NodeQuery::Compiler::Boolean.new(value: val[0])
275
268
  end
276
269
 
277
- def _reduce_21(val, _values)
270
+ def _reduce_20(val, _values)
278
271
  NodeQuery::Compiler::Float.new(value: val[0])
279
272
  end
280
273
 
281
- def _reduce_22(val, _values)
274
+ def _reduce_21(val, _values)
282
275
  NodeQuery::Compiler::Integer.new(value: val[0])
283
276
  end
284
277
 
285
- def _reduce_23(val, _values)
278
+ def _reduce_22(val, _values)
286
279
  NodeQuery::Compiler::Nil.new(value: val[0])
287
280
  end
288
281
 
289
- def _reduce_24(val, _values)
282
+ def _reduce_23(val, _values)
290
283
  NodeQuery::Compiler::Regexp.new(value: val[0])
291
284
  end
292
285
 
293
- def _reduce_25(val, _values)
286
+ def _reduce_24(val, _values)
294
287
  NodeQuery::Compiler::String.new(value: val[0])
295
288
  end
296
289
 
297
- def _reduce_26(val, _values)
290
+ def _reduce_25(val, _values)
298
291
  NodeQuery::Compiler::Symbol.new(value: val[0])
299
292
  end
300
293
 
301
- def _reduce_27(val, _values)
294
+ def _reduce_26(val, _values)
302
295
  NodeQuery::Compiler::Identifier.new(value: val[0])
303
296
  end
304
297
 
@@ -2,7 +2,7 @@ class NodeQueryParser
2
2
  options no_result_var
3
3
  token tCOMMA tNODE_TYPE tGOTO_SCOPE tATTRIBUTE tKEY tIDENTIFIER tIDENTIFIER_VALUE tPSEUDO_CLASS tRELATIONSHIP
4
4
  tOPEN_ATTRIBUTE tCLOSE_ATTRIBUTE tOPEN_ARRAY tCLOSE_ARRAY tOPEN_SELECTOR tCLOSE_SELECTOR
5
- tOPERATOR tARRAY_VALUE tDYNAMIC_ATTRIBUTE tBOOLEAN tFLOAT tINTEGER tNIL tREGEXP tSTRING tSYMBOL
5
+ tOPERATOR tARRAY_VALUE tBOOLEAN tFLOAT tINTEGER tNIL tREGEXP tSTRING tSYMBOL
6
6
  rule
7
7
  expression_list
8
8
  : expression tCOMMA expression_list { NodeQuery::Compiler::ExpressionList.new(expression: val[0], rest: val[2]) }
@@ -37,7 +37,6 @@ rule
37
37
 
38
38
  value
39
39
  : basic_selector
40
- | tDYNAMIC_ATTRIBUTE { NodeQuery::Compiler::EvaluatedValue.new(value: val[0]) }
41
40
  | tBOOLEAN { NodeQuery::Compiler::Boolean.new(value: val[0]) }
42
41
  | tFLOAT { NodeQuery::Compiler::Float.new(value: val[0]) }
43
42
  | tINTEGER { NodeQuery::Compiler::Integer.new(value: val[0])}
data/node_query.gemspec CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  # Uncomment to register a new dependency of your gem
32
- spec.add_dependency "activesupport"
32
+ spec.add_dependency "activesupport", "< 7.0.0"
33
33
 
34
34
  # For more information and examples about making a new gem, check out our
35
35
  # guide at: https://bundler.io/guides/creating_gem.html
data/sig/node_query.rbs CHANGED
@@ -5,7 +5,9 @@ class NodeQuery[T]
5
5
 
6
6
  def self.adapter: () -> NodeQuery::Adapter
7
7
 
8
- def initialize: (nql: String) -> NodeQuery
8
+ def initialize: (nqlOrRues: String | Hash) -> NodeQuery
9
9
 
10
- def parse: (node: T) -> Array[T]
10
+ def query_nodes: (node: T, including_self: boolean) -> Array[T]
11
+
12
+ def match_node?: (node: T) -> boolean
11
13
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: node_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.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-07-01 00:00:00.000000000 Z
11
+ date: 2022-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "<"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 7.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "<"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 7.0.0
27
27
  description: ast node query language
28
28
  email:
29
29
  - flyerhzm@gmail.com
@@ -47,7 +47,6 @@ files:
47
47
  - lib/node_query/compiler/basic_selector.rb
48
48
  - lib/node_query/compiler/boolean.rb
49
49
  - lib/node_query/compiler/comparable.rb
50
- - lib/node_query/compiler/evaluated_value.rb
51
50
  - lib/node_query/compiler/expression.rb
52
51
  - lib/node_query/compiler/expression_list.rb
53
52
  - lib/node_query/compiler/float.rb
@@ -61,6 +60,7 @@ files:
61
60
  - lib/node_query/compiler/string.rb
62
61
  - lib/node_query/compiler/symbol.rb
63
62
  - lib/node_query/helper.rb
63
+ - lib/node_query/node_rules.rb
64
64
  - lib/node_query/parser_adapter.rb
65
65
  - lib/node_query/version.rb
66
66
  - lib/node_query_lexer.rex
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module NodeQuery::Compiler
4
- # EvaluatedValue represents a ruby dynamic attribute.
5
- # e.g. code is <code>{ a: a }</code>, query is <code>'.hash > .pair[key={{value}}]'</code>,
6
- # <code>{{value}}</code> is the dynamic attribute.
7
- class EvaluatedValue
8
- include Comparable
9
-
10
- attr_accessor :base_node
11
-
12
- # Initialize an EvaluatedValue.
13
- # @param value [String] the dynamic attribute value
14
- def initialize(value:)
15
- @value = value
16
- end
17
-
18
- # Get the actual value of a node.
19
- # @param node [Node] the node
20
- # @return [String] if node is a {Node}, return the node source code, otherwise return the node itself.
21
- def actual_value(node)
22
- if node.is_a?(::Parser::AST::Node)
23
- NodeQuery.adapter.get_source(node)
24
- else
25
- node
26
- end
27
- end
28
-
29
- # Get the expected value.
30
- # @return [String] Query the node by @value from base_node, if the node is a {Node}, return the node source code, otherwise return the node itself.
31
- def expected_value
32
- node = NodeQuery::Helper.get_target_node(base_node, @value)
33
- if node.is_a?(::Parser::AST::Node)
34
- NodeQuery.adapter.get_source(node)
35
- else
36
- node
37
- end
38
- end
39
-
40
- # Get valid operators.
41
- # @return [Array] valid operators
42
- def valid_operators
43
- SIMPLE_VALID_OPERATORS
44
- end
45
-
46
- def to_s
47
- "{{#{@value}}}"
48
- end
49
- end
50
- end