Like grep, but uses tree-sitter grammars to search in structures instead of strings
 
 
 
Go to file
Brian Hicks 9e1bb159d4 re-add the rest of the lanaguages 2021-08-16 08:05:59 -05:00
nix update sources 2021-06-11 09:50:28 -05:00
scripts remove tree-grepper-dump 2021-04-27 15:52:15 -05:00
src re-add the rest of the lanaguages 2021-08-16 08:05:59 -05:00
vendor add Typescript support 2021-07-26 10:13:35 -05:00
.envrc add wrapper scripts to make running exploration commands easier 2021-01-15 16:35:22 -06:00
.gitignore cargo init 2020-11-06 08:09:12 -06:00
.gitmodules add Typescript support 2021-07-26 10:13:35 -05:00
Cargo.lock use a global allocator 2021-08-15 05:50:34 -05:00
Cargo.toml use a global allocator 2021-08-15 05:50:34 -05:00
LICENSE add hippocratic license 2021-07-26 08:23:10 -05:00
README.md update roadmap 2021-07-26 08:23:10 -05:00
build.rs add Typescript support 2021-07-26 10:13:35 -05:00
default.nix add libiconv dependency 2021-03-08 10:10:50 -06:00
shell.nix add libiconv dependency 2021-03-08 10:10:50 -06:00

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.