I have a function which takes a string of Reason code and transforms it into a string of OCaml code:
let ocaml_from_reason str =
let open Ast_404.Parsetree in
let phrases = Lexing.from_string str |> Reason_toolchain.RE.use_file in
List.iter (function
| Ptop_def str ->
Reason_toolchain.ML.print_implementation_with_comments Format.str_formatter ( str, [] )) phrases;
Format.flush_str_formatter ()
I am trying to parse multiple Reason statements via RE.use_file
and iterate through each statement and print each toplevel_phrase
with ML.print_implementation_with_comment
… which kinda works, but as a result I get:
/* Reason input */
let a = 1 + 1;
let b = a + 2;
Which results in the (faulty) output:
(* OCaml output *)
let a = 1 + 1let b = a + 2
So it drops the ;;
for each toplevel expression… I guess i need to add some functionality to the Reason printer to make this work?