GithubHelp home page GithubHelp logo

leemgs / comby Goto Github PK

View Code? Open in Web Editor NEW

This project forked from comby-tools/comby

0.0 1.0 0.0 1.8 MB

A tool for structural code search and replace that supports ~every language.

Home Page: https://comby.dev

License: Apache License 2.0

Shell 12.59% C 1.46% OCaml 81.39% Go 0.01% Standard ML 3.87% Makefile 0.12% Dockerfile 0.57%

comby's Introduction

comby

Apache-2.0 Build Status codecov Downloads Commit Gitter

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.netlify.app)

  • 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)'

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

comby's People

Contributors

rvantonder avatar calinou avatar abitrolly avatar indradhanush avatar kit-ty-kate avatar mseri avatar rikhuijzer avatar elimisteve avatar mrnugget avatar cal101 avatar strager avatar vindarel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.