remelange
v0.1.0
Published
Experimental JS to Ocaml compiler
Readme
remelange — experimental JS/TS to OCaml compiler
A minimal JS/TS to OCaml compiler using Tree-sitter.
Installation and usage
Create sample.js
/*
* Calculate the nth Fibonacci number
*/
function fib(n) {
if (n <= 1) {
return n;
} else {
return fib(n - 1) + fib(n - 2);
}
}You can run remelange without installing using npx:
npx remelange sample.js > sample.mlOptionally format the code:
ocamlformat --enable-outside-detected-project sample.mlResult sample.ml:
(* COMPILED WITH remelange *)
(*/*
* Calculate the nth Fibonacci number
*/*)
let rec fib n = if n <= 1 then n else fib n - 1 + (fib n - 2)Generate *.mli file if you want to publish as opam package:
ocamlc -i sample.ml > sample.mlival fib : int -> intFeatures
✅ Recursive function declaration
✅ Respect OCaml naming convention
✅ Supports function calls, variables, expressions
TODO
- [ ] Improve indentation and formatting
- [ ] Support for TS polymorphic variants
