node_query 1.14.0 → 1.15.0

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: 3dfe6e9207a883cc7d7240f46bac3d4628443f9eb40bcd5af36802311ebad8ae
4
- data.tar.gz: 1d4dbd34cb794d95fc594f020fd07706e5babc85a38ea303a2c9ce4a31ed2f0a
3
+ metadata.gz: 9215c4354d5f17a61bd0703869547d2dc4eca4b074c5e689451034073c9554da
4
+ data.tar.gz: d602ad70ae5d1d8c53ea7192a1c401cbe67450ece27523fa4040e520e9b85558
5
5
  SHA512:
6
- metadata.gz: 70dc0235743a5191905c18633a633f620bdff6ffcd8bd4704b31d84ff724239e2e604e9999be9532022fa4d6b590bf3d2b886f468f0e4add83c4c1594f45ad58
7
- data.tar.gz: 3831937eb116d7e49812631488cc12bbbcf1c923212e810e35ca98a15590b6241c3659ed24909d36206a28176d2d7a721f1ec9e2d10556c6fea62f2889e0d104
6
+ metadata.gz: 4edce7905bb8b5835d0024f80d2e6a34e01602040c67250873e34d3ebd9c2396df5175608ffe1995048c36f681627b3570571a4f293fd35c9d93da76bb33c0aa
7
+ data.tar.gz: 9d812e03d9045f344a00a950dbc503ae185cb469844d3f62b98cb3db64659786552e9e46d2209ef809f6a189eae55b98c1a16bf9c2106d12f75519a24dc75d7f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.15.0 (2024-02-10)
4
+
5
+ * Support `prism`
6
+
7
+ ## 1.14.1 (2023-11-27)
8
+
9
+ * Fix `ArrayValue` with `adapter` parameter
10
+
3
11
  ## 1.14.0 (2023-11-27)
4
12
 
5
13
  * Add `adapter` parameter to `NodeQuery`
data/Gemfile CHANGED
@@ -14,6 +14,6 @@ gem "guard-rspec"
14
14
  gem "guard-rake"
15
15
  gem "oedipus_lex"
16
16
  gem "racc"
17
- gem "parser"
18
17
  gem "parser_node_ext"
19
18
  gem "syntax_tree_ext"
19
+ gem "prism_ext"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_query (1.14.0)
4
+ node_query (1.15.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -38,16 +38,19 @@ GEM
38
38
  nenv (~> 0.1)
39
39
  shellany (~> 0.0)
40
40
  oedipus_lex (2.6.0)
41
- parser (3.2.2.3)
41
+ parser (3.3.0.5)
42
42
  ast (~> 2.4.1)
43
43
  racc
44
- parser_node_ext (1.2.1)
44
+ parser_node_ext (1.2.2)
45
45
  parser
46
46
  prettier_print (1.2.1)
47
+ prism (0.22.0)
48
+ prism_ext (0.2.0)
49
+ prism
47
50
  pry (0.14.1)
48
51
  coderay (~> 1.1)
49
52
  method_source (~> 1.0)
50
- racc (1.6.2)
53
+ racc (1.7.3)
51
54
  rake (13.0.6)
52
55
  rb-fsevent (0.11.1)
53
56
  rb-inotify (0.10.1)
@@ -66,15 +69,16 @@ GEM
66
69
  rspec-support (~> 3.11.0)
67
70
  rspec-support (3.11.0)
68
71
  shellany (0.0.1)
69
- syntax_tree (6.1.1)
72
+ syntax_tree (6.2.0)
70
73
  prettier_print (>= 1.2.0)
71
- syntax_tree_ext (0.6.4)
74
+ syntax_tree_ext (0.7.0)
72
75
  syntax_tree
73
76
  thor (1.2.1)
74
77
 
75
78
  PLATFORMS
76
79
  x86_64-darwin-21
77
80
  x86_64-darwin-22
81
+ x86_64-darwin-23
78
82
  x86_64-linux
79
83
 
80
84
  DEPENDENCIES
@@ -83,8 +87,8 @@ DEPENDENCIES
83
87
  guard-rspec
84
88
  node_query!
85
89
  oedipus_lex
86
- parser
87
90
  parser_node_ext
91
+ prism_ext
88
92
  racc
89
93
  rake (~> 13.0)
90
94
  rspec (~> 3.0)
data/README.md CHANGED
@@ -258,7 +258,7 @@ It matches def node whose arguments are either id or name.
258
258
  .class .send
259
259
  ```
260
260
 
261
- It matches send node whose ansestor is class node.
261
+ It matches send node whose ancestor is class node.
262
262
 
263
263
  #### Child combinator
264
264
 
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'prism'
4
+ require 'prism_ext'
5
+
6
+ class NodeQuery::PrismAdapter
7
+ def is_node?(node)
8
+ node.is_a?(Prism::Node)
9
+ end
10
+
11
+ def get_node_type(node)
12
+ node.class.name.split('::').last.to_sym
13
+ end
14
+
15
+ def get_source(node)
16
+ node.slice
17
+ end
18
+
19
+ def get_children(node)
20
+ node.child_nodes
21
+ end
22
+
23
+ def get_siblings(node)
24
+ child_nodes = node.parent_node.child_nodes
25
+ if child_nodes.is_a?(Array) && child_nodes.size == 1 && child_nodes.first.is_a?(Array)
26
+ index = child_nodes.first.index(node)
27
+ return child_nodes.first[index + 1...]
28
+ end
29
+
30
+ index = child_nodes.index(node)
31
+ child_nodes[index + 1...]
32
+ end
33
+ end
@@ -29,6 +29,13 @@ class NodeQuery::SyntaxTreeAdapter
29
29
  end
30
30
 
31
31
  def get_siblings(node)
32
- node.siblings
32
+ child_nodes = node.parent_node.deconstruct_keys([]).except(:location, :comments).values
33
+ if child_nodes.is_a?(Array) && child_nodes.size == 1 && child_nodes.first.is_a?(Array)
34
+ index = child_nodes.first.index(node)
35
+ return child_nodes.first[index + 1...]
36
+ end
37
+
38
+ index = child_nodes.index(node)
39
+ child_nodes[index + 1...]
33
40
  end
34
41
  end
@@ -93,7 +93,7 @@ module NodeQuery::Compiler
93
93
  end
94
94
  end
95
95
  else
96
- NodeQuery.adapter.get_children(node).each do |child_node|
96
+ @adapter.get_children(node).each do |child_node|
97
97
  if match?(child_node, child_node)
98
98
  nodes << child_node
99
99
  break if options[:stop_at_first_match]
@@ -171,10 +171,10 @@ module NodeQuery::Compiler
171
171
  end
172
172
  end
173
173
  when '+'
174
- next_sibling = node.siblings.first
174
+ next_sibling = @adapter.get_siblings(node).first
175
175
  nodes << next_sibling if @rest.match?(next_sibling, next_sibling)
176
176
  when '~'
177
- node.siblings.each do |sibling_node|
177
+ @adapter.get_siblings(node).each do |sibling_node|
178
178
  nodes << sibling_node if @rest.match?(sibling_node, sibling_node)
179
179
  end
180
180
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeQuery
4
- VERSION = "1.14.0"
4
+ VERSION = "1.15.0"
5
5
  end
data/lib/node_query.rb CHANGED
@@ -11,6 +11,7 @@ class NodeQuery
11
11
  autoload :Adapter, "node_query/adapter"
12
12
  autoload :ParserAdapter, "node_query/adapter/parser"
13
13
  autoload :SyntaxTreeAdapter, "node_query/adapter/syntax_tree"
14
+ autoload :PrismAdapter, "node_query/adapter/prism"
14
15
  autoload :Compiler, "node_query/compiler"
15
16
  autoload :Helper, "node_query/helper"
16
17
  autoload :NodeRules, "node_query/node_rules"
@@ -254,7 +254,7 @@ def _reduce_14(val, _values)
254
254
  end
255
255
 
256
256
  def _reduce_15(val, _values)
257
- NodeQuery::Compiler::Attribute.new(key: val[1], value: NodeQuery::Compiler::ArrayValue.new, operator: val[2], adapter: @adapter)
257
+ NodeQuery::Compiler::Attribute.new(key: val[1], value: NodeQuery::Compiler::ArrayValue.new(adapter: @adapter), operator: val[2], adapter: @adapter)
258
258
  end
259
259
 
260
260
  def _reduce_16(val, _values)
@@ -29,7 +29,7 @@ rule
29
29
 
30
30
  attribute
31
31
  : tOPEN_ATTRIBUTE tKEY tOPERATOR value tCLOSE_ATTRIBUTE { NodeQuery::Compiler::Attribute.new(key: val[1], value: val[3], operator: val[2], adapter: @adapter) }
32
- | tOPEN_ATTRIBUTE tKEY tOPERATOR tOPEN_ARRAY tCLOSE_ARRAY tCLOSE_ATTRIBUTE { NodeQuery::Compiler::Attribute.new(key: val[1], value: NodeQuery::Compiler::ArrayValue.new, operator: val[2], adapter: @adapter) }
32
+ | tOPEN_ATTRIBUTE tKEY tOPERATOR tOPEN_ARRAY tCLOSE_ARRAY tCLOSE_ATTRIBUTE { NodeQuery::Compiler::Attribute.new(key: val[1], value: NodeQuery::Compiler::ArrayValue.new(adapter: @adapter), operator: val[2], adapter: @adapter) }
33
33
  | tOPEN_ATTRIBUTE tKEY tOPERATOR tOPEN_ARRAY array_value tCLOSE_ARRAY tCLOSE_ATTRIBUTE { NodeQuery::Compiler::Attribute.new(key: val[1], value: val[4], operator: val[2], adapter: @adapter) }
34
34
 
35
35
  array_value
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.14.0
4
+ version: 1.15.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: 2023-11-27 00:00:00.000000000 Z
11
+ date: 2024-02-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ast node query language
14
14
  email:
@@ -27,6 +27,7 @@ files:
27
27
  - lib/node_query.rb
28
28
  - lib/node_query/adapter.rb
29
29
  - lib/node_query/adapter/parser.rb
30
+ - lib/node_query/adapter/prism.rb
30
31
  - lib/node_query/adapter/syntax_tree.rb
31
32
  - lib/node_query/compiler.rb
32
33
  - lib/node_query/compiler/array_value.rb
@@ -78,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
79
  - !ruby/object:Gem::Version
79
80
  version: '0'
80
81
  requirements: []
81
- rubygems_version: 3.4.20
82
+ rubygems_version: 3.5.3
82
83
  signing_key:
83
84
  specification_version: 4
84
85
  summary: ast node query language