rbtr-lang-tree-sitter-query 2026.9.0.dev1__tar.gz
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.
- rbtr_lang_tree_sitter_query-2026.9.0.dev1/LICENSE +21 -0
- rbtr_lang_tree_sitter_query-2026.9.0.dev1/PKG-INFO +60 -0
- rbtr_lang_tree_sitter_query-2026.9.0.dev1/README.md +34 -0
- rbtr_lang_tree_sitter_query-2026.9.0.dev1/pyproject.toml +57 -0
- rbtr_lang_tree_sitter_query-2026.9.0.dev1/pyproject.toml.orig +61 -0
- rbtr_lang_tree_sitter_query-2026.9.0.dev1/src/rbtr_lang_tree_sitter_query/__init__.py +1 -0
- rbtr_lang_tree_sitter_query-2026.9.0.dev1/src/rbtr_lang_tree_sitter_query/plugin.py +35 -0
- rbtr_lang_tree_sitter_query-2026.9.0.dev1/src/rbtr_lang_tree_sitter_query/py.typed +0 -0
- rbtr_lang_tree_sitter_query-2026.9.0.dev1/src/rbtr_lang_tree_sitter_query/tests/__init__.py +0 -0
- rbtr_lang_tree_sitter_query-2026.9.0.dev1/src/rbtr_lang_tree_sitter_query/tests/__snapshots__/test_samples/test_edges_match_snapshot.json +1 -0
- rbtr_lang_tree_sitter_query-2026.9.0.dev1/src/rbtr_lang_tree_sitter_query/tests/__snapshots__/test_samples/test_extraction_matches_snapshot.json +230 -0
- rbtr_lang_tree_sitter_query-2026.9.0.dev1/src/rbtr_lang_tree_sitter_query/tests/samples/tree_sitter_query/highlights.scm +39 -0
- rbtr_lang_tree_sitter_query-2026.9.0.dev1/src/rbtr_lang_tree_sitter_query/tests/test_samples.py +68 -0
- rbtr_lang_tree_sitter_query-2026.9.0.dev1/src/rbtr_lang_tree_sitter_query/tree_sitter_query.scm +14 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alejandro Giacometti
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rbtr-lang-tree-sitter-query
|
|
3
|
+
Version: 2026.9.0.dev1
|
|
4
|
+
Summary: rbtr — tree-sitter query (.scm) language plugin
|
|
5
|
+
Keywords: code-search,code-index,tree-sitter,static-analysis,semantic-search,developer-tools,tree-sitter-query
|
|
6
|
+
Author: Alejandro Giacometti
|
|
7
|
+
Author-email: Alejandro Giacometti <alejandro.giacometti@gmail.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
15
|
+
Classifier: Topic :: Text Processing :: Indexing
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Dist: rbtr==2026.9.0.dev1
|
|
18
|
+
Requires-Dist: tree-sitter-query
|
|
19
|
+
Requires-Python: >=3.13
|
|
20
|
+
Project-URL: Homepage, https://github.com/janrito/rbtr
|
|
21
|
+
Project-URL: Repository, https://github.com/janrito/rbtr
|
|
22
|
+
Project-URL: Documentation, https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-tree-sitter-query#readme
|
|
23
|
+
Project-URL: Issues, https://github.com/janrito/rbtr/issues
|
|
24
|
+
Project-URL: Changelog, https://github.com/janrito/rbtr/releases
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# rbtr-lang-tree-sitter-query
|
|
28
|
+
|
|
29
|
+
tree-sitter query (`.scm`) support for [rbtr]. Optional plugin —
|
|
30
|
+
install with `pip install rbtr[tree_sitter_query]`.
|
|
31
|
+
|
|
32
|
+
[rbtr]: https://github.com/janrito/rbtr/tree/main/packages/rbtr#readme
|
|
33
|
+
|
|
34
|
+
## What it ingests
|
|
35
|
+
|
|
36
|
+
`.scm` files — the tree-sitter query language rbtr's own plugins are written
|
|
37
|
+
in, and which third-party grammars ship too (`tags.scm`, `highlights.scm`,
|
|
38
|
+
`injections.scm`), so cloned repos are covered. Each top-level pattern becomes
|
|
39
|
+
a **doc-section** chunk, named by its own outer capture where the author gave
|
|
40
|
+
one. Patterns with no outer label are anonymous sections whose nested captures
|
|
41
|
+
stay full-text-searchable.
|
|
42
|
+
|
|
43
|
+
## Chunks produced
|
|
44
|
+
|
|
45
|
+
```scm
|
|
46
|
+
; doc_section "function"
|
|
47
|
+
(function_definition name: (identifier) @_fn_name) @function
|
|
48
|
+
|
|
49
|
+
; doc_section "keyword"
|
|
50
|
+
["if" "else"] @keyword
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Embedded / injected chunks
|
|
54
|
+
|
|
55
|
+
None. Query files do not embed other languages.
|
|
56
|
+
|
|
57
|
+
## Grammar & dependencies
|
|
58
|
+
|
|
59
|
+
Uses the `tree-sitter-query` grammar (`.scm`). No dependency on other language
|
|
60
|
+
plugins.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# rbtr-lang-tree-sitter-query
|
|
2
|
+
|
|
3
|
+
tree-sitter query (`.scm`) support for [rbtr]. Optional plugin —
|
|
4
|
+
install with `pip install rbtr[tree_sitter_query]`.
|
|
5
|
+
|
|
6
|
+
[rbtr]: https://github.com/janrito/rbtr/tree/main/packages/rbtr#readme
|
|
7
|
+
|
|
8
|
+
## What it ingests
|
|
9
|
+
|
|
10
|
+
`.scm` files — the tree-sitter query language rbtr's own plugins are written
|
|
11
|
+
in, and which third-party grammars ship too (`tags.scm`, `highlights.scm`,
|
|
12
|
+
`injections.scm`), so cloned repos are covered. Each top-level pattern becomes
|
|
13
|
+
a **doc-section** chunk, named by its own outer capture where the author gave
|
|
14
|
+
one. Patterns with no outer label are anonymous sections whose nested captures
|
|
15
|
+
stay full-text-searchable.
|
|
16
|
+
|
|
17
|
+
## Chunks produced
|
|
18
|
+
|
|
19
|
+
```scm
|
|
20
|
+
; doc_section "function"
|
|
21
|
+
(function_definition name: (identifier) @_fn_name) @function
|
|
22
|
+
|
|
23
|
+
; doc_section "keyword"
|
|
24
|
+
["if" "else"] @keyword
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Embedded / injected chunks
|
|
28
|
+
|
|
29
|
+
None. Query files do not embed other languages.
|
|
30
|
+
|
|
31
|
+
## Grammar & dependencies
|
|
32
|
+
|
|
33
|
+
Uses the `tree-sitter-query` grammar (`.scm`). No dependency on other language
|
|
34
|
+
plugins.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.11.26,<1"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[tool.uv.build-backend]
|
|
6
|
+
module-name = "rbtr_lang_tree_sitter_query"
|
|
7
|
+
|
|
8
|
+
[tool.uv.sources.rbtr]
|
|
9
|
+
workspace = true
|
|
10
|
+
|
|
11
|
+
[project]
|
|
12
|
+
name = "rbtr-lang-tree-sitter-query"
|
|
13
|
+
version = "2026.9.0-dev1"
|
|
14
|
+
description = "rbtr — tree-sitter query (.scm) language plugin"
|
|
15
|
+
readme = "README.md"
|
|
16
|
+
license = "MIT"
|
|
17
|
+
license-files = ["LICENSE"]
|
|
18
|
+
keywords = [
|
|
19
|
+
"code-search",
|
|
20
|
+
"code-index",
|
|
21
|
+
"tree-sitter",
|
|
22
|
+
"static-analysis",
|
|
23
|
+
"semantic-search",
|
|
24
|
+
"developer-tools",
|
|
25
|
+
"tree-sitter-query",
|
|
26
|
+
]
|
|
27
|
+
classifiers = [
|
|
28
|
+
"Development Status :: 4 - Beta",
|
|
29
|
+
"Intended Audience :: Developers",
|
|
30
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
31
|
+
"Programming Language :: Python :: 3.13",
|
|
32
|
+
"Topic :: Software Development :: Libraries",
|
|
33
|
+
"Topic :: Text Processing :: Indexing",
|
|
34
|
+
"Typing :: Typed",
|
|
35
|
+
]
|
|
36
|
+
requires-python = ">=3.13"
|
|
37
|
+
dependencies = [
|
|
38
|
+
"rbtr==2026.9.0-dev1",
|
|
39
|
+
"tree-sitter-query",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[[project.authors]]
|
|
43
|
+
name = "Alejandro Giacometti"
|
|
44
|
+
email = "alejandro.giacometti@gmail.com"
|
|
45
|
+
|
|
46
|
+
[project.urls]
|
|
47
|
+
Homepage = "https://github.com/janrito/rbtr"
|
|
48
|
+
Repository = "https://github.com/janrito/rbtr"
|
|
49
|
+
Documentation = "https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-tree-sitter-query#readme"
|
|
50
|
+
Issues = "https://github.com/janrito/rbtr/issues"
|
|
51
|
+
Changelog = "https://github.com/janrito/rbtr/releases"
|
|
52
|
+
|
|
53
|
+
[project.entry-points."rbtr.languages"]
|
|
54
|
+
tree_sitter_query = "rbtr_lang_tree_sitter_query.plugin:tree_sitter_query"
|
|
55
|
+
|
|
56
|
+
[dependency-groups]
|
|
57
|
+
dev = ["rbtr[test]"]
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.11.26,<1"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[tool.uv.build-backend]
|
|
6
|
+
module-name = "rbtr_lang_tree_sitter_query"
|
|
7
|
+
# No source-exclude: the plugin's tests, samples, and snapshots ship with
|
|
8
|
+
# the wheel (they are the language's golden record), and tree_sitter_query.scm
|
|
9
|
+
# ships as package data.
|
|
10
|
+
|
|
11
|
+
[project]
|
|
12
|
+
name = "rbtr-lang-tree-sitter-query"
|
|
13
|
+
version = "2026.9.0-dev1"
|
|
14
|
+
description = "rbtr — tree-sitter query (.scm) language plugin"
|
|
15
|
+
readme = "README.md"
|
|
16
|
+
license = "MIT"
|
|
17
|
+
license-files = ["LICENSE"]
|
|
18
|
+
authors = [
|
|
19
|
+
{ name = "Alejandro Giacometti", email = "alejandro.giacometti@gmail.com" },
|
|
20
|
+
]
|
|
21
|
+
keywords = [
|
|
22
|
+
"code-search",
|
|
23
|
+
"code-index",
|
|
24
|
+
"tree-sitter",
|
|
25
|
+
"static-analysis",
|
|
26
|
+
"semantic-search",
|
|
27
|
+
"developer-tools",
|
|
28
|
+
"tree-sitter-query",
|
|
29
|
+
]
|
|
30
|
+
classifiers = [
|
|
31
|
+
"Development Status :: 4 - Beta",
|
|
32
|
+
"Intended Audience :: Developers",
|
|
33
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
34
|
+
"Programming Language :: Python :: 3.13",
|
|
35
|
+
"Topic :: Software Development :: Libraries",
|
|
36
|
+
"Topic :: Text Processing :: Indexing",
|
|
37
|
+
"Typing :: Typed",
|
|
38
|
+
]
|
|
39
|
+
requires-python = ">=3.13"
|
|
40
|
+
dependencies = [
|
|
41
|
+
"rbtr==2026.9.0-dev1",
|
|
42
|
+
"tree-sitter-query",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[project.urls]
|
|
46
|
+
Homepage = "https://github.com/janrito/rbtr"
|
|
47
|
+
Repository = "https://github.com/janrito/rbtr"
|
|
48
|
+
Documentation = "https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-tree-sitter-query#readme"
|
|
49
|
+
Issues = "https://github.com/janrito/rbtr/issues"
|
|
50
|
+
Changelog = "https://github.com/janrito/rbtr/releases"
|
|
51
|
+
|
|
52
|
+
[project.entry-points."rbtr.languages"]
|
|
53
|
+
# The value resolves to the language's `LanguageRegistration` (named by its
|
|
54
|
+
# id) — see the rbtr ARCHITECTURE "External plugins" note.
|
|
55
|
+
tree_sitter_query = "rbtr_lang_tree_sitter_query.plugin:tree_sitter_query"
|
|
56
|
+
|
|
57
|
+
[tool.uv.sources]
|
|
58
|
+
rbtr = { workspace = true }
|
|
59
|
+
|
|
60
|
+
[dependency-groups]
|
|
61
|
+
dev = ["rbtr[test]"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""tree-sitter query language plugin package."""
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""tree-sitter query language plugin.
|
|
2
|
+
|
|
3
|
+
Indexes `.scm` files — the tree-sitter query language that rbtr's own
|
|
4
|
+
language plugins are written in (see the `.scm` files beside each
|
|
5
|
+
`plugin.py`). Third-party grammars ship `.scm` too (`tags.scm`,
|
|
6
|
+
`highlights.scm`, `injections.scm`), so cloned repos are covered as well.
|
|
7
|
+
|
|
8
|
+
Each top-level pattern becomes a `doc_section` chunk, named by its own
|
|
9
|
+
outer capture where the author gave one (`tree_sitter_query.scm` pairs
|
|
10
|
+
it as `@_section_name`):
|
|
11
|
+
|
|
12
|
+
(function_definition name: (identifier) @_fn_name) @function
|
|
13
|
+
→ section "function"
|
|
14
|
+
|
|
15
|
+
["if" "else"] @keyword
|
|
16
|
+
→ section "keyword"
|
|
17
|
+
|
|
18
|
+
Patterns with no outer label of their own — a predicate-wrapped injection
|
|
19
|
+
rule, or one anchored at a structural wrapper — are anonymous sections;
|
|
20
|
+
their nested captures stay full-text-searchable.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
from rbtr.languages.registration import LanguageRegistration, QueryExtraction, load_query
|
|
26
|
+
|
|
27
|
+
tree_sitter_query = LanguageRegistration(
|
|
28
|
+
id="tree_sitter_query",
|
|
29
|
+
extensions=frozenset({".scm"}),
|
|
30
|
+
grammar_module="tree_sitter_query",
|
|
31
|
+
extraction=QueryExtraction(
|
|
32
|
+
query=load_query(__package__, "tree_sitter_query"),
|
|
33
|
+
),
|
|
34
|
+
extraction_serial=2,
|
|
35
|
+
)
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"blob_sha": "sha1",
|
|
4
|
+
"file_path": "highlights.scm",
|
|
5
|
+
"kind": "comment",
|
|
6
|
+
"name": "",
|
|
7
|
+
"scope": "",
|
|
8
|
+
"language": "tree_sitter_query",
|
|
9
|
+
"file_language": "tree_sitter_query",
|
|
10
|
+
"content": "; A tree-sitter query file exercising every construct rbtr should index:\n; named nodes with fields, anonymous nodes, alternation lists, groupings,\n; predicates, wildcards, negated fields, anchors, quantifiers, supertypes,\n; and a MISSING-node pattern. Every top-level pattern is one doc section.",
|
|
11
|
+
"line_start": 1,
|
|
12
|
+
"line_end": 4,
|
|
13
|
+
"metadata": {
|
|
14
|
+
"module": "",
|
|
15
|
+
"names": "",
|
|
16
|
+
"dots": "",
|
|
17
|
+
"language_hint": ""
|
|
18
|
+
},
|
|
19
|
+
"id": "91411c21fd288abd"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"blob_sha": "sha1",
|
|
23
|
+
"file_path": "highlights.scm",
|
|
24
|
+
"kind": "doc_section",
|
|
25
|
+
"name": "definition.function",
|
|
26
|
+
"scope": "",
|
|
27
|
+
"language": "tree_sitter_query",
|
|
28
|
+
"file_language": "tree_sitter_query",
|
|
29
|
+
"content": "; Named-node patterns with a field and an outer definition capture.\n(function_definition\n name: (identifier) @function\n body: (_) @_body) @definition.function",
|
|
30
|
+
"line_start": 6,
|
|
31
|
+
"line_end": 9,
|
|
32
|
+
"metadata": {
|
|
33
|
+
"module": "",
|
|
34
|
+
"names": "",
|
|
35
|
+
"dots": "",
|
|
36
|
+
"language_hint": ""
|
|
37
|
+
},
|
|
38
|
+
"id": "22635e30fc3ec0ec"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"blob_sha": "sha1",
|
|
42
|
+
"file_path": "highlights.scm",
|
|
43
|
+
"kind": "doc_section",
|
|
44
|
+
"name": "definition.class",
|
|
45
|
+
"scope": "",
|
|
46
|
+
"language": "tree_sitter_query",
|
|
47
|
+
"file_language": "tree_sitter_query",
|
|
48
|
+
"content": "(class_definition\n name: (identifier) @type) @definition.class",
|
|
49
|
+
"line_start": 11,
|
|
50
|
+
"line_end": 12,
|
|
51
|
+
"metadata": {
|
|
52
|
+
"module": "",
|
|
53
|
+
"names": "",
|
|
54
|
+
"dots": "",
|
|
55
|
+
"language_hint": ""
|
|
56
|
+
},
|
|
57
|
+
"id": "2f7ccba614073350"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"blob_sha": "sha1",
|
|
61
|
+
"file_path": "highlights.scm",
|
|
62
|
+
"kind": "doc_section",
|
|
63
|
+
"name": "keyword",
|
|
64
|
+
"scope": "",
|
|
65
|
+
"language": "tree_sitter_query",
|
|
66
|
+
"file_language": "tree_sitter_query",
|
|
67
|
+
"content": "; Alternation list and a bare anonymous-node matcher.\n[\"if\" \"else\" \"while\" \"return\"] @keyword",
|
|
68
|
+
"line_start": 14,
|
|
69
|
+
"line_end": 15,
|
|
70
|
+
"metadata": {
|
|
71
|
+
"module": "",
|
|
72
|
+
"names": "",
|
|
73
|
+
"dots": "",
|
|
74
|
+
"language_hint": ""
|
|
75
|
+
},
|
|
76
|
+
"id": "68190efc87150b38"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"blob_sha": "sha1",
|
|
80
|
+
"file_path": "highlights.scm",
|
|
81
|
+
"kind": "doc_section",
|
|
82
|
+
"name": "keyword.coroutine",
|
|
83
|
+
"scope": "",
|
|
84
|
+
"language": "tree_sitter_query",
|
|
85
|
+
"file_language": "tree_sitter_query",
|
|
86
|
+
"content": "\"async\" @keyword.coroutine",
|
|
87
|
+
"line_start": 17,
|
|
88
|
+
"line_end": 17,
|
|
89
|
+
"metadata": {
|
|
90
|
+
"module": "",
|
|
91
|
+
"names": "",
|
|
92
|
+
"dots": "",
|
|
93
|
+
"language_hint": ""
|
|
94
|
+
},
|
|
95
|
+
"id": "4587431c020385fb"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"blob_sha": "sha1",
|
|
99
|
+
"file_path": "highlights.scm",
|
|
100
|
+
"kind": "doc_section",
|
|
101
|
+
"name": "",
|
|
102
|
+
"scope": "",
|
|
103
|
+
"language": "tree_sitter_query",
|
|
104
|
+
"file_language": "tree_sitter_query",
|
|
105
|
+
"content": "; Wildcard child, a negated field, anchors, and quantifiers.\n(call_expression\n function: (_) @call\n !type_arguments)",
|
|
106
|
+
"line_start": 19,
|
|
107
|
+
"line_end": 22,
|
|
108
|
+
"metadata": {
|
|
109
|
+
"module": "",
|
|
110
|
+
"names": "",
|
|
111
|
+
"dots": "",
|
|
112
|
+
"language_hint": ""
|
|
113
|
+
},
|
|
114
|
+
"id": "efd9cbebd9a590b9"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"blob_sha": "sha1",
|
|
118
|
+
"file_path": "highlights.scm",
|
|
119
|
+
"kind": "doc_section",
|
|
120
|
+
"name": "",
|
|
121
|
+
"scope": "",
|
|
122
|
+
"language": "tree_sitter_query",
|
|
123
|
+
"file_language": "tree_sitter_query",
|
|
124
|
+
"content": "(array . (identifier) @first (_)* @rest)",
|
|
125
|
+
"line_start": 24,
|
|
126
|
+
"line_end": 24,
|
|
127
|
+
"metadata": {
|
|
128
|
+
"module": "",
|
|
129
|
+
"names": "",
|
|
130
|
+
"dots": "",
|
|
131
|
+
"language_hint": ""
|
|
132
|
+
},
|
|
133
|
+
"id": "7d959afd205ade46"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"blob_sha": "sha1",
|
|
137
|
+
"file_path": "highlights.scm",
|
|
138
|
+
"kind": "doc_section",
|
|
139
|
+
"name": "",
|
|
140
|
+
"scope": "",
|
|
141
|
+
"language": "tree_sitter_query",
|
|
142
|
+
"file_language": "tree_sitter_query",
|
|
143
|
+
"content": "; Groupings with predicates: regex match, alternation, and an injection.\n((identifier) @constant\n (#match? @constant \"^[A-Z][A-Z_]+$\"))",
|
|
144
|
+
"line_start": 26,
|
|
145
|
+
"line_end": 28,
|
|
146
|
+
"metadata": {
|
|
147
|
+
"module": "",
|
|
148
|
+
"names": "",
|
|
149
|
+
"dots": "",
|
|
150
|
+
"language_hint": ""
|
|
151
|
+
},
|
|
152
|
+
"id": "0ef0b2c93e4c6519"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"blob_sha": "sha1",
|
|
156
|
+
"file_path": "highlights.scm",
|
|
157
|
+
"kind": "doc_section",
|
|
158
|
+
"name": "",
|
|
159
|
+
"scope": "",
|
|
160
|
+
"language": "tree_sitter_query",
|
|
161
|
+
"file_language": "tree_sitter_query",
|
|
162
|
+
"content": "((identifier) @type.builtin\n (#any-of? @type.builtin \"int\" \"str\" \"bool\"))",
|
|
163
|
+
"line_start": 30,
|
|
164
|
+
"line_end": 31,
|
|
165
|
+
"metadata": {
|
|
166
|
+
"module": "",
|
|
167
|
+
"names": "",
|
|
168
|
+
"dots": "",
|
|
169
|
+
"language_hint": ""
|
|
170
|
+
},
|
|
171
|
+
"id": "d90c7294ccaddc1d"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"blob_sha": "sha1",
|
|
175
|
+
"file_path": "highlights.scm",
|
|
176
|
+
"kind": "doc_section",
|
|
177
|
+
"name": "",
|
|
178
|
+
"scope": "",
|
|
179
|
+
"language": "tree_sitter_query",
|
|
180
|
+
"file_language": "tree_sitter_query",
|
|
181
|
+
"content": "((comment) @injection.content\n (#set! injection.language \"markdown\"))",
|
|
182
|
+
"line_start": 33,
|
|
183
|
+
"line_end": 34,
|
|
184
|
+
"metadata": {
|
|
185
|
+
"module": "",
|
|
186
|
+
"names": "",
|
|
187
|
+
"dots": "",
|
|
188
|
+
"language_hint": ""
|
|
189
|
+
},
|
|
190
|
+
"id": "a89ebd6b36363bf2"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
"blob_sha": "sha1",
|
|
194
|
+
"file_path": "highlights.scm",
|
|
195
|
+
"kind": "doc_section",
|
|
196
|
+
"name": "definition.function",
|
|
197
|
+
"scope": "",
|
|
198
|
+
"language": "tree_sitter_query",
|
|
199
|
+
"file_language": "tree_sitter_query",
|
|
200
|
+
"content": "; Supertype/subtype match and a MISSING-node pattern.\n(declaration/function_definition) @definition.function",
|
|
201
|
+
"line_start": 36,
|
|
202
|
+
"line_end": 37,
|
|
203
|
+
"metadata": {
|
|
204
|
+
"module": "",
|
|
205
|
+
"names": "",
|
|
206
|
+
"dots": "",
|
|
207
|
+
"language_hint": ""
|
|
208
|
+
},
|
|
209
|
+
"id": "d208be73ec2bbd8a"
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
"blob_sha": "sha1",
|
|
213
|
+
"file_path": "highlights.scm",
|
|
214
|
+
"kind": "doc_section",
|
|
215
|
+
"name": "",
|
|
216
|
+
"scope": "",
|
|
217
|
+
"language": "tree_sitter_query",
|
|
218
|
+
"file_language": "tree_sitter_query",
|
|
219
|
+
"content": "(binary_expression (MISSING identifier))",
|
|
220
|
+
"line_start": 39,
|
|
221
|
+
"line_end": 39,
|
|
222
|
+
"metadata": {
|
|
223
|
+
"module": "",
|
|
224
|
+
"names": "",
|
|
225
|
+
"dots": "",
|
|
226
|
+
"language_hint": ""
|
|
227
|
+
},
|
|
228
|
+
"id": "cbe537008a79992a"
|
|
229
|
+
}
|
|
230
|
+
]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
; A tree-sitter query file exercising every construct rbtr should index:
|
|
2
|
+
; named nodes with fields, anonymous nodes, alternation lists, groupings,
|
|
3
|
+
; predicates, wildcards, negated fields, anchors, quantifiers, supertypes,
|
|
4
|
+
; and a MISSING-node pattern. Every top-level pattern is one doc section.
|
|
5
|
+
|
|
6
|
+
; Named-node patterns with a field and an outer definition capture.
|
|
7
|
+
(function_definition
|
|
8
|
+
name: (identifier) @function
|
|
9
|
+
body: (_) @_body) @definition.function
|
|
10
|
+
|
|
11
|
+
(class_definition
|
|
12
|
+
name: (identifier) @type) @definition.class
|
|
13
|
+
|
|
14
|
+
; Alternation list and a bare anonymous-node matcher.
|
|
15
|
+
["if" "else" "while" "return"] @keyword
|
|
16
|
+
|
|
17
|
+
"async" @keyword.coroutine
|
|
18
|
+
|
|
19
|
+
; Wildcard child, a negated field, anchors, and quantifiers.
|
|
20
|
+
(call_expression
|
|
21
|
+
function: (_) @call
|
|
22
|
+
!type_arguments)
|
|
23
|
+
|
|
24
|
+
(array . (identifier) @first (_)* @rest)
|
|
25
|
+
|
|
26
|
+
; Groupings with predicates: regex match, alternation, and an injection.
|
|
27
|
+
((identifier) @constant
|
|
28
|
+
(#match? @constant "^[A-Z][A-Z_]+$"))
|
|
29
|
+
|
|
30
|
+
((identifier) @type.builtin
|
|
31
|
+
(#any-of? @type.builtin "int" "str" "bool"))
|
|
32
|
+
|
|
33
|
+
((comment) @injection.content
|
|
34
|
+
(#set! injection.language "markdown"))
|
|
35
|
+
|
|
36
|
+
; Supertype/subtype match and a MISSING-node pattern.
|
|
37
|
+
(declaration/function_definition) @definition.function
|
|
38
|
+
|
|
39
|
+
(binary_expression (MISSING identifier))
|
rbtr_lang_tree_sitter_query-2026.9.0.dev1/src/rbtr_lang_tree_sitter_query/tests/test_samples.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""tree-sitter query sample extraction: `samples/tree_sitter_query/` through the real pipeline."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
from tree_sitter import Parser
|
|
10
|
+
|
|
11
|
+
from rbtr.domain.models import Chunk, ChunkKind, Edge
|
|
12
|
+
from rbtr.git import FileEntry
|
|
13
|
+
from rbtr.languages.edges import build_resolution_map, infer_import_edges
|
|
14
|
+
from rbtr.languages.extract import extract_file
|
|
15
|
+
from rbtr.languages.manager import get_manager
|
|
16
|
+
from rbtr.testing import render_edges
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
from syrupy.assertion import SnapshotAssertion
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.fixture
|
|
23
|
+
def project() -> list[tuple[str, str]]:
|
|
24
|
+
root = Path(__file__).parent / "samples" / "tree_sitter_query"
|
|
25
|
+
return [
|
|
26
|
+
(str(p.relative_to(root)), p.read_text()) for p in sorted(root.rglob("*")) if p.is_file()
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@pytest.fixture
|
|
31
|
+
def chunks(project: list[tuple[str, str]]) -> list[Chunk]:
|
|
32
|
+
manager = get_manager()
|
|
33
|
+
out: list[Chunk] = []
|
|
34
|
+
for path, text in project:
|
|
35
|
+
lang = manager.detect_language(path) or "tree_sitter_query"
|
|
36
|
+
out.extend(extract_file(FileEntry(path, "sha1", text.encode()), lang))
|
|
37
|
+
return out
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@pytest.fixture
|
|
41
|
+
def edges(project: list[tuple[str, str]], chunks: list[Chunk]) -> list[Edge]:
|
|
42
|
+
manager = get_manager()
|
|
43
|
+
repo_files = {path for path, _ in project}
|
|
44
|
+
return infer_import_edges(chunks, repo_files, build_resolution_map(manager))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_emits_expected_kinds(chunks: list[Chunk]) -> None:
|
|
48
|
+
"""Each top-level query pattern is a doc-section chunk."""
|
|
49
|
+
kinds = {c.kind for c in chunks}
|
|
50
|
+
assert {ChunkKind.DOC_SECTION, ChunkKind.COMMENT} <= kinds
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_parses_cleanly(project: list[tuple[str, str]]) -> None:
|
|
54
|
+
manager = get_manager()
|
|
55
|
+
for path, text in project:
|
|
56
|
+
grammar = manager.grammar(manager.detect_language(path) or "tree_sitter_query")
|
|
57
|
+
assert grammar is not None
|
|
58
|
+
assert not Parser(grammar).parse(text.encode()).root_node.has_error, path
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_extraction_matches_snapshot(chunks: list[Chunk], snapshot_json: SnapshotAssertion) -> None:
|
|
62
|
+
assert chunks == snapshot_json
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_edges_match_snapshot(
|
|
66
|
+
chunks: list[Chunk], edges: list[Edge], snapshot_json: SnapshotAssertion
|
|
67
|
+
) -> None:
|
|
68
|
+
assert render_edges(edges, chunks) == snapshot_json
|
rbtr_lang_tree_sitter_query-2026.9.0.dev1/src/rbtr_lang_tree_sitter_query/tree_sitter_query.scm
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
; Every top-level pattern is a section. A pattern is named by its own outer
|
|
2
|
+
; label — a capture that is a direct child of the pattern node (e.g.
|
|
3
|
+
; `(function_definition …) @function` → "function"; `["if" "else"] @keyword`
|
|
4
|
+
; → "keyword"). The `?` makes that label optional: predicate-wrapped rules
|
|
5
|
+
; and structural wrappers carry no label of their own and stay anonymous.
|
|
6
|
+
; Captures, predicates, and matched node types inside remain full-text
|
|
7
|
+
; searchable within the section either way.
|
|
8
|
+
; Comments: a `;` block folds into the pattern it precedes, else standalone.
|
|
9
|
+
(comment) @comment
|
|
10
|
+
|
|
11
|
+
(program (named_node (capture (identifier) @_section_name)?) @doc_section)
|
|
12
|
+
(program (list (capture (identifier) @_section_name)?) @doc_section)
|
|
13
|
+
(program (grouping (capture (identifier) @_section_name)?) @doc_section)
|
|
14
|
+
(program (anonymous_node (capture (identifier) @_section_name)?) @doc_section)
|