1212
1313
1414let process_interface_file ppf name =
15- Js_implementation. interface ppf name (Compenv. output_prefix name)
15+ Js_implementation. interface ppf name
16+ ~parser: Pparse_driver. parse_interface
17+ (Compenv. output_prefix name)
1618let process_implementation_file ppf name =
17- Js_implementation. implementation ppf name (Compenv. output_prefix name)
19+ Js_implementation. implementation ppf name
20+ ~parser: Pparse_driver. parse_implementation
21+ (Compenv. output_prefix name)
1822
1923
2024let setup_reason_context () =
2125 Js_config. is_reason := true ;
22- Clflags. preprocessor := None ;
23- (* FIX #3988 - Don't run pp-flags on Reason files to make napkin easier*)
2426 Lazy. force Super_main. setup;
2527 Lazy. force Reason_outcome_printer_main. setup
2628
27- let reason_pp ~sourcefile =
29+
30+ let handle_reason (type a ) (kind : a Ml_binary.kind ) sourcefile ppf opref =
2831 setup_reason_context () ;
29- Ast_reason_pp. pp sourcefile
32+ let tmpfile = Ast_reason_pp. pp sourcefile in
33+ (match kind with
34+ | Ml_binary. Ml ->
35+ Js_implementation. implementation
36+ ~parser: (fun file_in ->
37+ let in_chan = open_in_bin file_in in
38+ let ast = Ml_binary. read_ast Ml in_chan in
39+ close_in in_chan; ast
40+ )
41+ ppf tmpfile opref
42+
43+ | Ml_binary. Mli ->
44+ Js_implementation. interface
45+ ~parser: (fun file_in ->
46+ let in_chan = open_in_bin file_in in
47+ let ast = Ml_binary. read_ast Mli in_chan in
48+ close_in in_chan; ast
49+ )
50+ ppf tmpfile opref ; );
51+ Ast_reason_pp. clean tmpfile
3052
53+
3154type valid_input =
3255 | Ml
3356 | Mli
@@ -78,16 +101,9 @@ let process_file ppf sourcefile =
78101 | _ -> raise(Arg. Bad (" don't know what to do with " ^ sourcefile)) in
79102 let opref = Compenv. output_prefix sourcefile in
80103 match input with
81- | Re ->
82- setup_reason_context () ;
83- let tmpfile = reason_pp ~sourcefile in
84- Js_implementation. implementation ppf tmpfile opref ;
85- Ast_reason_pp. clean tmpfile
104+ | Re -> handle_reason Ml sourcefile ppf opref
86105 | Rei ->
87- setup_reason_context () ;
88- let tmpfile = (reason_pp ~sourcefile ) in
89- Js_implementation. interface ppf tmpfile opref ;
90- Ast_reason_pp. clean tmpfile
106+ handle_reason Mli sourcefile ppf opref
91107 | Reiast
92108 ->
93109 setup_reason_context () ;
@@ -97,9 +113,13 @@ let process_file ppf sourcefile =
97113 setup_reason_context () ;
98114 Js_implementation. implementation_mlast ppf sourcefile opref
99115 | Ml ->
100- Js_implementation. implementation ppf sourcefile opref
116+ Js_implementation. implementation
117+ ~parser: Pparse_driver. parse_implementation
118+ ppf sourcefile opref
101119 | Mli ->
102- Js_implementation. interface ppf sourcefile opref
120+ Js_implementation. interface
121+ ~parser: Pparse_driver. parse_interface
122+ ppf sourcefile opref
103123 | Mliast
104124 -> Js_implementation. interface_mliast ppf sourcefile opref
105125 | Mlast
0 commit comments