grep-ast


Namegrep-ast JSON
Version 0.6.1 PyPI version JSON
download
home_pagehttps://github.com/paul-gauthier/grep-ast
SummaryA tool to grep through the AST of a source file
upload_time2025-02-10 22:28:33
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseNone
keywords
VCS
bugtrack_url
requirements tree-sitter-languages tree-sitter pathspec
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://tree-sitter.github.io/tree-sitter/) and
[tree-sitter-languages](https://github.com/grantjenks/py-tree-sitter-languages).
So it supports a lot of popular [code languages](https://github.com/paul-gauthier/grep-ast/blob/main/grep_ast/parsers.py).

## Install

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

## Usage

Basic usage:

```bash
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.

<img src="assets/screenshot-encoding.svg" alt="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).

<img src="assets/screenshot-TreeContext.svg" alt="aider screencast">

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/paul-gauthier/grep-ast",
    "name": "grep-ast",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/ea/5f/3d226aeaa4e788ffe9d028b18f4f29380cb37e6026f0872e5729ac7ac126/grep_ast-0.6.1.tar.gz",
    "platform": null,
    "description": "# grep-ast\n\nGrep soure code files and see matching lines with\nuseful context that show how they fit into the code.\nSee the loops, functions, methods, classes, etc\nthat contain all the matching lines.\nGet a sense of what's inside a matched class or function definition.\nYou see relevant code from every layer of the\nabstract syntax tree, above and below the matches.\n\nBy default, grep-AST recurses the current directory to search all source code files.\nIt respects `.gitignore`, so it will usually \"do the right thing\" in most repos\nif you just do `grep-ast <regex>` without specifying any filenames.\n\nYou can also invoke `grep-ast` as `gast` for convenience.\n\nGrep-AST is built with [tree-sitter](https://tree-sitter.github.io/tree-sitter/) and\n[tree-sitter-languages](https://github.com/grantjenks/py-tree-sitter-languages).\nSo it supports a lot of popular [code languages](https://github.com/paul-gauthier/grep-ast/blob/main/grep_ast/parsers.py).\n\n## Install\n\n```bash\npython -m pip install git+https://github.com/paul-gauthier/grep-ast.git\n```\n\n## Usage\n\nBasic usage:\n\n```bash\ngrep-ast [pattern] [filenames...]\n```\n\nFull options list:\n\n```\nusage: grep_ast.py [-h] [-i] [--color] [--no-color] [--encoding ENCODING] [--languages] [--verbose]\n                   [pat] [filenames ...]\n\npositional arguments:\n  pat                  the pattern to search for\n  filenames            the files to display\n\noptions:\n  -h, --help           show this help message and exit\n  -i, --ignore-case    ignore case distinctions\n  --color              force color printing\n  --no-color           disable color printing\n  --encoding ENCODING  file encoding\n  --languages          print the parsers table\n  --verbose            enable verbose output\n```\n\n## Examples\n\nHere we search for **\"encoding\"** in the source to this tool.\nThese results mainly highlight how `grep-ast`\nshows you how the matches fit into the code base.\n\n<img src=\"assets/screenshot-encoding.svg\" alt=\"aider screencast\">\n\nHere we search for **\"TreeContext\"** in the source to this tool.\nThese results mainly highlight how `grep-ast`\nhelps you understand the *contents* of a matching\nnamed code block (class, function, method, etc).\n\n<img src=\"assets/screenshot-TreeContext.svg\" alt=\"aider screencast\">\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A tool to grep through the AST of a source file",
    "version": "0.6.1",
    "project_urls": {
        "Homepage": "https://github.com/paul-gauthier/grep-ast"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e3cb23f3cd837510fed606b333847753ec2102691f56f15b4e72a39a10145105",
                "md5": "2473d67f1190e5581e3bf7592c749b95",
                "sha256": "57832bb903ebd04e880775946c7a71af5c6a97be9404699caf9d5acc90430bca"
            },
            "downloads": -1,
            "filename": "grep_ast-0.6.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2473d67f1190e5581e3bf7592c749b95",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 12249,
            "upload_time": "2025-02-10T22:28:32",
            "upload_time_iso_8601": "2025-02-10T22:28:32.348960Z",
            "url": "https://files.pythonhosted.org/packages/e3/cb/23f3cd837510fed606b333847753ec2102691f56f15b4e72a39a10145105/grep_ast-0.6.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ea5f3d226aeaa4e788ffe9d028b18f4f29380cb37e6026f0872e5729ac7ac126",
                "md5": "ad31ba7657b5826d6a37215bc4688592",
                "sha256": "b904580a991497afd4135c51a217d001b27086323bc7529673a1dd4003ee24d0"
            },
            "downloads": -1,
            "filename": "grep_ast-0.6.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ad31ba7657b5826d6a37215bc4688592",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12284,
            "upload_time": "2025-02-10T22:28:33",
            "upload_time_iso_8601": "2025-02-10T22:28:33.316971Z",
            "url": "https://files.pythonhosted.org/packages/ea/5f/3d226aeaa4e788ffe9d028b18f4f29380cb37e6026f0872e5729ac7ac126/grep_ast-0.6.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-10 22:28:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "paul-gauthier",
    "github_project": "grep-ast",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "tree-sitter-languages",
            "specs": [
                [
                    ">=",
                    "1.8.0"
                ]
            ]
        },
        {
            "name": "tree-sitter",
            "specs": [
                [
                    "==",
                    "0.21.3"
                ]
            ]
        },
        {
            "name": "pathspec",
            "specs": []
        }
    ],
    "lcname": "grep-ast"
}
        
Elapsed time: 0.53684s