I would like to work with the refmt tool in order to learn more about code is translated between the 3 syntax forms: rescript (res) reasonml (re) and also Ocaml (ml).
First question: How do you install the refmt command? If I install rescript with npm i -g bs-platform I don’t get a refmt command, it’s not linked into a PATH directory like /usr/local/bin.
Do you link it manually?
Second question: refmt --help only mentions the reason format (re). Is there actually a rescript format (res)?
Here is what happens when I try to use the res format:
/usr/local/lib/node_modules/bs-platform/darwin/refmt.exe --parse ml --print res test.ml
refmt: option `--print': invalid value `res', expected one of `ml', `re',
`binary', `binary_reason', `ast' or `none'
# in your local npm project...
npm install --dev bs-platform
npx bsrefmt --help
bsrefmt is the vendored refmt shipped with bs-platform (aka ReScript), and is pinned to version 3.6.
The refmt command doesn’t support ReScript syntax, and the bsc -format cli doesn’t offer any option to print other syntaxes than ReScript (it can parse ml, and re though to print to ReScript). It’s a one-way converter.
If you are interested in how ReScript translates to Reason, you can use the Online Playground and toggle between .re / .res.
Thanks for the replies. My first question is now answered, but for second one, I’m still not sure what to do
If I understand correctly there is no way of translating between Rescript and Ocaml. But what about Rescript and Reasonml? Is that possible at the cli?
You mention bsc -format … but how to use it? There is no --help and I could not find any documentition.
Any help is appreciated in my quest to at least in the end, even indirectly , translate between .res and .ml
As seen in the screenshot posted above, open the playground, click on the settings in the right pane, in the syntax section, press RE for toggling to Reason, RES for toggling to ReScript. The content of the editor should automatically adapt to the selected language.
There we are using the low level apis of the ReScript syntax parser to convert between syntaxes. These are all private apis though, because interfaces are still changing, and we don’t want ppl to run into breaking changes all the time.
edit: if this is not clear, the playground can do certain things that the CLI can not. It was too much effort to make back and forth translation completely lossless. I still added rudimentary conversion to the playground though, because i wanted to help previous Reason users converting ReScript snippets in a quick and accessible way.