package reason
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=65d2f512c98bda432bfb4165c479a7dd6c755ebdf7110a761da3a4b54bf0864c
md5=f3ce46cf6819fc742b74d0e08a27e853
Description
Reason gives OCaml a new syntax that is remniscient of languages like JavaScript. It's also the umbrella project for a set of tools for the OCaml & JavaScript ecosystem.
README
Reason
Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems
Getting Started
Community
Contributing
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:
parseRE(codeString)
: returns an AST + comments info that you'd use for printingparseREI(codeString)
: same, but for interfaceprintRE(astAndComments)
: receives the data structure returned byparseRE
and othersprintREI(astAndComments)
: same, but for interfaceparseML(codeString)
,parseMLI(codeString)
,printML(astAndComments)
,printMLI(astAndComments)
: the OCaml syntax counterparts.
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**
}
}
Example usage:
const refmt = require('refmt')
// convert the ocaml syntax to reason syntax
console.log(refmt.printRE(refmt.parseML('let f a = 1')))
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 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 RE
parsing functions might throw this (docs on Location.t
here). The ML
parsing functions might throw Syntaxerr.Error error
.
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!
Dependencies (8)
-
ocaml-migrate-parsetree
< "2.0.0"
-
topkg
>= "0.9.1"
-
result
= "1.2"
-
merlin-extend
>= "0.3" & < "0.4"
-
utop
>= "1.17"
-
menhir
>= "20170418" & <= "20170712"
-
ocamlfind
build
-
ocaml
>= "4.02" & < "4.06"
Dev Dependencies
None
Used by (20)
- box
-
brotli
>= "2.0.3"
-
dream
>= "1.0.0~alpha2"
-
graphql_ppx
>= "0.7.1"
-
immutable
>= "0.0.6"
-
logs-ppx
< "0.2.0"
-
melange
= "1.0.0"
- melange-atdgen-codec-runtime
- melange-fest
- melange-jest
- melange-moment
- melange-react-dates
-
ocaml-lsp-server
< "1.2.0"
- opam_of_packagejson
- rhythm
-
rtop
>= "3.3.5" & < "3.7.0"
-
sihl
< "0.1.4"
-
spin
< "0.6.0"
- tablecloth-melange
- tyxml-jsx
Conflicts (1)
-
utop
< "1.17"