A code rewrite tool for structural search and replace that supports ~every language.
Go to file
2021-11-14 02:00:36 -08:00
.github remove feature request template 2021-05-21 03:32:19 -07:00
dockerfiles remove server things 2021-06-05 14:50:53 -07:00
docs update licenses 2021-02-22 13:00:55 -07:00
lib support reading async from tar 2021-11-14 02:00:36 -08:00
scripts update script test command 2021-05-26 13:04:38 -07:00
src support reading async from tar 2021-11-14 02:00:36 -08:00
test support nested newline-separated rewrites 2021-06-06 00:54:03 -07:00
.dockerignore update dockerfiles 2021-05-21 00:25:17 -07:00
.gitignore Update lwt dependency (#156) 2019-12-25 00:23:44 -07:00
.travis.ocaml.yml Add docker files and scripts and update travis with docker build 2019-06-06 15:51:36 -04:00
.travis.yml restore code coverage, add codecov (#243) 2021-02-21 22:06:01 -07:00
comby-kernel.opam constrain mparser dependency 2021-06-16 17:37:44 -07:00
comby-semantic.opam add yojson dependency 2021-06-15 15:08:57 -07:00
comby.opam support reading async from tar 2021-11-14 02:00:36 -08:00
Dockerfile update dockerfiles 2021-05-12 12:27:33 -07:00
dune support reading async from tar 2021-11-14 02:00:36 -08:00
dune-project fix up dune test dependency for opam 2021-04-07 20:59:42 -07:00
LICENSE Initial code commit 2019-04-09 03:18:31 -04:00
Makefile fix symlink build issue 2021-06-23 00:11:12 -07:00
push-coverage-report.sh restore code coverage, add codecov (#243) 2021-02-21 22:06:01 -07:00
README.md update Linux OS dependency 2021-10-30 13:10:26 -07:00

comby

Apache-2.0 Build Status Coverage Status codecov Downloads Commit Gitter

See the usage documentation.

A short example below shows how comby simplifies matching and rewriting compared to regex approaches like sed.

Comby supports interactive review mode (click here to see it in action).

Need help writing patterns or have other problems? Post them in Gitter.

Install (pre-built binaries)

Mac OS X

  • brew install comby

Ubuntu Linux

  • bash <(curl -sL get.comby.dev)

  • Other Linux distributions: The PCRE library is dynamically linked in the Ubuntu binary. For other distributions like Arch Linux, a fixup is needed: sudo ln -s /usr/lib/libpcre.so /usr/lib/libpcre.so.3. On Fedora, use sudo ln -s /usr/lib64/libpcre.so /usr/lib64/libpcre.so.3. Alternatively, consider building from source.

Windows

Docker

  • docker pull comby/comby
click to expand an example invocation for the docker image

Running with docker on stdin:

docker run -a stdin -a stdout -a stderr -i comby/comby '(:[emoji] hi)' 'bye :[emoji]' lisp -stdin <<< '(👋 hi)'

Or try it live.

Isn't a regex approach like sed good enough?

Sometimes, yes. But often, small changes and refactorings are complicated by nested expressions, comments, or strings. Consider the following C-like snippet. Say the challenge is to rewrite the two if conditions to the value 1. Can you write a regular expression that matches the contents of the two if condition expressions, and only those two? Feel free to share your pattern with @rvtond on Twitter.

if (fgets(line, 128, file_pointer) == Null) // 1) if (...) returns 0
      return 0;
...
if (scanf("%d) %d", &x, &y) == 2) // 2) if (scanf("%d) %d", &x, &y) == 2) returns 0
      return 0;

To match these with comby, all you need to write is if (:[condition]), and specify one flag that this language is C-like. The replacement is if (1). See the live example.

Build from source

  • Install opam. TL;DR do sh <(curl -sL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh)

  • Run this if you don't have OCaml installed (it bootstraps the OCaml compiler):

opam init
opam switch create 4.11.0 4.11.0
  • Run eval $(opam env)

  • Install OS dependencies:

    • Linux: sudo apt-get install autoconf libpcre3-dev pkg-config zlib1g-dev m4 libgmp-dev libev4 libsqlite3-dev

    • Mac: brew install pkg-config gmp pcre libev

  • Then install the library dependencies:

git clone https://github.com/comby-tools/comby
cd comby 
opam install . --deps-only
  • Build and test
make
make test
  • Install comby on your PATH by running
make install