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.
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).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file grep_ast-0.3.1.tar.gz
.
File metadata
- Download URL: grep_ast-0.3.1.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44fb0519536c4b8dca2793ed87ea794ad4d32f4612737306f7a07e9501e5580f |
|
MD5 | 414e30cfecff1b878bc201f6e939da54 |
|
BLAKE2b-256 | 555fe954ee77db17cfeea8561045d26c0d06ea95892ae7a20186a48fe1d658f6 |
File details
Details for the file grep_ast-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: grep_ast-0.3.1-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a0a09b1c6b0a563eb7ef0fd1424c56e1d58ff24b06ac4d3fde3dcb2c3b67a5c |
|
MD5 | a5d9b9910e1c9556ded8cffd5ae66577 |
|
BLAKE2b-256 | 49e78cf1a9b20c48af8c919375717825957664b8ba37af7ba322ee7a90784b81 |