- Category
- Developer Tools
- Rank
- No. 731Tools index
- Pricing
- Open Source
- Type
- TOOL
- Builder
- aider-ai
- GitHub
- 365 stars
- Date
About
Grep through source code and see useful AST context around matching lines. Powers Aider's code understanding.
What it does
grep-ast searches each source line with a regular expression, then parses the file to reveal the surrounding program structure. Its compact output keeps matches, nearby lines, enclosing scope headers, selected child structure, and scope endings while collapsing omitted regions.
Why it's ranked here
This is a focused bridge between plain text search and full code navigation. Tree-sitter support covers many languages, directory traversal honors ignore rules by default, and output stays compact. The narrow interface and light test coverage make it better as a practical utility than a comprehensive analysis platform.
What's good
It works with familiar regular expressions and needs little setup. Automatic recursion and ignore-rule handling suit real repositories. Color, line numbers, case-insensitive matching, encoding selection, and a language listing make the command useful both interactively and in piped workflows.
Tradeoffs
Matching remains line-oriented text search, so syntax guides presentation rather than query semantics. Language selection depends on filenames and extensions, including ambiguous mappings such as MATLAB taking precedence over Objective-C. Unknown languages and decoding failures are skipped without normal user-facing diagnostics. The supplied tests only verify parser availability.
How to use it well
Use it when engineers or coding agents know a textual clue but need enough structural context to understand each hit quickly. It fits repository exploration, call-site inspection, and targeted reading before editing. It does not replace symbol-aware queries, reference tracking, type analysis, or an interactive language server.
Technical notes+
setup.py packages the Python project with setuptools and registers grep-ast and gast console scripts at grep_ast.main:main. grep_ast/main.py handles argparse, recursive traversal, .gitignore matching through pathspec, decoding, and output. grep_ast/grep_ast.py implements TreeContext: regular expressions find lines, Tree-sitter nodes populate scope and header tables, and context selection adds parents, bounded child material, margins, scope endings, and gap markers. grep_ast/parsers.py maps filenames and extensions to grammars, with a larger table when tree-sitter-language-pack is active. grep_ast/tsl.py retains a fallback import for tree_sitter_languages. tests/test_parsers.py checks that every configured parser can be obtained.
Observed
- License
- Apache License 2.0
- Primary language
- Python
- Packaging
- Setuptools package with dependencies declared in requirements.txt
- Install surface
- README documents installation from the Git repository through pip
- Interfaces
- Two CLI commands plus an importable TreeContext library class
- Core dependencies
- tree-sitter-language-pack and pathspec
- Language support
- Parser selection covers many source and configuration formats by filename or extension
- Test structure
- The provided repository tree includes one parser-focused test module
Read from README.md, setup.py, requirements.txt, grep_ast/tsl.py, grep_ast/main.py, grep_ast/dump.py, grep_ast/parsers.py, grep_ast/__init__.py, grep_ast/grep_ast.py, tests/test_parsers.py, .flake8, LICENSE.txt, MANIFEST.in, .pre-commit-config.yaml, scripts/screenshot.sh.
What it can do
Search for text patterns in source code files
Source code files and search pattern/regex → Matching lines with line numbers
Display AST context around matching lines
Source code files with matches → Abstract syntax tree structure around matched code
Parse source code into AST representation
Source code files → Abstract syntax tree structure
Extract function and class definitions containing matches
Source code files and search pattern → Code blocks showing complete function/class context
Analyze code structure and relationships
Source code files → Structured code understanding data for AI tools
Tags
Tech Stack
Comments (0)
No comments yet
Editorially curated, with community endorsements as a secondary signal. Corrections welcome.
