rbtr-lang-toml 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_toml-2026.9.0.dev1/LICENSE +21 -0
- rbtr_lang_toml-2026.9.0.dev1/PKG-INFO +60 -0
- rbtr_lang_toml-2026.9.0.dev1/README.md +34 -0
- rbtr_lang_toml-2026.9.0.dev1/pyproject.toml +57 -0
- rbtr_lang_toml-2026.9.0.dev1/pyproject.toml.orig +61 -0
- rbtr_lang_toml-2026.9.0.dev1/src/rbtr_lang_toml/__init__.py +1 -0
- rbtr_lang_toml-2026.9.0.dev1/src/rbtr_lang_toml/plugin.py +96 -0
- rbtr_lang_toml-2026.9.0.dev1/src/rbtr_lang_toml/py.typed +0 -0
- rbtr_lang_toml-2026.9.0.dev1/src/rbtr_lang_toml/tests/__init__.py +0 -0
- rbtr_lang_toml-2026.9.0.dev1/src/rbtr_lang_toml/tests/__snapshots__/test_samples/test_edges_match_snapshot.json +3 -0
- rbtr_lang_toml-2026.9.0.dev1/src/rbtr_lang_toml/tests/__snapshots__/test_samples/test_extraction_matches_snapshot.json +173 -0
- rbtr_lang_toml-2026.9.0.dev1/src/rbtr_lang_toml/tests/cases_extraction.py +27 -0
- rbtr_lang_toml-2026.9.0.dev1/src/rbtr_lang_toml/tests/samples/toml/crates/helper/Cargo.toml +5 -0
- rbtr_lang_toml-2026.9.0.dev1/src/rbtr_lang_toml/tests/samples/toml/toml.toml +21 -0
- rbtr_lang_toml-2026.9.0.dev1/src/rbtr_lang_toml/tests/test_extraction.py +28 -0
- rbtr_lang_toml-2026.9.0.dev1/src/rbtr_lang_toml/tests/test_samples.py +68 -0
- rbtr_lang_toml-2026.9.0.dev1/src/rbtr_lang_toml/toml.scm +27 -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-toml
|
|
3
|
+
Version: 2026.9.0.dev1
|
|
4
|
+
Summary: rbtr — TOML language plugin
|
|
5
|
+
Keywords: code-search,code-index,tree-sitter,static-analysis,semantic-search,developer-tools,toml
|
|
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-toml
|
|
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-toml#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-toml
|
|
28
|
+
|
|
29
|
+
TOML support for [rbtr]. Optional plugin — install with
|
|
30
|
+
`pip install rbtr[toml]`.
|
|
31
|
+
|
|
32
|
+
[rbtr]: https://github.com/janrito/rbtr/tree/main/packages/rbtr#readme
|
|
33
|
+
|
|
34
|
+
## What it ingests
|
|
35
|
+
|
|
36
|
+
Tables and array-tables become **config-key** chunks (TOML is data, not code).
|
|
37
|
+
A dotted table splits into its last-segment name plus the preceding path as
|
|
38
|
+
scope.
|
|
39
|
+
|
|
40
|
+
A `path` dependency — `helper = { path = "crates/helper" }`, as Cargo and
|
|
41
|
+
Poetry write a local package — becomes an **import**. It names a directory,
|
|
42
|
+
and the manifest inside it (`Cargo.toml`, `pyproject.toml`) is what the edge
|
|
43
|
+
reaches.
|
|
44
|
+
|
|
45
|
+
## Chunks produced
|
|
46
|
+
|
|
47
|
+
```toml
|
|
48
|
+
[project] # config_key "project"
|
|
49
|
+
[tool.ruff] # config_key "ruff", scope "tool"
|
|
50
|
+
[tool.ruff.lint] # config_key "lint", scope "tool::ruff"
|
|
51
|
+
[[locales]] # config_key "locales"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Embedded / injected chunks
|
|
55
|
+
|
|
56
|
+
None. TOML does not embed other languages.
|
|
57
|
+
|
|
58
|
+
## Grammar & dependencies
|
|
59
|
+
|
|
60
|
+
Uses the `tree-sitter-toml` grammar. No dependency on other language plugins.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# rbtr-lang-toml
|
|
2
|
+
|
|
3
|
+
TOML support for [rbtr]. Optional plugin — install with
|
|
4
|
+
`pip install rbtr[toml]`.
|
|
5
|
+
|
|
6
|
+
[rbtr]: https://github.com/janrito/rbtr/tree/main/packages/rbtr#readme
|
|
7
|
+
|
|
8
|
+
## What it ingests
|
|
9
|
+
|
|
10
|
+
Tables and array-tables become **config-key** chunks (TOML is data, not code).
|
|
11
|
+
A dotted table splits into its last-segment name plus the preceding path as
|
|
12
|
+
scope.
|
|
13
|
+
|
|
14
|
+
A `path` dependency — `helper = { path = "crates/helper" }`, as Cargo and
|
|
15
|
+
Poetry write a local package — becomes an **import**. It names a directory,
|
|
16
|
+
and the manifest inside it (`Cargo.toml`, `pyproject.toml`) is what the edge
|
|
17
|
+
reaches.
|
|
18
|
+
|
|
19
|
+
## Chunks produced
|
|
20
|
+
|
|
21
|
+
```toml
|
|
22
|
+
[project] # config_key "project"
|
|
23
|
+
[tool.ruff] # config_key "ruff", scope "tool"
|
|
24
|
+
[tool.ruff.lint] # config_key "lint", scope "tool::ruff"
|
|
25
|
+
[[locales]] # config_key "locales"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Embedded / injected chunks
|
|
29
|
+
|
|
30
|
+
None. TOML does not embed other languages.
|
|
31
|
+
|
|
32
|
+
## Grammar & dependencies
|
|
33
|
+
|
|
34
|
+
Uses the `tree-sitter-toml` grammar. No dependency on other language 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_toml"
|
|
7
|
+
|
|
8
|
+
[tool.uv.sources.rbtr]
|
|
9
|
+
workspace = true
|
|
10
|
+
|
|
11
|
+
[project]
|
|
12
|
+
name = "rbtr-lang-toml"
|
|
13
|
+
version = "2026.9.0-dev1"
|
|
14
|
+
description = "rbtr — TOML 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
|
+
"toml",
|
|
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-toml",
|
|
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-toml#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
|
+
toml = "rbtr_lang_toml.plugin:toml"
|
|
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_toml"
|
|
7
|
+
# No source-exclude: the plugin's tests, samples, and snapshots ship with
|
|
8
|
+
# the wheel (they are the language's golden record), and toml.scm ships as
|
|
9
|
+
# package data.
|
|
10
|
+
|
|
11
|
+
[project]
|
|
12
|
+
name = "rbtr-lang-toml"
|
|
13
|
+
version = "2026.9.0-dev1"
|
|
14
|
+
description = "rbtr — TOML 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
|
+
"toml",
|
|
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-toml",
|
|
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-toml#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
|
+
toml = "rbtr_lang_toml.plugin:toml"
|
|
56
|
+
|
|
57
|
+
[tool.uv.sources]
|
|
58
|
+
rbtr = { workspace = true }
|
|
59
|
+
|
|
60
|
+
[dependency-groups]
|
|
61
|
+
dev = ["rbtr[test]"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""TOML language plugin package."""
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""TOML language plugin.
|
|
2
|
+
|
|
3
|
+
Extracts each table and array-of-tables as a doc section, via a
|
|
4
|
+
tree-sitter query. A dotted table is named by its last key segment
|
|
5
|
+
and scoped under the preceding segments.
|
|
6
|
+
|
|
7
|
+
Extracted chunks::
|
|
8
|
+
|
|
9
|
+
[project] → config_key "project", scope ""
|
|
10
|
+
[tool.ruff] → config_key "ruff", scope "tool"
|
|
11
|
+
[tool.ruff.lint] → config_key "lint", scope "tool::ruff"
|
|
12
|
+
[[locales]] → config_key "locales", scope ""
|
|
13
|
+
|
|
14
|
+
The dotted-key hierarchy lives in the key *string*, not tree
|
|
15
|
+
ancestry, so name and scope are derived by walking the key's
|
|
16
|
+
ordered segment nodes (`name_extractor` + `scope_extractor`) —
|
|
17
|
+
robust to quoted segments containing dots (`[a."b.c"]`).
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
from typing import TYPE_CHECKING
|
|
23
|
+
|
|
24
|
+
from rbtr.languages.registration import (
|
|
25
|
+
LanguageRegistration,
|
|
26
|
+
NameResolver,
|
|
27
|
+
QueryExtraction,
|
|
28
|
+
ScopeResolver,
|
|
29
|
+
load_query,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
if TYPE_CHECKING:
|
|
33
|
+
from tree_sitter import Node
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _key_text(node: Node) -> str:
|
|
37
|
+
"""Text of a single key node, stripping the quotes off a quoted key."""
|
|
38
|
+
text = node.text.decode("utf-8", errors="replace") if node.text else ""
|
|
39
|
+
if node.type == "quoted_key" and len(text) >= 2 and text[0] in "\"'" and text[-1] == text[0]:
|
|
40
|
+
return text[1:-1]
|
|
41
|
+
return text
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _key_segments(key_node: Node) -> list[str]:
|
|
45
|
+
"""Ordered segments of a table key.
|
|
46
|
+
|
|
47
|
+
A `bare_key`/`quoted_key` is one segment; a `dotted_key` is its
|
|
48
|
+
child segments in order (left-recursive, so an in-order walk yields
|
|
49
|
+
`[tool, ruff, lint]` for `tool.ruff.lint`).
|
|
50
|
+
"""
|
|
51
|
+
if key_node.type in ("bare_key", "quoted_key"):
|
|
52
|
+
return [_key_text(key_node)]
|
|
53
|
+
if key_node.type == "dotted_key":
|
|
54
|
+
segments: list[str] = []
|
|
55
|
+
for child in key_node.children:
|
|
56
|
+
if child.type in ("bare_key", "quoted_key", "dotted_key"):
|
|
57
|
+
segments.extend(_key_segments(child))
|
|
58
|
+
return segments
|
|
59
|
+
return []
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
toml = LanguageRegistration(
|
|
63
|
+
id="toml",
|
|
64
|
+
extensions=frozenset({".toml"}),
|
|
65
|
+
grammar_module="tree_sitter_toml",
|
|
66
|
+
extraction=QueryExtraction(
|
|
67
|
+
query=load_query(__package__, "toml"),
|
|
68
|
+
),
|
|
69
|
+
# A `path` dependency names a directory, which its manifest stands for.
|
|
70
|
+
index_files=frozenset({"Cargo.toml", "pyproject.toml"}),
|
|
71
|
+
extraction_serial=5,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@toml.name_extractor
|
|
76
|
+
def toml_table_name(
|
|
77
|
+
resolver: NameResolver, capture_name: str, node: Node, captures: dict[str, list[Node]]
|
|
78
|
+
) -> str:
|
|
79
|
+
"""Name a table by its last key segment (`[tool.ruff]` → `"ruff"`)."""
|
|
80
|
+
key_nodes = captures.get("_section_name", [])
|
|
81
|
+
if key_nodes:
|
|
82
|
+
segments = _key_segments(key_nodes[0])
|
|
83
|
+
if segments:
|
|
84
|
+
return segments[-1]
|
|
85
|
+
return resolver(capture_name, node, captures)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@toml.scope_extractor
|
|
89
|
+
def toml_table_scope(
|
|
90
|
+
_resolver: ScopeResolver, _capture_name: str, _node: Node, captures: dict[str, list[Node]]
|
|
91
|
+
) -> list[str]:
|
|
92
|
+
"""Scope a table under its leading key segments (`[tool.ruff]` → `["tool"]`)."""
|
|
93
|
+
key_nodes = captures.get("_section_name", [])
|
|
94
|
+
if not key_nodes:
|
|
95
|
+
return []
|
|
96
|
+
return _key_segments(key_nodes[0])[:-1]
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"blob_sha": "sha1",
|
|
4
|
+
"file_path": "crates/helper/Cargo.toml",
|
|
5
|
+
"kind": "config_key",
|
|
6
|
+
"name": "package",
|
|
7
|
+
"scope": "",
|
|
8
|
+
"language": "toml",
|
|
9
|
+
"file_language": "toml",
|
|
10
|
+
"content": "# Reached from the root manifest's `path` dependency: the reference names\n# this directory, and this manifest stands for it.\n[package]\nname = \"helper\"\nversion = \"0.1.0\"\n",
|
|
11
|
+
"line_start": 1,
|
|
12
|
+
"line_end": 5,
|
|
13
|
+
"metadata": {
|
|
14
|
+
"module": "",
|
|
15
|
+
"names": "",
|
|
16
|
+
"dots": "",
|
|
17
|
+
"language_hint": ""
|
|
18
|
+
},
|
|
19
|
+
"id": "fe7065b1fd42886f"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"blob_sha": "sha1",
|
|
23
|
+
"file_path": "toml.toml",
|
|
24
|
+
"kind": "comment",
|
|
25
|
+
"name": "",
|
|
26
|
+
"scope": "",
|
|
27
|
+
"language": "toml",
|
|
28
|
+
"file_language": "toml",
|
|
29
|
+
"content": "# Greeter configuration.",
|
|
30
|
+
"line_start": 1,
|
|
31
|
+
"line_end": 1,
|
|
32
|
+
"metadata": {
|
|
33
|
+
"module": "",
|
|
34
|
+
"names": "",
|
|
35
|
+
"dots": "",
|
|
36
|
+
"language_hint": ""
|
|
37
|
+
},
|
|
38
|
+
"id": "50ad5e5473caed7a"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"blob_sha": "sha1",
|
|
42
|
+
"file_path": "toml.toml",
|
|
43
|
+
"kind": "config_key",
|
|
44
|
+
"name": "project",
|
|
45
|
+
"scope": "",
|
|
46
|
+
"language": "toml",
|
|
47
|
+
"file_language": "toml",
|
|
48
|
+
"content": "[project]\nname = \"greeter\"\nversion = \"1.0.0\"\n\n",
|
|
49
|
+
"line_start": 3,
|
|
50
|
+
"line_end": 6,
|
|
51
|
+
"metadata": {
|
|
52
|
+
"module": "",
|
|
53
|
+
"names": "",
|
|
54
|
+
"dots": "",
|
|
55
|
+
"language_hint": ""
|
|
56
|
+
},
|
|
57
|
+
"id": "810e02a3ef287aee"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"blob_sha": "sha1",
|
|
61
|
+
"file_path": "toml.toml",
|
|
62
|
+
"kind": "config_key",
|
|
63
|
+
"name": "greeter",
|
|
64
|
+
"scope": "tool",
|
|
65
|
+
"language": "toml",
|
|
66
|
+
"file_language": "toml",
|
|
67
|
+
"content": "[tool.greeter]\ndefault_greeting = \"Hello\"\nlocale = \"en\"\n\n",
|
|
68
|
+
"line_start": 7,
|
|
69
|
+
"line_end": 10,
|
|
70
|
+
"metadata": {
|
|
71
|
+
"module": "",
|
|
72
|
+
"names": "",
|
|
73
|
+
"dots": "",
|
|
74
|
+
"language_hint": ""
|
|
75
|
+
},
|
|
76
|
+
"id": "0c56dae5307aca27"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"blob_sha": "sha1",
|
|
80
|
+
"file_path": "toml.toml",
|
|
81
|
+
"kind": "config_key",
|
|
82
|
+
"name": "limits",
|
|
83
|
+
"scope": "tool::greeter",
|
|
84
|
+
"language": "toml",
|
|
85
|
+
"file_language": "toml",
|
|
86
|
+
"content": "[tool.greeter.limits]\nmax_length = 280\n\n",
|
|
87
|
+
"line_start": 11,
|
|
88
|
+
"line_end": 13,
|
|
89
|
+
"metadata": {
|
|
90
|
+
"module": "",
|
|
91
|
+
"names": "",
|
|
92
|
+
"dots": "",
|
|
93
|
+
"language_hint": ""
|
|
94
|
+
},
|
|
95
|
+
"id": "52a55cfee81b7ca6"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"blob_sha": "sha1",
|
|
99
|
+
"file_path": "toml.toml",
|
|
100
|
+
"kind": "config_key",
|
|
101
|
+
"name": "locales",
|
|
102
|
+
"scope": "",
|
|
103
|
+
"language": "toml",
|
|
104
|
+
"file_language": "toml",
|
|
105
|
+
"content": "[[locales]]\ncode = \"en\"\n\n",
|
|
106
|
+
"line_start": 14,
|
|
107
|
+
"line_end": 16,
|
|
108
|
+
"metadata": {
|
|
109
|
+
"module": "",
|
|
110
|
+
"names": "",
|
|
111
|
+
"dots": "",
|
|
112
|
+
"language_hint": ""
|
|
113
|
+
},
|
|
114
|
+
"id": "1a4a2f317d869574"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"blob_sha": "sha1",
|
|
118
|
+
"file_path": "toml.toml",
|
|
119
|
+
"kind": "config_key",
|
|
120
|
+
"name": "locales",
|
|
121
|
+
"scope": "",
|
|
122
|
+
"language": "toml",
|
|
123
|
+
"file_language": "toml",
|
|
124
|
+
"content": "[[locales]]\ncode = \"fr\"\n\n",
|
|
125
|
+
"line_start": 17,
|
|
126
|
+
"line_end": 19,
|
|
127
|
+
"metadata": {
|
|
128
|
+
"module": "",
|
|
129
|
+
"names": "",
|
|
130
|
+
"dots": "",
|
|
131
|
+
"language_hint": ""
|
|
132
|
+
},
|
|
133
|
+
"id": "07b8eb89d6873489"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"blob_sha": "sha1",
|
|
137
|
+
"file_path": "toml.toml",
|
|
138
|
+
"kind": "config_key",
|
|
139
|
+
"name": "dependencies",
|
|
140
|
+
"scope": "",
|
|
141
|
+
"language": "toml",
|
|
142
|
+
"file_language": "toml",
|
|
143
|
+
"content": "[dependencies]\nhelper = { path = \"crates/helper\" }\n",
|
|
144
|
+
"line_start": 20,
|
|
145
|
+
"line_end": 21,
|
|
146
|
+
"metadata": {
|
|
147
|
+
"module": "",
|
|
148
|
+
"names": "",
|
|
149
|
+
"dots": "",
|
|
150
|
+
"language_hint": ""
|
|
151
|
+
},
|
|
152
|
+
"id": "e38a60287b94f718"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"blob_sha": "sha1",
|
|
156
|
+
"file_path": "toml.toml",
|
|
157
|
+
"kind": "import",
|
|
158
|
+
"name": "path = \"crates/helper\"",
|
|
159
|
+
"scope": "",
|
|
160
|
+
"language": "toml",
|
|
161
|
+
"file_language": "toml",
|
|
162
|
+
"content": "path = \"crates/helper\"",
|
|
163
|
+
"line_start": 21,
|
|
164
|
+
"line_end": 21,
|
|
165
|
+
"metadata": {
|
|
166
|
+
"module": "crates/helper",
|
|
167
|
+
"names": "",
|
|
168
|
+
"dots": "",
|
|
169
|
+
"language_hint": ""
|
|
170
|
+
},
|
|
171
|
+
"id": "bb6218d7bbc421e1"
|
|
172
|
+
}
|
|
173
|
+
]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""TOML extraction test cases (tables and array-tables -> config_key)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pytest_cases import case
|
|
6
|
+
|
|
7
|
+
type SymbolCase = tuple[str, str, list[tuple[str, str, str]]]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@case(tags=["symbol"])
|
|
11
|
+
def case_toml_splits_by_table() -> SymbolCase:
|
|
12
|
+
"""TOML splits by tables; a dotted table is named by its last segment."""
|
|
13
|
+
src = """\
|
|
14
|
+
[project]
|
|
15
|
+
name = "rbtr"
|
|
16
|
+
|
|
17
|
+
[tool.ruff]
|
|
18
|
+
line-length = 99
|
|
19
|
+
"""
|
|
20
|
+
return (
|
|
21
|
+
"toml",
|
|
22
|
+
src,
|
|
23
|
+
[
|
|
24
|
+
("config_key", "project", ""),
|
|
25
|
+
("config_key", "ruff", "tool"),
|
|
26
|
+
],
|
|
27
|
+
)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Greeter configuration.
|
|
2
|
+
|
|
3
|
+
[project]
|
|
4
|
+
name = "greeter"
|
|
5
|
+
version = "1.0.0"
|
|
6
|
+
|
|
7
|
+
[tool.greeter]
|
|
8
|
+
default_greeting = "Hello"
|
|
9
|
+
locale = "en"
|
|
10
|
+
|
|
11
|
+
[tool.greeter.limits]
|
|
12
|
+
max_length = 280
|
|
13
|
+
|
|
14
|
+
[[locales]]
|
|
15
|
+
code = "en"
|
|
16
|
+
|
|
17
|
+
[[locales]]
|
|
18
|
+
code = "fr"
|
|
19
|
+
|
|
20
|
+
[dependencies]
|
|
21
|
+
helper = { path = "crates/helper" }
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""TOML extraction tests (cases in `cases_extraction.py`)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pytest_cases import parametrize_with_cases
|
|
6
|
+
|
|
7
|
+
from rbtr.git import FileEntry
|
|
8
|
+
from rbtr.languages.extract import extract_file
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@parametrize_with_cases("lang, source, expected", cases=".cases_extraction", has_tag="symbol")
|
|
12
|
+
def test_extracts_expected_symbols(lang: str, source: str, expected: list) -> None:
|
|
13
|
+
"""Each expected (kind, name, scope) tuple appears in the output."""
|
|
14
|
+
chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
|
|
15
|
+
symbols = [(c.kind, c.name, c.scope) for c in chunks]
|
|
16
|
+
for exp in expected:
|
|
17
|
+
assert exp in symbols, f"expected {exp} not found in {symbols}"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_toml_dotted_key_scope() -> None:
|
|
21
|
+
"""A TOML dotted table splits into last-segment name + preceding scope."""
|
|
22
|
+
src = """\
|
|
23
|
+
[tool.ruff.lint]
|
|
24
|
+
select = ["E"]
|
|
25
|
+
"""
|
|
26
|
+
chunks = extract_file(FileEntry("input", "sha1", src.encode()), "toml")
|
|
27
|
+
assert chunks[0].name == "lint"
|
|
28
|
+
assert chunks[0].scope == "tool::ruff"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""TOML sample extraction: the `samples/toml/` project 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" / "toml"
|
|
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 "toml"
|
|
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
|
+
"""The sample exercises TOML's config-key chunks."""
|
|
49
|
+
kinds = {c.kind for c in chunks}
|
|
50
|
+
assert {ChunkKind.CONFIG_KEY, 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 "toml")
|
|
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
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
; Comments (`#`).
|
|
2
|
+
(comment) @comment
|
|
3
|
+
|
|
4
|
+
(table
|
|
5
|
+
(bare_key) @_section_name) @config_key
|
|
6
|
+
|
|
7
|
+
(table
|
|
8
|
+
(dotted_key) @_section_name) @config_key
|
|
9
|
+
|
|
10
|
+
(table
|
|
11
|
+
(quoted_key) @_section_name) @config_key
|
|
12
|
+
|
|
13
|
+
(table_array_element
|
|
14
|
+
(bare_key) @_section_name) @config_key
|
|
15
|
+
|
|
16
|
+
(table_array_element
|
|
17
|
+
(dotted_key) @_section_name) @config_key
|
|
18
|
+
|
|
19
|
+
(table_array_element
|
|
20
|
+
(quoted_key) @_section_name) @config_key
|
|
21
|
+
|
|
22
|
+
; A `path` dependency names a directory this repository holds, as Cargo
|
|
23
|
+
; writes a local crate: `helper = { path = "crates/helper" }`.
|
|
24
|
+
(pair
|
|
25
|
+
(bare_key) @_key
|
|
26
|
+
(#eq? @_key "path")
|
|
27
|
+
(string) @_import_module) @import
|