Skip to main content

Run Tree Sitter queries from the command line

Project description

TSQuery

Run Tree Sitter queries from the command line.

Installation

pip install tsquery

Usage

Parsers (.so files) should be installed somewhere in $XDG_DATA_HOME or $XDG_DATA_DIRS. Use the official Tree Sitter CLI tool to compile a grammar to parser source.

For example, this command prints the names of functions defined in a toy Python program:

# Write a toy Python program
cat > example.py <<EOF
def baz():
    return 1

def foo(bar):
    if bar:
        baz()
EOF

# Run a query against it
tsquery '(function_definition name: (identifier) @func.name)' example.py

See also example.sh in this repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tsquery-0.1.1.tar.gz (5.9 kB view hashes)

Uploaded Source

Built Distribution

tsquery-0.1.1-py3-none-any.whl (19.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page