Coder Social home page Coder Social logo

grep-ast's Introduction

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

grep-ast's People

Contributors

h0x91b avatar paul-gauthier avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.