Better HN
topnewbestaskshowjobs
Log inSign up

jgke

2 karma · joined Sep 8, 2018 (8y ago) · 5 submissions

Submissions

comment 2y ago · link · parent

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

comment 5y ago · link · parent

I was doing auditing on a codebase I hadn't seen before, and saw some potential SQL injections SonarQube didn't pick up. Semgrep didn't support the language so I couldn't use that for searching potential injections, and grep just didn't cut it -- so I wrote a tool which can tokenize and parse (almost) any popular language and search it using regex-like patterns.

3.

Show HN: Syntax-searcher – Language-independent CLI for syntax-aware code search(github.com ↗)

1 points · by jgke · 5y ago · 1 comment

4.

Simulating a Pandemic with Elixir(dev.solita.fi ↗)

2 points · by jgke · 6y ago · discuss

5.

Enforcing Database Transactions with Rust(dev.solita.fi ↗)

2 points · by jgke · 7y ago · discuss