You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
2 years ago | |
---|---|---|
nix | 2 years ago | |
scripts | 2 years ago | |
src | 2 years ago | |
vendor | 2 years ago | |
.envrc | 3 years ago | |
.gitignore | 3 years ago | |
.gitmodules | 2 years ago | |
Cargo.lock | 2 years ago | |
Cargo.toml | 2 years ago | |
LICENSE | 2 years ago | |
README.md | 2 years ago | |
build.rs | 2 years ago | |
default.nix | 3 years ago | |
shell.nix | 3 years 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.