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 +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +9 -3
- data/README.md +9 -8
- data/lib/node_query/{parser_adapter.rb → adapter/parser.rb} +3 -0
- data/lib/node_query/adapter/syntax_tree.rb +26 -0
- data/lib/node_query/version.rb +1 -1
- data/lib/node_query.rb +3 -2
- data/lib/node_query_lexer.rex +1 -1
- data/lib/node_query_lexer.rex.rb +1 -1
- data/lib/node_query_parser.racc.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f0ea7e92fbee3e2c0c28554dd021b1e2a07fd4c64b9dd7f1a6b5acbc7d8385f
|
4
|
+
data.tar.gz: cc317efc39dd07bc30c1cd54cd03eded67c82a92a37b809340add4c8372e77ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
node_query (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.
|
41
|
+
parser (3.2.2.1)
|
42
42
|
ast (~> 2.4.1)
|
43
|
-
parser_node_ext (1.
|
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
|
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 :
|
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
|
-
|
482
|
-
NodeQuery.configure(adapter: ParserAdapter.new)
|
483
|
-
```
|
481
|
+
It provides 2 adapters
|
484
482
|
|
485
|
-
|
483
|
+
1. `ParserAdapter`
|
484
|
+
2. `SyntaxTreeAdapter`
|
486
485
|
|
487
|
-
|
486
|
+
```ruby
|
487
|
+
NodeQuery.configure(adapter: SyntaxTreeAdapter.new) # default is ParserAdapter
|
488
|
+
```
|
488
489
|
|
489
490
|
## Development
|
490
491
|
|
@@ -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
|
data/lib/node_query/version.rb
CHANGED
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/
|
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
|
21
|
+
@adapter = options[:adapter]
|
21
22
|
end
|
22
23
|
|
23
24
|
# Get the adapter
|
data/lib/node_query_lexer.rex
CHANGED
data/lib/node_query_lexer.rex.rb
CHANGED
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.
|
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-
|
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
|