Skip to content
Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.ci Fix Azure Pipelines (#2351) Mar 19, 2019
.circleci Check in esy.lock files (#2312) Jan 8, 2019
bspacks Fix bspack Oct 5, 2018
docs Clean up link to docs. Dec 29, 2018
esy.lock Fix Azure Pipelines (#2351) Mar 19, 2019
formatTest Handle single line comments ending with eof (#2353) Mar 19, 2019
miscTests [JSX PPX] More tests (#2099) Jul 31, 2018
pkg [Reason] Cut Build Time In Half. Nov 1, 2017
scripts Housecleaning: move to Dune and fix compilation warnings (#2149) Aug 20, 2018
src Sync back package.ml for 3.4.1 (#2358) Mar 23, 2019
.gitattributes Fix #1518: Handle CRLF with refmt (#2275) Dec 11, 2018
.gitignore Cleanup esy files for esy 0.3.X (#2241) Oct 20, 2018
.merlin merge reason-parser into main source code (#1330) Jul 14, 2017
.npmignore Publish refmt.js before `npm publish` (#1534) Oct 21, 2017
.travis.yml Remove travis email spam Dec 13, 2018
CODE_OF_CONDUCT.md Add `CODE_OF_CONDUCT.md` Jan 25, 2018
FUTURE.md Changelog Oct 5, 2018
HISTORY.md Update HISTORY (#2359) Mar 23, 2019
LICENSE.txt Convert Reason to MIT license. Dec 11, 2017
MAINTAINERS.md Minor typo fix (#2260) Nov 13, 2018
Makefile Outcome Printer Test Infrastructure (#2213) Oct 8, 2018
ORIGINS.md Use with-stdout-to instead of bash to redirect Dec 26, 2017
README.md CI using Azure Pipelines (#2276) Jan 9, 2019
TODO.md
azure-pipelines.yml Fix Azure Pipelines (#2351) Mar 19, 2019
dune Add dune root file which ignores node_modules Oct 20, 2018
dune-project
esy.json Fix Azure Pipelines (#2351) Mar 19, 2019
esy.lock.json Cleanup esy files for esy 0.3.X (#2241) Oct 20, 2018
jbuild-ignore Split rtop into own opam package Jan 27, 2018
package.json Prepare release of 3.4.0 Jan 14, 2019
reason.opam Upgrade the OPAM files to the 2.0 format (#2244) Oct 20, 2018
rtop.opam Fix OPAM 2 warning: `Synopsis should start with a capital and not end… Mar 17, 2019

README.md

Reason

Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems.

Build Status Build Status CircleCI

Getting Started

Community

Roadmap & Contribution

Documentations

Go to https://github.com/reasonml/reasonml.github.io to contribute to the Reason documentation.

Codebase

See the src folder's README.

Installation for Programmatic Usage

If you're not using Reason programmatically, disregard this section and see the Getting Started guide above. This is for using Reason's refmt as a third-party library.

JavaScript API

We expose a refmt.js for you to use on the web. Again, for local development, please use the native refmt that comes with the installation here. It's an order of magnitude faster than the JS version. Don't use the JS version unless you know what you're doing. Let's keep our ecosystem fast please.

Aaaanyways, to install refmt.js: npm install reason.

Here's the API, with pseudo type annotations:

  • parseRE(code: string): astAndComments: parse Reason code
  • parseREI(code: string): astAndComments: parse Reason interface code
  • printRE(data: astAndComments): string: print Reason code
  • printREI(data: astAndComments): string: print Reason interface code
  • parseML(code), parseMLI(code), printML(data), printMLI(data): same as above, but for the OCaml syntax

The type string is self-descriptive. The type astAndComments returned by the parse* functions is an opaque data structure; you will only use it as input to the print* functions. For example:

const refmt = require('reason');

// convert the ocaml syntax to reason syntax
const ast = refmt.parseML('let f a = 1');
const result = refmt.printRE(ast);
console.log(result); // prints `let f = (a) => 1`

The parse* functions potentially throw an error of this shape:

{
  message: string,
  // location can be undefined
  location: {
    // all 1-indexed
    startLine: number, // inclusive
    startLineStartChar: number, // inclusive
    endLine: number, // inclusive
    endLineEndChar: number, // **exclusive**
  }
}

NOTE: refmt.js requires the node module fs, which of course isn't available on the web. If using webpack, to avoid the missing module error, put node: { fs: 'empty' } into webpack.config.js. See https://webpack.js.org/configuration/node/#other-node-core-libraries for more information.

refmt.js is minified for you through Closure Compiler, with an accompanying refmt.map. The size is 2.3MB but don't get fooled; it gzips down to just 345KB. This way, you can carry it around in your own blog and use it to create an interactive refmt playground, without worrying about imposing bandwidth overhead to your readers. Again, keep our ecosystem fast and lean.

Native API

We're spoiled with more APIs on the native side. To use Reason from OPAM as a native library, you have these functions. So:

  • Reason_toolchain.RE.implementation_with_comments
  • Reason_toolchain.RE.interface_with_comments
  • Reason_toolchain.RE.print_interface_with_comments
  • Reason_toolchain.ML.implementation_with_comments
  • etc.

The ML parsing functions might throw Syntaxerr.Error error. The RE parsing functions might throw:

Example usage:

let ast_and_comments =
  Lexing.from_string "let f a => 1"
  |> Reason_toolchain.RE.implementation_with_comments

(* Convert Reason back to OCaml syntax. That'll show these Reason users! *)
let ocaml_syntax =
  Reason_toolchain.ML.print_implementation_with_comments
    Format.str_formatter
    ast_and_comments;
  Format.flush_str_formatter ()

License

See Reason license in LICENSE.txt.

Works that are forked from other projects are under their original licenses.

Credit

The general structure of refmt repo was copied from whitequark's m17n project, including parts of the README that instruct how to use this with the OPAM toolchain. Thank you OCaml!

You can’t perform that action at this time.