tree-sitter-python-orchard 0.4.1__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.
Files changed (22) hide show
  1. tree-sitter-python-orchard-0.4.1/LICENSE +21 -0
  2. tree-sitter-python-orchard-0.4.1/PKG-INFO +30 -0
  3. tree-sitter-python-orchard-0.4.1/README.md +13 -0
  4. tree-sitter-python-orchard-0.4.1/bindings/python/tree_sitter_python_orchard/__init__.py +42 -0
  5. tree-sitter-python-orchard-0.4.1/bindings/python/tree_sitter_python_orchard/__init__.pyi +10 -0
  6. tree-sitter-python-orchard-0.4.1/bindings/python/tree_sitter_python_orchard/binding.c +35 -0
  7. tree-sitter-python-orchard-0.4.1/bindings/python/tree_sitter_python_orchard/py.typed +0 -0
  8. tree-sitter-python-orchard-0.4.1/bindings/python/tree_sitter_python_orchard.egg-info/PKG-INFO +30 -0
  9. tree-sitter-python-orchard-0.4.1/bindings/python/tree_sitter_python_orchard.egg-info/SOURCES.txt +15 -0
  10. tree-sitter-python-orchard-0.4.1/bindings/python/tree_sitter_python_orchard.egg-info/dependency_links.txt +1 -0
  11. tree-sitter-python-orchard-0.4.1/bindings/python/tree_sitter_python_orchard.egg-info/not-zip-safe +1 -0
  12. tree-sitter-python-orchard-0.4.1/bindings/python/tree_sitter_python_orchard.egg-info/requires.txt +3 -0
  13. tree-sitter-python-orchard-0.4.1/bindings/python/tree_sitter_python_orchard.egg-info/top_level.txt +2 -0
  14. tree-sitter-python-orchard-0.4.1/pyproject.toml +29 -0
  15. tree-sitter-python-orchard-0.4.1/queries/highlights.scm +138 -0
  16. tree-sitter-python-orchard-0.4.1/queries/tags.scm +14 -0
  17. tree-sitter-python-orchard-0.4.1/setup.cfg +4 -0
  18. tree-sitter-python-orchard-0.4.1/setup.py +77 -0
  19. tree-sitter-python-orchard-0.4.1/src/parser.c +130621 -0
  20. tree-sitter-python-orchard-0.4.1/src/tree_sitter/alloc.h +54 -0
  21. tree-sitter-python-orchard-0.4.1/src/tree_sitter/array.h +291 -0
  22. tree-sitter-python-orchard-0.4.1/src/tree_sitter/parser.h +286 -0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Max Brunsfeld
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,30 @@
1
+ Metadata-Version: 2.1
2
+ Name: tree-sitter-python-orchard
3
+ Version: 0.4.1
4
+ Summary: Parser for Python files
5
+ Author-email: Max Brunsfeld <maxbrunsfeld@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://codeberg.org/grammar-orchard/tree-siter-python-orchard
8
+ Keywords: incremental,parsing,tree-sitter,python-orchard
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Topic :: Software Development :: Compilers
11
+ Classifier: Topic :: Text Processing :: Linguistic
12
+ Classifier: Typing :: Typed
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ Provides-Extra: core
16
+ License-File: LICENSE
17
+
18
+ # tree-sitter-python-orchard
19
+
20
+ [![crates][crates]](https://crates.io/crates/tree-sitter-python-orchard)
21
+ [pypi]: https://img.shields.io/pypi/v/tree-sitter-python-orchard?logo=pypi&logoColor=ffd242
22
+
23
+ Python grammar for Tree-sitter, forked from https://github.com/tree-sitter/tree-sitter-python
24
+
25
+ Note that unlike upstream, generated files are not checked into git, so you need to run `tree-sitter generate` after cloning this repository.
26
+
27
+ Contributions are welcome, so are co-maintainers.
28
+
29
+ [crates]: https://img.shields.io/crates/v/tree-sitter-python-orchard?logo=rust
30
+ [pypi]: https://img.shields.io/pypi/v/tree-sitter-python-orchard?logo=pypi&logoColor=ffd242
@@ -0,0 +1,13 @@
1
+ # tree-sitter-python-orchard
2
+
3
+ [![crates][crates]](https://crates.io/crates/tree-sitter-python-orchard)
4
+ [pypi]: https://img.shields.io/pypi/v/tree-sitter-python-orchard?logo=pypi&logoColor=ffd242
5
+
6
+ Python grammar for Tree-sitter, forked from https://github.com/tree-sitter/tree-sitter-python
7
+
8
+ Note that unlike upstream, generated files are not checked into git, so you need to run `tree-sitter generate` after cloning this repository.
9
+
10
+ Contributions are welcome, so are co-maintainers.
11
+
12
+ [crates]: https://img.shields.io/crates/v/tree-sitter-python-orchard?logo=rust
13
+ [pypi]: https://img.shields.io/pypi/v/tree-sitter-python-orchard?logo=pypi&logoColor=ffd242
@@ -0,0 +1,42 @@
1
+ """Parser for Python files"""
2
+
3
+ from importlib.resources import files as _files
4
+
5
+ from ._binding import language
6
+
7
+
8
+ def _get_query(name, file):
9
+ query = _files(f"{__package__}.queries") / file
10
+ globals()[name] = query.read_text()
11
+ return globals()[name]
12
+
13
+
14
+ def __getattr__(name):
15
+ # NOTE: uncomment these to include any queries that this grammar contains:
16
+
17
+ if name == "HIGHLIGHTS_QUERY":
18
+ return _get_query("HIGHLIGHTS_QUERY", "highlights.scm")
19
+ # if name == "INJECTIONS_QUERY":
20
+ # return _get_query("INJECTIONS_QUERY", "injections.scm")
21
+ # if name == "LOCALS_QUERY":
22
+ # return _get_query("LOCALS_QUERY", "locals.scm")
23
+ if name == "TAGS_QUERY":
24
+ return _get_query("TAGS_QUERY", "tags.scm")
25
+
26
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
27
+
28
+
29
+ __all__ = [
30
+ "language",
31
+ # "HIGHLIGHTS_QUERY",
32
+ # "INJECTIONS_QUERY",
33
+ # "LOCALS_QUERY",
34
+ # "TAGS_QUERY",
35
+ ]
36
+
37
+
38
+ def __dir__():
39
+ return sorted(__all__ + [
40
+ "__all__", "__builtins__", "__cached__", "__doc__", "__file__",
41
+ "__loader__", "__name__", "__package__", "__path__", "__spec__",
42
+ ])
@@ -0,0 +1,10 @@
1
+ from typing import Final
2
+
3
+ # NOTE: uncomment these to include any queries that this grammar contains:
4
+
5
+ # HIGHLIGHTS_QUERY: Final[str]
6
+ # INJECTIONS_QUERY: Final[str]
7
+ # LOCALS_QUERY: Final[str]
8
+ # TAGS_QUERY: Final[str]
9
+
10
+ def language() -> object: ...
@@ -0,0 +1,35 @@
1
+ #include <Python.h>
2
+
3
+ typedef struct TSLanguage TSLanguage;
4
+
5
+ TSLanguage *tree_sitter_python_orchard(void);
6
+
7
+ static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) {
8
+ return PyCapsule_New(tree_sitter_python_orchard(), "tree_sitter.Language", NULL);
9
+ }
10
+
11
+ static struct PyModuleDef_Slot slots[] = {
12
+ #ifdef Py_GIL_DISABLED
13
+ {Py_mod_gil, Py_MOD_GIL_NOT_USED},
14
+ #endif
15
+ {0, NULL}
16
+ };
17
+
18
+ static PyMethodDef methods[] = {
19
+ {"language", _binding_language, METH_NOARGS,
20
+ "Get the tree-sitter language for this grammar."},
21
+ {NULL, NULL, 0, NULL}
22
+ };
23
+
24
+ static struct PyModuleDef module = {
25
+ .m_base = PyModuleDef_HEAD_INIT,
26
+ .m_name = "_binding",
27
+ .m_doc = NULL,
28
+ .m_size = 0,
29
+ .m_methods = methods,
30
+ .m_slots = slots,
31
+ };
32
+
33
+ PyMODINIT_FUNC PyInit__binding(void) {
34
+ return PyModuleDef_Init(&module);
35
+ }
@@ -0,0 +1,30 @@
1
+ Metadata-Version: 2.1
2
+ Name: tree-sitter-python-orchard
3
+ Version: 0.4.1
4
+ Summary: Parser for Python files
5
+ Author-email: Max Brunsfeld <maxbrunsfeld@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://codeberg.org/grammar-orchard/tree-siter-python-orchard
8
+ Keywords: incremental,parsing,tree-sitter,python-orchard
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Topic :: Software Development :: Compilers
11
+ Classifier: Topic :: Text Processing :: Linguistic
12
+ Classifier: Typing :: Typed
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ Provides-Extra: core
16
+ License-File: LICENSE
17
+
18
+ # tree-sitter-python-orchard
19
+
20
+ [![crates][crates]](https://crates.io/crates/tree-sitter-python-orchard)
21
+ [pypi]: https://img.shields.io/pypi/v/tree-sitter-python-orchard?logo=pypi&logoColor=ffd242
22
+
23
+ Python grammar for Tree-sitter, forked from https://github.com/tree-sitter/tree-sitter-python
24
+
25
+ Note that unlike upstream, generated files are not checked into git, so you need to run `tree-sitter generate` after cloning this repository.
26
+
27
+ Contributions are welcome, so are co-maintainers.
28
+
29
+ [crates]: https://img.shields.io/crates/v/tree-sitter-python-orchard?logo=rust
30
+ [pypi]: https://img.shields.io/pypi/v/tree-sitter-python-orchard?logo=pypi&logoColor=ffd242
@@ -0,0 +1,15 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ bindings/python/tree_sitter_python_orchard/__init__.py
6
+ bindings/python/tree_sitter_python_orchard/__init__.pyi
7
+ bindings/python/tree_sitter_python_orchard/binding.c
8
+ bindings/python/tree_sitter_python_orchard/py.typed
9
+ bindings/python/tree_sitter_python_orchard.egg-info/PKG-INFO
10
+ bindings/python/tree_sitter_python_orchard.egg-info/SOURCES.txt
11
+ bindings/python/tree_sitter_python_orchard.egg-info/dependency_links.txt
12
+ bindings/python/tree_sitter_python_orchard.egg-info/not-zip-safe
13
+ bindings/python/tree_sitter_python_orchard.egg-info/requires.txt
14
+ bindings/python/tree_sitter_python_orchard.egg-info/top_level.txt
15
+ src/parser.c
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["setuptools>=62.4.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "tree-sitter-python-orchard"
7
+ description = "Parser for Python files"
8
+ version = "0.4.1"
9
+ keywords = ["incremental", "parsing", "tree-sitter", "python-orchard"]
10
+ classifiers = [
11
+ "Intended Audience :: Developers",
12
+ "Topic :: Software Development :: Compilers",
13
+ "Topic :: Text Processing :: Linguistic",
14
+ "Typing :: Typed",
15
+ ]
16
+ authors = [{ name = "Max Brunsfeld", email = "maxbrunsfeld@gmail.com" }]
17
+ requires-python = ">=3.10"
18
+ license.text = "MIT"
19
+ readme = "README.md"
20
+
21
+ [project.urls]
22
+ Homepage = "https://codeberg.org/grammar-orchard/tree-siter-python-orchard"
23
+
24
+ [project.optional-dependencies]
25
+ core = ["tree-sitter~=0.24"]
26
+
27
+ [tool.cibuildwheel]
28
+ build = "cp310-*"
29
+ build-frontend = "build"
@@ -0,0 +1,138 @@
1
+ ; Identifier naming conventions
2
+
3
+ (identifier) @variable
4
+
5
+ ((identifier) @constructor
6
+ (#match? @constructor "^[A-Z]"))
7
+
8
+ ((identifier) @constant
9
+ (#match? @constant "^[A-Z][A-Z_]*$"))
10
+
11
+ ; Function calls
12
+
13
+ (decorator) @function
14
+ (decorator
15
+ (identifier) @function)
16
+
17
+ (call
18
+ function: (attribute attribute: (identifier) @function.method))
19
+ (call
20
+ function: (identifier) @function)
21
+
22
+ ; Builtin functions
23
+
24
+ ((call
25
+ function: (identifier) @function.builtin)
26
+ (#match?
27
+ @function.builtin
28
+ "^(abs|all|any|ascii|bin|bool|breakpoint|bytearray|bytes|callable|chr|classmethod|compile|complex|delattr|dict|dir|divmod|enumerate|eval|exec|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|isinstance|issubclass|iter|len|list|locals|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|range|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|vars|zip|__import__)$"))
29
+
30
+ ; Function definitions
31
+
32
+ (function_definition
33
+ name: (identifier) @function)
34
+
35
+ (attribute attribute: (identifier) @property)
36
+ (type (identifier) @type)
37
+
38
+ ; Literals
39
+
40
+ [
41
+ (none)
42
+ (true)
43
+ (false)
44
+ ] @constant.builtin
45
+
46
+ [
47
+ (integer)
48
+ (float)
49
+ ] @number
50
+
51
+ (comment) @comment
52
+ (string) @string
53
+ (docstring) @string
54
+ (escape_sequence) @escape
55
+
56
+ (interpolation
57
+ "{" @punctuation.special
58
+ "}" @punctuation.special) @embedded
59
+
60
+ [
61
+ "-"
62
+ "-="
63
+ "!="
64
+ "*"
65
+ "**"
66
+ "**="
67
+ "*="
68
+ "/"
69
+ "//"
70
+ "//="
71
+ "/="
72
+ "&"
73
+ "&="
74
+ "%"
75
+ "%="
76
+ "^"
77
+ "^="
78
+ "+"
79
+ "->"
80
+ "+="
81
+ "<"
82
+ "<<"
83
+ "<<="
84
+ "<="
85
+ "<>"
86
+ "="
87
+ ":="
88
+ "=="
89
+ ">"
90
+ ">="
91
+ ">>"
92
+ ">>="
93
+ "|"
94
+ "|="
95
+ "~"
96
+ "@="
97
+ "and"
98
+ "in"
99
+ "is"
100
+ "not"
101
+ "or"
102
+ "is not"
103
+ "not in"
104
+ ] @operator
105
+
106
+ [
107
+ "as"
108
+ "assert"
109
+ "async"
110
+ "await"
111
+ "break"
112
+ "class"
113
+ "continue"
114
+ "def"
115
+ "del"
116
+ "elif"
117
+ "else"
118
+ "except"
119
+ "exec"
120
+ "finally"
121
+ "for"
122
+ "from"
123
+ "global"
124
+ "if"
125
+ "import"
126
+ "lambda"
127
+ "nonlocal"
128
+ "pass"
129
+ "print"
130
+ "raise"
131
+ "return"
132
+ "try"
133
+ "while"
134
+ "with"
135
+ "yield"
136
+ "match"
137
+ "case"
138
+ ] @keyword
@@ -0,0 +1,14 @@
1
+ (module (expression_statement (assignment left: (identifier) @name) @definition.constant))
2
+
3
+ (class_definition
4
+ name: (identifier) @name) @definition.class
5
+
6
+ (function_definition
7
+ name: (identifier) @name) @definition.function
8
+
9
+ (call
10
+ function: [
11
+ (identifier) @name
12
+ (attribute
13
+ attribute: (identifier) @name)
14
+ ]) @reference.call
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,77 @@
1
+ from os import path
2
+ from sysconfig import get_config_var
3
+
4
+ from setuptools import Extension, find_packages, setup
5
+ from setuptools.command.build import build
6
+ from setuptools.command.build_ext import build_ext
7
+ from setuptools.command.egg_info import egg_info
8
+ from wheel.bdist_wheel import bdist_wheel
9
+
10
+
11
+ class Build(build):
12
+ def run(self):
13
+ if path.isdir("queries"):
14
+ dest = path.join(self.build_lib, "tree_sitter_python_orchard", "queries")
15
+ self.copy_tree("queries", dest)
16
+ super().run()
17
+
18
+
19
+ class BuildExt(build_ext):
20
+ def build_extension(self, ext: Extension):
21
+ if self.compiler.compiler_type != "msvc":
22
+ ext.extra_compile_args = ["-std=c11", "-fvisibility=hidden"]
23
+ else:
24
+ ext.extra_compile_args = ["/std:c11", "/utf-8"]
25
+ if path.exists("src/scanner.c"):
26
+ ext.sources.append("src/scanner.c")
27
+ if ext.py_limited_api:
28
+ ext.define_macros.append(("Py_LIMITED_API", "0x030A0000"))
29
+ super().build_extension(ext)
30
+
31
+
32
+ class BdistWheel(bdist_wheel):
33
+ def get_tag(self):
34
+ python, abi, platform = super().get_tag()
35
+ if python.startswith("cp"):
36
+ python, abi = "cp310", "abi3"
37
+ return python, abi, platform
38
+
39
+
40
+ class EggInfo(egg_info):
41
+ def find_sources(self):
42
+ super().find_sources()
43
+ self.filelist.recursive_include("queries", "*.scm")
44
+ self.filelist.include("src/tree_sitter/*.h")
45
+
46
+
47
+ setup(
48
+ packages=find_packages("bindings/python"),
49
+ package_dir={"": "bindings/python"},
50
+ package_data={
51
+ "tree_sitter_python_orchard": ["*.pyi", "py.typed"],
52
+ "tree_sitter_python_orchard.queries": ["*.scm"],
53
+ },
54
+ ext_package="tree_sitter_python_orchard",
55
+ ext_modules=[
56
+ Extension(
57
+ name="_binding",
58
+ sources=[
59
+ "bindings/python/tree_sitter_python_orchard/binding.c",
60
+ "src/parser.c",
61
+ ],
62
+ define_macros=[
63
+ ("PY_SSIZE_T_CLEAN", None),
64
+ ("TREE_SITTER_HIDE_SYMBOLS", None),
65
+ ],
66
+ include_dirs=["src"],
67
+ py_limited_api=not get_config_var("Py_GIL_DISABLED"),
68
+ )
69
+ ],
70
+ cmdclass={
71
+ "build": Build,
72
+ "build_ext": BuildExt,
73
+ "bdist_wheel": BdistWheel,
74
+ "egg_info": EggInfo,
75
+ },
76
+ zip_safe=False
77
+ )