Do suggest if there are better approaches here.
Hey, would you expand on what you’re trying to do? Convert some Purescript code to ReScript?
So we have a large frontend code base which is currently written in Purescript (https://www.purescript.org/). Another very similar project is built in Rescript. We wanted to unify these two projects and wanted to move from two languages to one in the company. Reason for this change are many but right now we have decided to move our Purescript codebase to Rescript. To do this we extracted the CST of Purescript whose compiler is written in Haskell (https://github.com/purescript/purescript/blob/master/src/Language/PureScript/CST/Types.hs). Once we have the AST we will transform it to print Rescript code. Now wanted to understand how to extract AST/CST of Rescript so that we can write code mapping between both programming language.
In short we are writing transpiler which will convert a Purescript React code to Rescript code. We want to transpile and not handwrite the implementation because it is always a moving target for such large code bases. Features get added faster than we can move things and also we want to compare things side by side old and new programming language.
For starters, you can call the compiler directly on a
.res file to get the AST:
npx bsc -dparsetree MyFile.res
Sounds crazy what you want to do, but nevertheless, wish you much success!
EDIT: It reminds me of philip2, an Elm to OCaml compiler
I think it’s possible to use the OCaml ast and then convert it to ReScript.
It might be easier to generare .res files as strings directly than trying to convert one AST to another kind of AST.
Most of the difficulties will be of a semantic nature though – unrelated to the representation used.
We decided to go ahead with this for now.