node_query 1.12.1 → 1.13.1

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: 35243974bb269cb011bc7fb7c4ca8877ef0338cd4cfb8dc80785a06e9b40ee6f
4
- data.tar.gz: ad100af634d93ddaa21bd37b89c3d0d542645007ee9bcd73c0f8fd28fe7211ae
3
+ metadata.gz: 9f0ea7e92fbee3e2c0c28554dd021b1e2a07fd4c64b9dd7f1a6b5acbc7d8385f
4
+ data.tar.gz: cc317efc39dd07bc30c1cd54cd03eded67c82a92a37b809340add4c8372e77ea
5
5
  SHA512:
6
- metadata.gz: 656a13c7124f155c6ed96c5d39a901edd248b4ee1d4b19b2d2205c2f244ba0057dec372087b5a4ba08c5d00e784ae5655a0fee1656befe3061df780e8edc9e7b
7
- data.tar.gz: e811b204f0cc9848b9c65a85295049e37e7f1bf2cb1897f79236093af95a941133962ae425d125c103e123da9019960d00ddf4c41850e868cf5fabd7c245f64a
6
+ metadata.gz: b7bb08d7bacc6da4232f7e16a9397e565ae4b4523b8d177068672441aecdcaa49a01be8b3e614aeef138e365ad210bd1e121857690061324f889e8486105c79a
7
+ data.tar.gz: 2736927c6b34ee327b02e4230bc4b8879f8582f8a9840740c99bd122a9d53eecd5c099dc2e3b2407629047a88e3477e253d878fe56e835264e38a405ede78bc2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.13.1 (2023-05-16)
4
+
5
+ * Require `parser` and `syntax_tree` in adapter
6
+ * `SyntaxTreeParser#get_node_type` returns a symbol
7
+ * Node type can be upcase
8
+
9
+ ## 1.13.0 (2023-05-15)
10
+
11
+ * Add `SyntaxTreeParser`
12
+
3
13
  ## 1.12.1 (2023-04-06)
4
14
 
5
15
  * 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.1)
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
 
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'parser'
4
+ require 'parser_node_ext'
5
+
3
6
  class NodeQuery::ParserAdapter
4
7
  def is_node?(node)
5
8
  node.is_a?(Parser::AST::Node)
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'syntax_tree'
4
+ require 'syntax_tree_ext'
5
+
6
+ class NodeQuery::SyntaxTreeAdapter
7
+ def is_node?(node)
8
+ node.is_a?(SyntaxTree::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.source
17
+ end
18
+
19
+ def get_children(node)
20
+ node.child_nodes
21
+ end
22
+
23
+ def get_siblings(node)
24
+ node.siblings
25
+ end
26
+ 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.1"
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"
@@ -17,7 +18,7 @@ class NodeQuery
17
18
  # @param [Hash] options options to configure
18
19
  # @option options [NodeQuery::Adapter] :adapter the adpater
19
20
  def self.configure(options)
20
- @adapter = options.adapter
21
+ @adapter = options[:adapter]
21
22
  end
22
23
 
23
24
  # Get the adapter
@@ -7,7 +7,7 @@ macros
7
7
  CLOSE_ARRAY /\)/
8
8
  OPEN_SELECTOR /\(/
9
9
  CLOSE_SELECTOR /\)/
10
- NODE_TYPE /\.[a-z]+/
10
+ NODE_TYPE /\.[a-zA-Z]+/
11
11
  IDENTIFIER /[@\*\-\.\w]*\w/
12
12
  IDENTIFIER_VALUE /[@\.\w!&:\?<>=]+/
13
13
  FALSE /false/
@@ -20,7 +20,7 @@ class NodeQueryLexer
20
20
  CLOSE_ARRAY = /\)/
21
21
  OPEN_SELECTOR = /\(/
22
22
  CLOSE_SELECTOR = /\)/
23
- NODE_TYPE = /\.[a-z]+/
23
+ NODE_TYPE = /\.[a-zA-Z]+/
24
24
  IDENTIFIER = /[@\*\-\.\w]*\w/
25
25
  IDENTIFIER_VALUE = /[@\.\w!&:\?<>=]+/
26
26
  FALSE = /false/
@@ -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.1
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