node_query 1.12.1 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +9 -3
- data/README.md +9 -8
- data/lib/node_query/adapter/syntax_tree.rb +23 -0
- data/lib/node_query/version.rb +1 -1
- data/lib/node_query.rb +2 -1
- data/lib/node_query_parser.racc.rb +1 -1
- metadata +4 -3
- /data/lib/node_query/{parser_adapter.rb → adapter/parser.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2e54cf10c098ebfaff54d05d36f482c2766b5308f4b8389b2b6a86c1bfb6363
|
4
|
+
data.tar.gz: 4d0b3f4ece89c3d4184c9b8159b924a2e321bafde7b598ee1789f17a41b73ee4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a0245239a1a6739dc8a9c51ddc507ddec1fba5e11820678d002af9572e4ed3e810b4ff4835bf6c6c36019e750f252da6a1fbbe08aa2abf00374d7010d6e7e36
|
7
|
+
data.tar.gz: e5ae500ad6d17776a1c2becc86f451fa7cc222e731a309dcb86be654930e1b3d038ad649319fa7805e03c4ea54320959898413bbde79a07dfeb09a50831a897d
|
data/CHANGELOG.md
CHANGED
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.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.
|
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,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
|
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"
|
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.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
|
+
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
|
File without changes
|