Skip to main content

A tool to grep through the AST of a source file

Project description

grep-ast

Grep soure code files and see matching lines with useful context that show how they fit into the code. See the loops, functions, methods, classes, etc that contain all the matching lines. Get a sense of what's inside a matched class or function definition. You see relevant code from every layer of the abstract syntax tree, above and below the matches.

By default, grep-AST recurses the current directory to search all source code files. It respects .gitignore, so it will usually "do the right thing" in most repos if you just do grep-ast <regex> without specifying any filenames.

You can also invoke grep-ast as gast for convenience.

Grep-AST is built with tree-sitter and tree-sitter-languages. So it supports a lot of popular code languages.

Install

python -m pip install git+https://github.com/paul-gauthier/grep-ast.git

Usage

Basic usage:

grep-ast [pattern] [filenames...]

Full options list:

usage: grep_ast.py [-h] [-i] [--color] [--no-color] [--encoding ENCODING] [--languages] [--verbose]
                   [pat] [filenames ...]

positional arguments:
  pat                  the pattern to search for
  filenames            the files to display

options:
  -h, --help           show this help message and exit
  -i, --ignore-case    ignore case distinctions
  --color              force color printing
  --no-color           disable color printing
  --encoding ENCODING  file encoding
  --languages          print the parsers table
  --verbose            enable verbose output

Examples

Here we search for "encoding" in the source to this tool. These results mainly highlight how grep-ast shows you how the matches fit into the code base.

aider screencast

Here we search for "TreeContext" in the source to this tool. These results mainly highlight how grep-ast helps you understand the contents of a matching named code block (class, function, method, etc).

aider screencast

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

grep_ast-0.3.2.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

grep_ast-0.3.2-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file grep_ast-0.3.2.tar.gz.

File metadata

  • Download URL: grep_ast-0.3.2.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for grep_ast-0.3.2.tar.gz
Algorithm Hash digest
SHA256 d53bc7d25dfefafe77643fec189ab38e3cbd839d546c070a950ebedad82ee164
MD5 c9f860f6fb9d562fe76a7a53ffa1762d
BLAKE2b-256 0b3be3c2102a172253a823876af9d7d7ee626fdc00fbffc589787cd52282b4b1

See more details on using hashes here.

File details

Details for the file grep_ast-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: grep_ast-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for grep_ast-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b7ceb84743983c3f4f5bca82f3374534cd9dbd759792d0dedf5648fedbb6f3fc
MD5 4dffd4bd090ca3a5b5fe68d088f9a98b
BLAKE2b-256 9bdf06c24dead5b362b60b2b1e6aed09464097b08309d1f73c18368b3a91a059

See more details on using hashes here.

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