node_query 1.12.1 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35243974bb269cb011bc7fb7c4ca8877ef0338cd4cfb8dc80785a06e9b40ee6f
4
- data.tar.gz: ad100af634d93ddaa21bd37b89c3d0d542645007ee9bcd73c0f8fd28fe7211ae
3
+ metadata.gz: a2e54cf10c098ebfaff54d05d36f482c2766b5308f4b8389b2b6a86c1bfb6363
4
+ data.tar.gz: 4d0b3f4ece89c3d4184c9b8159b924a2e321bafde7b598ee1789f17a41b73ee4
5
5
  SHA512:
6
- metadata.gz: 656a13c7124f155c6ed96c5d39a901edd248b4ee1d4b19b2d2205c2f244ba0057dec372087b5a4ba08c5d00e784ae5655a0fee1656befe3061df780e8edc9e7b
7
- data.tar.gz: e811b204f0cc9848b9c65a85295049e37e7f1bf2cb1897f79236093af95a941133962ae425d125c103e123da9019960d00ddf4c41850e868cf5fabd7c245f64a
6
+ metadata.gz: 0a0245239a1a6739dc8a9c51ddc507ddec1fba5e11820678d002af9572e4ed3e810b4ff4835bf6c6c36019e750f252da6a1fbbe08aa2abf00374d7010d6e7e36
7
+ data.tar.gz: e5ae500ad6d17776a1c2becc86f451fa7cc222e731a309dcb86be654930e1b3d038ad649319fa7805e03c4ea54320959898413bbde79a07dfeb09a50831a897d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.13.0 (2023-05-15)
4
+
5
+ * Add `SyntaxTreeParser`
6
+
3
7
  ## 1.12.1 (2023-04-06)
4
8
 
5
9
  * Fix when `actual` is nil
data/Gemfile CHANGED
@@ -16,3 +16,4 @@ gem "oedipus_lex"
16
16
  gem "racc"
17
17
  gem "parser"
18
18
  gem "parser_node_ext"
19
+ gem "syntax_tree_ext"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_query (1.12.1)
4
+ node_query (1.13.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -38,10 +38,11 @@ GEM
38
38
  nenv (~> 0.1)
39
39
  shellany (~> 0.0)
40
40
  oedipus_lex (2.6.0)
41
- parser (3.2.1.1)
41
+ parser (3.2.2.1)
42
42
  ast (~> 2.4.1)
43
- parser_node_ext (1.0.0)
43
+ parser_node_ext (1.1.0)
44
44
  parser
45
+ prettier_print (1.2.1)
45
46
  pry (0.14.1)
46
47
  coderay (~> 1.1)
47
48
  method_source (~> 1.0)
@@ -64,6 +65,10 @@ GEM
64
65
  rspec-support (~> 3.11.0)
65
66
  rspec-support (3.11.0)
66
67
  shellany (0.0.1)
68
+ syntax_tree (6.1.1)
69
+ prettier_print (>= 1.2.0)
70
+ syntax_tree_ext (0.3.0)
71
+ syntax_tree
67
72
  thor (1.2.1)
68
73
 
69
74
  PLATFORMS
@@ -82,6 +87,7 @@ DEPENDENCIES
82
87
  racc
83
88
  rake (~> 13.0)
84
89
  rspec (~> 3.0)
90
+ syntax_tree_ext
85
91
 
86
92
  BUNDLED WITH
87
93
  2.3.7
data/README.md CHANGED
@@ -17,14 +17,14 @@ NodeQuery defines a NQL (node query language) and node rules to query AST nodes.
17
17
  - [nql matches method result](#nql-matches-method-result)
18
18
  - [nql matches operators](#nql-matches-operators)
19
19
  - [nql matches array node attribute](#nql-matches-array-node-attribute)
20
- - [nql matches * in attribute key](#nql-matches--in-attribute-key)
20
+ - [nql matches \* in attribute key](#nql-matches--in-attribute-key)
21
21
  - [nql matches multiple selectors](#nql-matches-multiple-selectors)
22
22
  - [Descendant combinator](#descendant-combinator)
23
23
  - [Child combinator](#child-combinator)
24
24
  - [Adjacent sibling combinator](#adjacent-sibling-combinator)
25
25
  - [General sibling combinator](#general-sibling-combinator)
26
26
  - [nql matches goto scope](#nql-matches-goto-scope)
27
- - [nql matches :has and :not_has pseudo selector](#nql-matches-has-and-not_has-pseudo-selector)
27
+ - [nql matches :has and :not\_has pseudo selector](#nql-matches-has-and-not_has-pseudo-selector)
28
28
  - [nql matches :first-child and :last-child pseudo selector](#nql-matches-first-child-and-last-child-pseudo-selector)
29
29
  - [nql matches multiple expressions](#nql-matches-multiple-expressions)
30
30
  - [Node Rules](#node-rules)
@@ -474,17 +474,18 @@ It matches def node whose arguments are id and name.
474
474
 
475
475
  ## Write Adapter
476
476
 
477
- Different parser, like parser, will generate different AST nodes, to make NodeQuery work for them all,
477
+ Different parser, like parser, syntax_tree, will generate different AST nodes, to make NodeQuery work for them all,
478
478
  we define an [Adapter](https://github.com/xinminlabs/node-query-ruby/blob/main/lib/node_query/adapter.rb) interface,
479
479
  if you implement the Adapter interface, you can set it as NodeQuery's adapter.
480
480
 
481
- ```ruby
482
- NodeQuery.configure(adapter: ParserAdapter.new)
483
- ```
481
+ It provides 2 adapters
484
482
 
485
- Here is the ParserAdapter implementation:
483
+ 1. `ParserAdapter`
484
+ 2. `SyntaxTreeAdapter`
486
485
 
487
- [ParserAdapter](https://github.com/xinminlabs/node-query-ruby/blob/main/lib/node_query/parser_adapter.rb)
486
+ ```ruby
487
+ NodeQuery.configure(adapter: SyntaxTreeAdapter.new) # default is ParserAdapter
488
+ ```
488
489
 
489
490
  ## Development
490
491
 
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ class NodeQuery::SyntaxTreeAdapter
4
+ def is_node?(node)
5
+ node.is_a?(SyntaxTree::Node)
6
+ end
7
+
8
+ def get_node_type(node)
9
+ node.class.name.split('::').last
10
+ end
11
+
12
+ def get_source(node)
13
+ node.source
14
+ end
15
+
16
+ def get_children(node)
17
+ node.child_nodes
18
+ end
19
+
20
+ def get_siblings(node)
21
+ node.siblings
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeQuery
4
- VERSION = "1.12.1"
4
+ VERSION = "1.13.0"
5
5
  end
data/lib/node_query.rb CHANGED
@@ -8,7 +8,8 @@ class NodeQuery
8
8
  class MethodNotSupported < StandardError; end
9
9
 
10
10
  autoload :Adapter, "node_query/adapter"
11
- autoload :ParserAdapter, "node_query/parser_adapter"
11
+ autoload :ParserAdapter, "node_query/adapter/parser"
12
+ autoload :SyntaxTreeAdapter, "node_query/adapter/syntax_tree"
12
13
  autoload :Compiler, "node_query/compiler"
13
14
  autoload :Helper, "node_query/helper"
14
15
  autoload :NodeRules, "node_query/node_rules"
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # DO NOT MODIFY!!!!
3
- # This file is automatically generated by Racc 1.6.0
3
+ # This file is automatically generated by Racc 1.6.2
4
4
  # from Racc grammar file "".
5
5
  #
6
6
 
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.12.1
4
+ version: 1.13.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-04-05 00:00:00.000000000 Z
11
+ date: 2023-05-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ast node query language
14
14
  email:
@@ -26,6 +26,8 @@ files:
26
26
  - Rakefile
27
27
  - lib/node_query.rb
28
28
  - lib/node_query/adapter.rb
29
+ - lib/node_query/adapter/parser.rb
30
+ - lib/node_query/adapter/syntax_tree.rb
29
31
  - lib/node_query/compiler.rb
30
32
  - lib/node_query/compiler/array_value.rb
31
33
  - lib/node_query/compiler/attribute.rb
@@ -47,7 +49,6 @@ files:
47
49
  - lib/node_query/compiler/symbol.rb
48
50
  - lib/node_query/helper.rb
49
51
  - lib/node_query/node_rules.rb
50
- - lib/node_query/parser_adapter.rb
51
52
  - lib/node_query/version.rb
52
53
  - lib/node_query_lexer.rex
53
54
  - lib/node_query_lexer.rex.rb