3 ms·
Cool! Like many others here, I also relatively recently created a similar tool called syntax-searcher or syns[1] which is focused on searching, and doesn't supp
by jgke 3y ago
Cool! Like many others here, I also relatively recently created a similar tool called syntax-searcher or syns[1] which is focused on searching, and doesn't support replacing. It's implemented with a hand-written tokenizer/parser rather than using eg. tree-sitter. It works best with (mostly) context-free languages, but it doesn't crash or anything with Python and the like. At least I find its query syntax better than the alternatives, but it's probably because I wrote it :)
I find the best uses for it being answering questions like 'how is this function called' and 'what is this struct's definition':
# find struct definition
$ syns 'struct Span {}'
[./src/psi.rs:21-26]
pub struct Span {
/// Starting byte index of the span.
pub lo: usize,
/// End byte index of the span.
pub hi: usize,
}
# How is this function called?
$ syns 'ast_match()'
[./src/query.rs:91] if &op.ty == op1 && self.ast_match(content1, &[\*start]).is_some() {
[./src/query.rs:125] .flat_map(move |tts| self.ast_match(tts, &[self.machine.initial]))
It's also pretty fast for most repositories, as an extreme case with the kernel source:
time syns 'kmalloc()' > /dev/null
syns 'kmalloc()' > /dev/null 61,82s user 0,90s system 99% cpu 1:02,73 total
Most other repositories print all results pretty much instantly.
[1] https://github.com/jgke/syntax-searcher https://github.com/jgke/syntax-searcher