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.

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:

aider screencast

Here we search for "TreeContext" in the source to this tool:

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.2.3.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

grep_ast-0.2.3-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file grep-ast-0.2.3.tar.gz.

File metadata

  • Download URL: grep-ast-0.2.3.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for grep-ast-0.2.3.tar.gz
Algorithm Hash digest
SHA256 64d51946775e0743213c4982acf52d3c9060147bdcdb1dd2f8014ef90d99db4a
MD5 88ccad0d6d893370355cbb7891a00b89
BLAKE2b-256 7ca2e76ff46582b636be1fb13a96dab38303eca0994e00a03655e2c273be64f6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for grep_ast-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1f0dd77abe8bfd2a7b2a841adee9a03523ffa68f2294ac1bc4fba067dc152561
MD5 6dfd7faf6df5f6c21788170bad219d49
BLAKE2b-256 1dc2ec02d0c960f70ab4cbd76917d7c95fcfe7335ad9e09f29a272095c616c07

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