Like grep, but uses tree-sitter grammars to search in structures instead of strings
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
Brian Hicks 9e1bb159d4 re-add the rest of the lanaguages 1 month ago
nix update sources 4 months ago
scripts remove tree-grepper-dump 5 months ago
src re-add the rest of the lanaguages 1 month ago
vendor add Typescript support 2 months ago
.envrc add wrapper scripts to make running exploration commands easier 8 months ago
.gitignore cargo init 11 months ago
.gitmodules add Typescript support 2 months ago
Cargo.lock use a global allocator 1 month ago
Cargo.toml use a global allocator 1 month ago
LICENSE add hippocratic license 2 months ago
README.md update roadmap 2 months ago
build.rs add Typescript support 2 months ago
default.nix add libiconv dependency 7 months ago
shell.nix add libiconv dependency 7 months ago

README.md

tree-grepper

Works like grep, but uses tree-sitter to search for structure instead of strings.

Installing

This isn't available packaged anywhere. That's fine, use nix:

nix-env -if https://git.bytes.zone/brian/tree-grepper/archive/main.tar.gz

Usage

Use it like grep (or really, more like ack/ag/pt/rg.)

$ tree-grepper '(import_clause (import) (upper_case_qid)@name)'
src/Main.elm:3:1:Browser
src/Main.elm:4:1:Browser.Navigation
src/main.elm:5:1:Css
...

tree-grepper uses Tree-sitter's s-expressions to find matches.

The binary name might change in the future if we find a better/shorter name. Stay tuned.

Some Terrible Benchmarks

On the first possible working version of tree-grepper:

Command Mean Time (Hyperfine)
tree-grepper '(import_clause)@import' 17.2ms
rg -t elm '^import' 10.3ms
grep -rE '^import' 71.0ms

So this is on rg's level of quickness (which makes sense, as this tool uses their tree walking/gitignoring library.) This tool may get slower as we add features, or faster as I learn more about how to write good Rust.

Roadmap

  • be able to do the thing in "Usage" above
  • output JSON to make embedding in other tools nicer
  • make capturing sub-matches easy (@name in the s-expression syntax)
  • make this tool work on a bunch of languages, not just Elm (which I'm starting with to scratch an itch.)
  • get conditionals working (#eq?, #match? from the tree-sitter docs don't work yet)
  • add tests
  • man page, nice help output, etc
  • produce a query from a language's syntax instead of having to write s-expressions directly
  • real/reproducible benchmarks

License

See LICENSE in the source.