Git Product home page Git Product logo

ocamlformat's Introduction

OCamlFormat

OCamlFormat is a tool to format OCaml code.

OCamlFormat works by parsing source code using the OCaml compiler's standard parser, deciding where to place comments in the parsetree, and writing the parsetree and comments in a consistent style.

See the source code of OCamlFormat itself and Infer for examples of the styles of code it produces.

Support for converting Reason to OCaml is included in the ocamlformat_reason package, which works by using refmt to parse Reason into an OCaml parsetree.

Limitations

There is currently no single dominant style for OCaml code, and the code produced by OCamlFormat does not attempt to closely mimic any of the common styles. Instead, the focus is on legibility, keeping the common cases reasonably compact while attempting to avoid confusing formatting in corner cases. Improvement is inevitably possible.

Another limitation originates from the treatment of comments by the OCaml parser: they are not included in the parsetree itself, but are only available as a separate list. This means that OCamlFormat must decide where to place the comments within the parsetree. It does this based on source locations of code and comments, as well as using a few heuristics such as whether only white space separates a comment and some code.

A limitation of the current implementation, though not a fundamental issue, is that the object language is largely unimplemented.

Influences

OCamlFormat follows the same basic design as refmt from Reason, but outputs OCaml instead of Reason, and differs in details.

Installation

OCamlFormat can be installed with opam:

opam pin add ocamlformat https://github.com/ocaml-ppx/ocamlformat.git

and for the Reason converter:

opam pin add ocamlformat_reason https://github.com/ocaml-ppx/ocamlformat.git

Alternately, see ocamlformat.opam and ocamlformat_reason.opam for manual build instructions.

Documentation

OCamlFormat is documented in its man page and through its internal help:

  • ocamlformat --help
  • man ocamlformat

Community

See CONTRIBUTING for how to help out.

License

OCamlFormat is MIT-licensed.

Note that building OCamlFormat will download and patch a module of the OCaml standard library, which is licensed under LGPL 2.1 + linking exception.

ocamlformat's People

Contributors

hcarty avatar jberdine avatar kit-ty-kate avatar mroch avatar octachron 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.