Skip to main content

Fork of grantjenks/py-tree-sitter-languages.

Binary Python wheels for all tree sitter languages.

py-tree-sitter is a fantastic library that provides Python bindings for the even more fantastic tree-sitter parsing library.

py-tree-sitter-languages provides binary Python wheels for all tree sitter languages. The binary wheels remove the need to download and compile support for individual languages.

Install

pip install tree_sitter_languages

Source installs are not supported. To see how the binary wheels are built, look at:

  1. setup.py — Python package setup.

  2. repos.txt — Text file that contains a list of included language repositories and their commit hashes.

  3. build.py — Python script to download and build the language repositories.

  4. .github/workflows/release.yml — GitHub action to invoke cibuildwheel and release to PyPI.

Usage

from tree_sitter_languages import get_language, get_parser

language = get_language('python')
parser = get_parser('python')

That’s the whole API!

Refer to py-tree-sitter for the language and parser API. Notice the Language.build_library(...) step can be skipped! The binary wheel includes the language binary.

Demo

Want to know something crazy? Python lacks multi-line comments. Whhaaa!?!

It’s really not such a big deal. Instead of writing:

"""
My awesome
multi-line
comment.
"""

Simply write:

# My awesome
# multi-line
# comment.

So multi-line comments are made by putting multiple single-line comments in sequence. Amazing!

Now, how to find all the strings being used as comments?

Start with some example Python code:

example = """
#!shebang
# License blah blah (Apache 2.0)
"This is a module docstring."

a = 1

'''This
is
not
a
multiline
comment.'''

b = 2

class Test:
    "This is a class docstring."

    'This is bogus.'

    def test(self):
        "This is a function docstring."

        "Please, no."

        return 1

c = 3
"""

Notice a couple things:

  1. Python has module, class, and function docstrings that bare a striking resemblance to the phony string comments.

  2. Python supports single-quoted, double-quoted, triple-single-quoted, and triple-double-quoted strings (not to mention prefixes for raw strings, unicode strings, and more).

Creating a regular expression to capture the phony string comments would be exceedingly difficult!

Enter tree-sitter:

from tree_sitter_languages import get_language, get_parser

language = get_language('python')
parser = get_parser('python')

Tree-sitter creates an abstract syntax tree (actually, a concrete syntax tree) and supports queries:

tree = parser.parse(example.encode())
node = tree.root_node
print(node.sexp())

Look for statements that are a single string expression:

stmt_str_pattern = '(expression_statement (string)) @stmt_str'
stmt_str_query = language.query(stmt_str_pattern)
stmt_strs = stmt_str_query.captures(node)
stmt_str_points = set(
    (node.start_point, node.end_point) for node, _ in stmt_strs
)
print(stmt_str_points)

Now, find those statement string expressions that are actually module, class, or function docstrings:

doc_str_pattern = """
    (module . (comment)* . (expression_statement (string)) @module_doc_str)

    (class_definition
        body: (block . (expression_statement (string)) @class_doc_str))

    (function_definition
        body: (block . (expression_statement (string)) @function_doc_str))
"""
doc_str_query = language.query(doc_str_pattern)
doc_strs = doc_str_query.captures(node)
doc_str_points = set(
    (node.start_point, node.end_point) for node, _ in doc_strs
)

With the set of string expression statements and the set of docstring statements, the locations of all phony string comments is:

comment_strs = stmt_str_points - doc_str_points
print(sorted(comment_strs))

License

Copyright 2022 Grant Jenks

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

The project also includes the following other projects distributed in binary form:

Metadata

Release files for pantoufle-tree-sitter-languages 1.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for pantoufle-tree-sitter-languages 1.6.0
File
pantoufle_tree_sitter_languages-1.6.0-cp311-cp311-musllinux_1_1_x86_64.whl CPython 3.11 CPython 3.11 Linux musl 1.1+ x86-64 Details
pantoufle_tree_sitter_languages-1.6.0-cp311-cp311-musllinux_1_1_i686.whl CPython 3.11 CPython 3.11 Linux musl 1.1+ x86-32 Details
pantoufle_tree_sitter_languages-1.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
pantoufle_tree_sitter_languages-1.6.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-32 Details
pantoufle_tree_sitter_languages-1.6.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
pantoufle_tree_sitter_languages-1.6.0-cp311-cp311-macosx_10_9_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.9+ x86-64 Details
pantoufle_tree_sitter_languages-1.6.0-cp310-cp310-musllinux_1_1_x86_64.whl CPython 3.10 CPython 3.10 Linux musl 1.1+ x86-64 Details
pantoufle_tree_sitter_languages-1.6.0-cp310-cp310-musllinux_1_1_i686.whl CPython 3.10 CPython 3.10 Linux musl 1.1+ x86-32 Details
pantoufle_tree_sitter_languages-1.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
pantoufle_tree_sitter_languages-1.6.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-32 Details
pantoufle_tree_sitter_languages-1.6.0-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details
pantoufle_tree_sitter_languages-1.6.0-cp310-cp310-macosx_10_9_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.9+ x86-64 Details

Total release size: 69.0 MB

Release files / pantoufle_tree_sitter_languages-1.6.0-cp311-cp311-musllinux_1_1_x86_64.whl

Download URL pantoufle_tree_sitter_languages-1.6.0-cp311-cp311-musllinux_1_1_x86_64.whl
Size 5.9 MB
Tags CPython 3.11 Linux musl 1.1+ x86-64
SHA-256 checksum
How to use checksums
a7acdd9f5b63202db18e9fbf813a64344c7c30db9065666cea6cdec5faa975d3
BLAKE2b-256 checksum
How to use checksums
656634ea4a7726660a455de6aca904e7d92b705b4101960df90870945bf587eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / pantoufle_tree_sitter_languages-1.6.0-cp311-cp311-musllinux_1_1_i686.whl

Download URL pantoufle_tree_sitter_languages-1.6.0-cp311-cp311-musllinux_1_1_i686.whl
Size 6.1 MB
Tags CPython 3.11 Linux musl 1.1+ x86-32
SHA-256 checksum
How to use checksums
476ff89c536f028a2537a7947250aab1a9924f9a8a4ea9f00f185da2ad38b980
BLAKE2b-256 checksum
How to use checksums
c5441a7f996c5e286884220612159f388ede291d087145ce22ff71e8d54d1241
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / pantoufle_tree_sitter_languages-1.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pantoufle_tree_sitter_languages-1.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 5.3 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
33f7fb86cfb4f9d0007309bcc6d296c78462a144fb3c59034b7bdb49d45c4ccd
BLAKE2b-256 checksum
How to use checksums
86dce0c534d69e8e34a0480ec2d075bf235a4ad96d4c1f1a6b1da28133838cd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / pantoufle_tree_sitter_languages-1.6.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL pantoufle_tree_sitter_languages-1.6.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl
Size 5.4 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-32
SHA-256 checksum
How to use checksums
bd622108a4cad6549d8a8bd6138b0fca5d4302713795bbcb8f08b790fbe2bf8b
BLAKE2b-256 checksum
How to use checksums
ecf86a6290a9b8408e3c26258b74d76412e97ee4ec90f7e69dfbcae58b17c6f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / pantoufle_tree_sitter_languages-1.6.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL pantoufle_tree_sitter_languages-1.6.0-cp311-cp311-macosx_11_0_arm64.whl
Size 6.1 MB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
bbd8a49718434a77bd3149727ffdaae6ec23493572597df9b9cb59df8e91bfce
BLAKE2b-256 checksum
How to use checksums
9b2307755eea2cff3f02dc3303974f85e068c0557558fb6eb021a18be2c5fd6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / pantoufle_tree_sitter_languages-1.6.0-cp311-cp311-macosx_10_9_x86_64.whl

Download URL pantoufle_tree_sitter_languages-1.6.0-cp311-cp311-macosx_10_9_x86_64.whl
Size 5.6 MB
Tags CPython 3.11 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
910608142d8c5d0385eb23ba7a80c1b4410512a102266344ff42d3b7dd381795
BLAKE2b-256 checksum
How to use checksums
fa8fa4ff851b97d05a723cf8caf7386dfac1efd4bdb27525e372869572268bd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / pantoufle_tree_sitter_languages-1.6.0-cp310-cp310-musllinux_1_1_x86_64.whl

Download URL pantoufle_tree_sitter_languages-1.6.0-cp310-cp310-musllinux_1_1_x86_64.whl
Size 5.9 MB
Tags CPython 3.10 Linux musl 1.1+ x86-64
SHA-256 checksum
How to use checksums
6fae43b37a930dd468affe19cda1cba03c4fa50d7623854b8f28a2bb2ea2ef83
BLAKE2b-256 checksum
How to use checksums
794c996cdc4ad1d92fc27a295d3e23f3fb4e9747aa69b60d0c4fb393211db044
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / pantoufle_tree_sitter_languages-1.6.0-cp310-cp310-musllinux_1_1_i686.whl

Download URL pantoufle_tree_sitter_languages-1.6.0-cp310-cp310-musllinux_1_1_i686.whl
Size 6.1 MB
Tags CPython 3.10 Linux musl 1.1+ x86-32
SHA-256 checksum
How to use checksums
128ddaaa8af5ed772bf76c5431a37107b8a421d2a4e19790d36ea3530c7cedf7
BLAKE2b-256 checksum
How to use checksums
fab8e082e058ffd8b2aeca976424fb946d194b3b066f2647dee106b048716f3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / pantoufle_tree_sitter_languages-1.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pantoufle_tree_sitter_languages-1.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 5.3 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
d091d156b93bb9225f4e3b3eccf1f6b1dc0ce62cbe234a0abe4c5a4f4ffe2e28
BLAKE2b-256 checksum
How to use checksums
6c240fcbde07b120942784340c3108a014b6e348e148afd72fc45521a33d5d9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / pantoufle_tree_sitter_languages-1.6.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL pantoufle_tree_sitter_languages-1.6.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl
Size 5.4 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-32
SHA-256 checksum
How to use checksums
8d45a9dc2fe36fb16cd31929b684346ac9810218d8c547640236d04df09acc61
BLAKE2b-256 checksum
How to use checksums
c2bf52b4e6b0103a041261497e5ac1695ebdd3b94c62c98bd5c2be5403eecb90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / pantoufle_tree_sitter_languages-1.6.0-cp310-cp310-macosx_11_0_arm64.whl

Download URL pantoufle_tree_sitter_languages-1.6.0-cp310-cp310-macosx_11_0_arm64.whl
Size 6.1 MB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9bcdaccdafe523a92df673114a5713e49152379206d34c909ec083ec1ff1f12a
BLAKE2b-256 checksum
How to use checksums
8196f299f2a9a413015bde6ae9c42baf7cab0ad78a3a289b8a1bcab0314b6b85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / pantoufle_tree_sitter_languages-1.6.0-cp310-cp310-macosx_10_9_x86_64.whl

Download URL pantoufle_tree_sitter_languages-1.6.0-cp310-cp310-macosx_10_9_x86_64.whl
Size 5.6 MB
Tags CPython 3.10 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
606686f527be49c10bc457137426df9e0e3010ba95ba833f7d3116fc2fb957fa
BLAKE2b-256 checksum
How to use checksums
6cc51bea5840356ab1898f608bdc51cb25ba8a4c40e122e5898f6fa8cd7c5440
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release history Release notifications | RSS feed

This release

1.6.0 This release

12 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page