Skip to content

Commit 785e32b

Browse files
committed
use shared type
1 parent 753de50 commit 785e32b

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

jscomp/core/pparse_driver.ml

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,15 @@ let remove_preprocessed inputfile =
3131
None -> ()
3232
| Some _ -> Misc.remove_file inputfile
3333

34-
type 'a ast_kind =
35-
| Structure : Parsetree.structure ast_kind
36-
| Signature : Parsetree.signature ast_kind
3734

38-
let magic_of_kind : type a . a ast_kind -> string = function
39-
| Structure -> Config.ast_impl_magic_number
40-
| Signature -> Config.ast_intf_magic_number
35+
let magic_of_kind : type a . a Ml_binary.kind -> string = function
36+
| Ml_binary.Ml -> Config.ast_impl_magic_number
37+
| Ml_binary.Mli -> Config.ast_intf_magic_number
4138

4239
(* Note: some of the functions here should go to Ast_mapper instead,
4340
which would encapsulate the "binary AST" protocol. *)
4441

45-
let write_ast (type a) (kind : a ast_kind) fn (ast : a) =
42+
let write_ast (type a) (kind : a Ml_binary.kind) fn (ast : a) =
4643
let oc = open_out_bin fn in
4744
output_string oc (magic_of_kind kind);
4845
output_value oc (!Location.input_name : string);
@@ -74,7 +71,7 @@ let apply_rewriter kind fn_in ppx =
7471
end;
7572
fn_out
7673

77-
let read_ast (type a) (kind : a ast_kind) fn : a =
74+
let read_ast (type a) (kind : a Ml_binary.kind) fn : a =
7875
let ic = open_in_bin fn in
7976
try
8077
let magic = magic_of_kind kind in
@@ -102,7 +99,7 @@ let apply_rewriters_str ?(restore = true) ~tool_name ast =
10299
| ppxs ->
103100
ast
104101
|> Ast_mapper.add_ppx_context_str ~tool_name
105-
|> rewrite Structure ppxs
102+
|> rewrite Ml ppxs
106103
|> Ast_mapper.drop_ppx_context_str ~restore
107104

108105
let apply_rewriters_sig ?(restore = true) ~tool_name ast =
@@ -111,15 +108,15 @@ let apply_rewriters_sig ?(restore = true) ~tool_name ast =
111108
| ppxs ->
112109
ast
113110
|> Ast_mapper.add_ppx_context_sig ~tool_name
114-
|> rewrite Signature ppxs
111+
|> rewrite Mli ppxs
115112
|> Ast_mapper.drop_ppx_context_sig ~restore
116113

117114
let apply_rewriters ?restore ~tool_name
118-
(type a) (kind : a ast_kind) (ast : a) : a =
115+
(type a) (kind : a Ml_binary.kind) (ast : a) : a =
119116
match kind with
120-
| Structure ->
117+
| Ml_binary.Ml ->
121118
apply_rewriters_str ?restore ~tool_name ast
122-
| Signature ->
119+
| Ml_binary.Mli ->
123120
apply_rewriters_sig ?restore ~tool_name ast
124121

125122
(* Parse a file or get a dumped syntax tree from it *)
@@ -142,13 +139,13 @@ let open_and_check_magic inputfile ast_magic =
142139
in
143140
(ic, is_ast_file)
144141

145-
let parse (type a) (kind : a ast_kind) lexbuf : a =
142+
let parse (type a) (kind : a Ml_binary.kind) lexbuf : a =
146143
match kind with
147-
| Structure -> Parse.implementation lexbuf
148-
| Signature -> Parse.interface lexbuf
144+
| Ml_binary.Ml -> Parse.implementation lexbuf
145+
| Ml_binary.Mli -> Parse.interface lexbuf
149146

150147
let file_aux ppf inputfile (type a) (parse_fun : _ -> a)
151-
(kind : a ast_kind) : a =
148+
(kind : a Ml_binary.kind) : a =
152149
let ast_magic = magic_of_kind kind in
153150
let (ic, is_ast_file) = open_and_check_magic inputfile ast_magic in
154151
let ast =
@@ -203,8 +200,8 @@ let parse_file kind ppf sourcefile =
203200

204201

205202
let parse_implementation ppf ~tool_name sourcefile =
206-
apply_rewriters ~restore:false ~tool_name Structure (parse_file
207-
Structure ppf sourcefile)
203+
apply_rewriters ~restore:false ~tool_name Ml (parse_file
204+
Ml ppf sourcefile)
208205
let parse_interface ppf ~tool_name sourcefile =
209-
apply_rewriters ~restore:false ~tool_name Signature (parse_file
210-
Signature ppf sourcefile)
206+
apply_rewriters ~restore:false ~tool_name Mli (parse_file
207+
Mli ppf sourcefile)

0 commit comments

Comments
 (0)