First Commit
This commit is contained in:
11
bindings/python/tests/test_binding.py
generated
Normal file
11
bindings/python/tests/test_binding.py
generated
Normal file
@ -0,0 +1,11 @@
|
||||
from unittest import TestCase
|
||||
|
||||
import tree_sitter, tree_sitter_jrpc
|
||||
|
||||
|
||||
class TestLanguage(TestCase):
|
||||
def test_can_load_grammar(self):
|
||||
try:
|
||||
tree_sitter.Language(tree_sitter_jrpc.language())
|
||||
except Exception:
|
||||
self.fail("Error loading Jrpc grammar")
|
42
bindings/python/tree_sitter_jrpc/__init__.py
generated
Normal file
42
bindings/python/tree_sitter_jrpc/__init__.py
generated
Normal file
@ -0,0 +1,42 @@
|
||||
"""Jrpc grammar for tree-sitter"""
|
||||
|
||||
from importlib.resources import files as _files
|
||||
|
||||
from ._binding import language
|
||||
|
||||
|
||||
def _get_query(name, file):
|
||||
query = _files(f"{__package__}.queries") / file
|
||||
globals()[name] = query.read_text()
|
||||
return globals()[name]
|
||||
|
||||
|
||||
def __getattr__(name):
|
||||
# NOTE: uncomment these to include any queries that this grammar contains:
|
||||
|
||||
# if name == "HIGHLIGHTS_QUERY":
|
||||
# return _get_query("HIGHLIGHTS_QUERY", "highlights.scm")
|
||||
# if name == "INJECTIONS_QUERY":
|
||||
# return _get_query("INJECTIONS_QUERY", "injections.scm")
|
||||
# if name == "LOCALS_QUERY":
|
||||
# return _get_query("LOCALS_QUERY", "locals.scm")
|
||||
# if name == "TAGS_QUERY":
|
||||
# return _get_query("TAGS_QUERY", "tags.scm")
|
||||
|
||||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
||||
|
||||
|
||||
__all__ = [
|
||||
"language",
|
||||
# "HIGHLIGHTS_QUERY",
|
||||
# "INJECTIONS_QUERY",
|
||||
# "LOCALS_QUERY",
|
||||
# "TAGS_QUERY",
|
||||
]
|
||||
|
||||
|
||||
def __dir__():
|
||||
return sorted(__all__ + [
|
||||
"__all__", "__builtins__", "__cached__", "__doc__", "__file__",
|
||||
"__loader__", "__name__", "__package__", "__path__", "__spec__",
|
||||
])
|
10
bindings/python/tree_sitter_jrpc/__init__.pyi
generated
Normal file
10
bindings/python/tree_sitter_jrpc/__init__.pyi
generated
Normal file
@ -0,0 +1,10 @@
|
||||
from typing import Final
|
||||
|
||||
# NOTE: uncomment these to include any queries that this grammar contains:
|
||||
|
||||
# HIGHLIGHTS_QUERY: Final[str]
|
||||
# INJECTIONS_QUERY: Final[str]
|
||||
# LOCALS_QUERY: Final[str]
|
||||
# TAGS_QUERY: Final[str]
|
||||
|
||||
def language() -> object: ...
|
27
bindings/python/tree_sitter_jrpc/binding.c
generated
Normal file
27
bindings/python/tree_sitter_jrpc/binding.c
generated
Normal file
@ -0,0 +1,27 @@
|
||||
#include <Python.h>
|
||||
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
|
||||
TSLanguage *tree_sitter_jrpc(void);
|
||||
|
||||
static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) {
|
||||
return PyCapsule_New(tree_sitter_jrpc(), "tree_sitter.Language", NULL);
|
||||
}
|
||||
|
||||
static PyMethodDef methods[] = {
|
||||
{"language", _binding_language, METH_NOARGS,
|
||||
"Get the tree-sitter language for this grammar."},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
static struct PyModuleDef module = {
|
||||
.m_base = PyModuleDef_HEAD_INIT,
|
||||
.m_name = "_binding",
|
||||
.m_doc = NULL,
|
||||
.m_size = -1,
|
||||
.m_methods = methods
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC PyInit__binding(void) {
|
||||
return PyModule_Create(&module);
|
||||
}
|
0
bindings/python/tree_sitter_jrpc/py.typed
generated
Normal file
0
bindings/python/tree_sitter_jrpc/py.typed
generated
Normal file
Reference in New Issue
Block a user