package comby
Install
Dune Dependency
Authors
Maintainers
Sources
md5=617a80e8673c3f811403f09701c08a25
sha512=2f8f82c119210ae0efd7f3eefdd992d6b52655575233dfab74662d9a9854ce4aafcd4fe01dad17ba310e38f28ee1437be2f3c4af4f6952a97bb19e1400fc709a
Description
Comby is a tool designed to make it easy to match change syntax for basically every language. You can think of it like grep or sed, but with added ability to recognize code structures like blocks and expressions (e.g., delimited by braces or parentheses), strings (e.g., delimited by quotes), and so on.
Published: 22 Mar 2021
README
comby
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, usesudo ln -s /usr/lib64/libpcre.so /usr/lib64/libpcre.so.3
. Alternatively, consider building from source.
Windows
Install the Windows Subsystem for Linux and install Ubuntu. Then run
bash <(curl -sL get.comby.dev)
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
Create a new switch if you don't have OCaml installed:
opam init
opam switch create 4.11.0 4.11.0
Install OS dependencies:
Linux:
sudo apt-get install pkg-config libpcre3-dev
Mac:
brew install pkg-config pcre
Then install the library dependencies:
git clone https://github.com/comby-tools/comby
cd comby && opam install . --deps-only -y
Run
eval $(opam env)
Build and test
make
make test
If you want to install
comby
on yourPATH
, run
make install
Dependencies (29)
-
tls
< "1.0.0"
-
toml
>= "6.0.0"
- shell
- pcre
-
yojson
< "2.0.0"
-
ppx_deriving_yojson
>= "3.6.0"
- ppx_deriving
-
patience_diff
>= "v0.14"
-
parany
>= "11"
- cohttp-lwt-unix
-
opium
>= "0.19.0"
- mparser-pcre
- mparser
- lwt_react
- lwt
- core
- conduit-lwt-unix
-
hack_parallel
arch != "arm32" & arch != "arm64"
-
conf-zlib
os = "linux"
- conf-sqlite3
- conf-pkg-config
-
conf-m4
os = "linux"
- conf-libpcre
- conf-libev
- conf-gmp
- conf-autoconf
-
angstrom
>= "0.15.0"
-
ocaml
>= "4.08.1"
-
dune
>= "2.7.0" & < "3.13"
Dev Dependencies (1)
-
bisect_ppx
with-test & dev & >= "2.5.0"
Used by
None
Conflicts
None