Comby Documentation
repository·master·Indexed 25 days ago
https://github.com/comby-tools/combyComby is a tool for structural code search and replace that understands nested expressions, comments, and strings for complex refactorings. The documentation covers installation across macOS, Linux, Windows, and Docker, building from source using OCaml, and detailed match semantics including weak delimiter matching and alphanumeric detection. It also includes details on the Comby rule language grammar and vendored libraries such as Patdiff (a patience diff implementation) and CamlZip.
What's inside Comby
- Patdiff is an OCaml implementation of Bram Cohen's patience diff algorithm. It is designed for comparing code and configuration files, offering word-level refinement and several specialized features for developers.
Understand alphanumeric delimiter detection
masterComby can match alphanumeric delimiters (like
forordef) at the character level. To prevent false positives (e.g., matching theforinside the wordbefore), Comby uses look-ahead and prefix consumption:- Prefix: Comby expects whitespace, punctuation delimiters (like
)), or the start of a line before an alphanumeric delimiter. The prefix is consumed to advance the state. - Suffix: Comby expects whitespace, punctuation (like
;or.), or the end of a line after the delimiter. The suffix is checked as a look-ahead but is not consumed, allowing for consecutive delimiters likebegin beginseparated by a single space.
- Prefix: Comby expects whitespace, punctuation delimiters (like
Use weak delimiter matching for unique delimiters
masterComby supports weak delimiter matching for unique delimiters (e.g.,
(),[]). In strict matching, delimiters must be balanced. In weak matching, a hole like(:[1])can match any character except the closing delimiter (e.g.,(])would match). This can provide a performance benefit because Comby does not need to ensure well-balancedness for other delimiter types.Note: Weak delimiter matching only works for unique delimiters. It cannot be used for delimiters that share a closing token, such as Ruby's
endwhich closes bothclassanddef.Install Comby on Windows
masterInstall the Windows Subsystem for Linux (WSL) and install Ubuntu. Then run the installation script within the Ubuntu environment.
bash <(curl -sL get.comby.dev)Install Comby on Mac OS X
masterInstall Comby using Homebrew.
brew install combyUse the 'attempt' operator for backtracking in choice sequences
masterWhen using the choice operator
<|>in a parse sequence, if the first branch succeeds in its initial steps but fails later, the entire parser fails and the second branch is never tried.To enable backtracking—allowing the parser to try the second branch if the first branch fails halfway through—wrap the branches in
attempt @@.This is critical for:
- Disambiguating holes like
:[1]and:[[1]]. - Handling alphanumeric sequences (like
beginorstruct) where you need to verify if a sequence initiates a balanced delimiter match.
- Disambiguating holes like
Build Comby from source
masterTo build Comby from source, you must have
opam(OCaml package manager) installed and an OCaml 5 switch configured.1. Setup OCaml environment
opam init opam switch create 5.1.0 5.1.0 eval $(opam env)2. Install OS dependencies
- Linux:
sudo apt install autoconf libpcre3-dev pkg-config zlib1g-dev m4 libgmp-dev libev4 libsqlite3-dev - Mac:
brew install pkg-config gmp pcre libev
3. Install library dependencies and build
git clone https://github.com/comby-tools/comby cd comby opam install . --deps-only make make test4. Install to PATH
make install- Linux:
Install Comby via Docker
masterPull the official Comby Docker image.
docker pull comby/combyInstall Comby on Ubuntu Linux
masterInstall Comby on Ubuntu using the provided installation script.
bash <(curl -sL get-comby.netlify.app)Overview of CamlZip capabilities
masterCamlZip is an Objective Caml library that provides functions for reading from and writing to compressed files. It supports the following formats:
- ZIP
- GZIP
- Java JAR files
For detailed API documentation, refer to the comments in
zip.mliandgzip.mliwithin the library source.Install the CamlZip library
masterTo install CamlZip, you must first ensure you have the following requirements:
- Objective Caml 4.02 or higher.
- The
Findlib/ocamlfindlibrary manager. - The
ZlibC library (version 1.1.3 or higher). Ensurelibz.aorlibz.sois available on your system.
Installation steps:
- Open the
Makefileand edit the three variables at the beginning to match your system'sZlibinstallation location (defaults are typically sufficient for Linux). - Run
make allto build the library. - If the Objective Caml native-code compiler (
ocamlopt) is available, runmake allopt. - Run
make install(usingsudoif necessary) to install the library viaocamlfind.
# Example installation sequence make all make allopt make installInstall Comby on other Linux distributions
masterThe Ubuntu binary is dynamically linked to the PCRE library. For other distributions, you may need to create a symbolic link for PCRE to work:
- Arch Linux:
sudo ln -s /usr/lib/libpcre.so /usr/lib/libpcre.so.3 - Fedora:
sudo ln -s /usr/lib64/libpcre.so /usr/lib64/libpcre.so.3
- Arch Linux: