1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586openPpxlibtypet=Parsetree.structureleterr=Printer_maker.err(* Note: filename should only be used with .ml files. See reason_toolchain. *)letdefaultImplementationParserForuse_stdinfilename=letopenReason_toolchaininlettheParser,parsedAsML=ifFilename.check_suffixfilename".re"thenRE.implementation_with_comments,falseelseifFilename.check_suffixfilename".ml"thenML.implementation_with_comments,trueelseerr("Cannot determine default implementation parser for filename '"^filename^"'.")intheParser(setup_lexbufuse_stdinfilename),parsedAsML,falseletparse~use_stdinfiletypefilename=let(ast,comments),parsedAsML,parsedAsInterface=matchfiletypewith|`Auto->defaultImplementationParserForuse_stdinfilename|`BinaryReason->Printer_maker.reasonBinaryParseruse_stdinfilename|`Binary->Printer_maker.ocamlBinaryParseruse_stdinfilename|`ML->letlexbuf=Reason_toolchain.setup_lexbufuse_stdinfilenameinletimpl=Reason_toolchain.ML.implementation_with_commentsinimpllexbuf,true,false|`Reason->letlexbuf=Reason_toolchain.setup_lexbufuse_stdinfilenameinletimpl=Reason_toolchain.RE.implementation_with_commentsinimpllexbuf,false,falseinifparsedAsInterfacethenerr"The file parsed does not appear to be an implementation file."else(ast,comments),parsedAsMLletprintprinttypefilenameparsedAsMLoutput_chanoutput_formatter=matchprinttypewith|`BinaryReason->fun(ast,comments)->(* Our special format for interchange between reason should keep the
* comments separate. This is not compatible for input into the
* ocaml compiler - only for input into another version of Reason. We
* also store whether or not the binary was originally *parsed* as an
* interface file.
*)output_valueoutput_chan(Ocaml_common.Config.ast_impl_magic_number,filename,ast,comments,parsedAsML,false)|`Binary->fun(ast,_)->letast=ast|>Reason_syntax_util.(apply_mapper_to_structureremove_stylistic_attrs_mapper)|>Reason_syntax_util.(apply_mapper_to_structurebackport_letopt_mapper)inPpxlib__.Utils.Ast_io.writeoutput_chan{Ppxlib__.Utils.Ast_io.input_name=filename;input_version=Obj.magic(modulePpxlib_ast.Compiler_version:Ppxlib_ast.OCaml_version);ast=Implast}~add_ppx_context:false|`AST->fun(ast,_)->Ocaml_common.Printast.implementationoutput_formatter(Reason_toolchain.To_current.copy_structureast)|`None->fun_->()|`ML->Reason_toolchain.ML.print_implementation_with_commentsoutput_formatter|`Reason->Reason_toolchain.RE.print_implementation_with_commentsoutput_formatter