Comby is a tool for searching and changing code structure (comby.dev)
from paequ2@lemmy.today to programming@programming.dev on 12 Aug 07:24
https://lemmy.today/post/35489058

I just used this to update 600 lines, across 33 files! It worked great!

#programming

threaded - newest

backlever@programming.dev on 12 Aug 09:26 collapse

ast-grep is worth checking out too: ast-grep.github.io

paequ2@lemmy.today on 12 Aug 18:12 collapse

Some very quick, superficial differences:

  • ast-grep uses tree-sitter for understanding languages

  • ast-grep is written in Rust

  • ast-grep uses YAML for config

  • ast-grep more normal –flags

  • comby doesn’t use tree-sitter and does it’s own thing… not sure what to think of this approach

  • comby is written in OCaml

  • comby uses TOML for config

  • comby uses -single-dash-flags

  • both have online playgrounds for testing

I personally hate YAML, so it’s comby for me! (For now.)

Also, here’s what Comby says about its approach to matching: comby.dev/docs/faq

Underneath the hood, Comby uses no tree definition, but turns patterns into an executable routine (a language-aware parser) where the tree structure is implicit in this executable routine. In theory, the syntax matched by this routine could dump a serialized parse tree, but this isn’t implemented :-). With this design, Comby sacrifices this ability to recognize many predefined language constructs in order to support a more freeform pattern writing and matching process. This loses precision for deeply recognizing all of a program’s structures, and may fall short of your needs depending on your use case.

backlever@programming.dev on 12 Aug 18:46 collapse

Fair enough. I hate YAML too, but I’m stuck with Python for now and Comby doesn’t handle indentation too well (it’s in their FAQ).

paequ2@lemmy.today on 12 Aug 19:36 collapse

Oh, yeah makes sense. Thankfully, I’m refactoring Go!