Type Providers for Tree Sitter
Create a type AST from any node-types.json file, as well as a generic visitor class and a transformer class, and a function to convert to the AST from the tree_sitter.Node type.
For example, the following code defines a module named tree_sitter_javascript from tree-sitter-javascript/src/nodes.json:
import pathlib
import tree_sitter_type_provider as tstp
node_types_json = pathlib.Path("tree-sitter-javascript/src/node-types.json")
node_types = tstp.NodeType.schema().loads(node_types_json.read_text(), many=True)
def as_class_name(node_type_name: str) -> str:
class_name_parts: typing.List[str] = ["Js"]
for part in node_type_name.split("_"):
class_name_parts.append(part.capitalize())
return "".join(class_name_parts)
sys.modules[__name__] = tstp.TreeSitterTypeProvider(
"tree_sitter_javascript",
node_types,
error_as_node=True, # Include ERROR as a node in the AST
as_class_name=as_class_name, # How to convert node types to Python class names
extra=["comment"], # Nodes which are marked as 'extra' in the grammar
)
The module contains a number of dataclasses which represent the AST nodes:
import tree_sitter as ts
import tree_sitter_type_provider as tstp
import typing
@dataclass
class JsArray(tstp.Node):
text: str
type_name: str
start_position: tstp.Point
end_position: tstp.Point
children: typing.List[typing.Union[JsExpression, JsSpreadElement]]
@dataclass
class JsDeclaration(tstp.Node):
text: str
type_name: str
start_position: tstp.Point
end_position: tstp.Point
@dataclass
class JsWhileStatement(tstp.Node):
text: str
type_name: str
start_position: tstp.Point
end_position: tstp.Point
body: JsStatement
condition: JsParenthesizedExpression
...
As well as a function to convert to the AST:
def from_tree_sitter(self, tsvalue: typing.Union[ts.Tree, ts.Node, ts.TreeCursor], *, encoding: str = 'utf-8') -> tstp.Node
Metadata
Release files for tree-sitter-type-provider 2.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| tree_sitter_type_provider-2.2.0.tar.gz | 10.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tree_sitter_type_provider-2.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.2 kB
Release files / tree_sitter_type_provider-2.2.0.tar.gz
| Download URL | tree_sitter_type_provider-2.2.0.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d9a1da73e4e5e6441cf84281b154730cbcad4480dfcfc61fc926d3aceb75fc55
|
|
BLAKE2b-256 checksum How to use checksums |
af9493b858bf76864aed6f1a7326448c69a7b9813e215b3efa7b900b2c4f4b54
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Release files / tree_sitter_type_provider-2.2.0-py3-none-any.whl
| Download URL | tree_sitter_type_provider-2.2.0-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
72e9ece6953d170a6cf09ad9cd44351b47a6b874c1ff4d95e94825e0f6df03df
|
|
BLAKE2b-256 checksum How to use checksums |
f2173ffc1330a417c39754e05e5282b60620b00cca58aa955f5acbd1826594b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Security for tree-sitter-type-provider 2.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.