Skip to content

Commit 753de50

Browse files
committed
separate parsing from command line ppx
1 parent 6ea9458 commit 753de50

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

jscomp/core/pparse_driver.ml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ let parse (type a) (kind : a ast_kind) lexbuf : a =
147147
| Structure -> Parse.implementation lexbuf
148148
| Signature -> Parse.interface lexbuf
149149

150-
let file_aux ppf ~tool_name inputfile (type a) (parse_fun : _ -> a)
151-
(kind : a ast_kind) =
150+
let file_aux ppf inputfile (type a) (parse_fun : _ -> a)
151+
(kind : a ast_kind) : a =
152152
let ast_magic = magic_of_kind kind in
153153
let (ic, is_ast_file) = open_and_check_magic inputfile ast_magic in
154154
let ast =
@@ -168,8 +168,8 @@ let file_aux ppf ~tool_name inputfile (type a) (parse_fun : _ -> a)
168168
end
169169
with x -> close_in ic; raise x
170170
in
171-
close_in ic;
172-
apply_rewriters ~restore:false ~tool_name kind ast
171+
close_in ic; ast
172+
173173

174174

175175
let report_error ppf = function
@@ -187,11 +187,12 @@ let () =
187187
| _ -> None
188188
)
189189

190-
let parse_file ~tool_name kind ppf sourcefile =
190+
let parse_file kind ppf sourcefile =
191191
Location.set_input_name sourcefile;
192192
let inputfile = preprocess sourcefile in
193193
let ast =
194-
try file_aux ppf ~tool_name inputfile (parse kind) kind
194+
try
195+
(file_aux ppf inputfile (parse kind) kind)
195196
with exn ->
196197
remove_preprocessed inputfile;
197198
raise exn
@@ -202,8 +203,8 @@ let parse_file ~tool_name kind ppf sourcefile =
202203

203204

204205
let parse_implementation ppf ~tool_name sourcefile =
205-
parse_file ~tool_name
206-
Structure ppf sourcefile
206+
apply_rewriters ~restore:false ~tool_name Structure (parse_file
207+
Structure ppf sourcefile)
207208
let parse_interface ppf ~tool_name sourcefile =
208-
parse_file ~tool_name
209-
Signature ppf sourcefile
209+
apply_rewriters ~restore:false ~tool_name Signature (parse_file
210+
Signature ppf sourcefile)

lib/4.06.1/whole_compiler.ml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -403739,8 +403739,8 @@ let parse (type a) (kind : a ast_kind) lexbuf : a =
403739403739
| Structure -> Parse.implementation lexbuf
403740403740
| Signature -> Parse.interface lexbuf
403741403741

403742-
let file_aux ppf ~tool_name inputfile (type a) (parse_fun : _ -> a)
403743-
(kind : a ast_kind) =
403742+
let file_aux ppf inputfile (type a) (parse_fun : _ -> a)
403743+
(kind : a ast_kind) : a =
403744403744
let ast_magic = magic_of_kind kind in
403745403745
let (ic, is_ast_file) = open_and_check_magic inputfile ast_magic in
403746403746
let ast =
@@ -403760,8 +403760,8 @@ let file_aux ppf ~tool_name inputfile (type a) (parse_fun : _ -> a)
403760403760
end
403761403761
with x -> close_in ic; raise x
403762403762
in
403763-
close_in ic;
403764-
apply_rewriters ~restore:false ~tool_name kind ast
403763+
close_in ic; ast
403764+
403765403765

403766403766

403767403767
let report_error ppf = function
@@ -403779,11 +403779,12 @@ let () =
403779403779
| _ -> None
403780403780
)
403781403781

403782-
let parse_file ~tool_name kind ppf sourcefile =
403782+
let parse_file kind ppf sourcefile =
403783403783
Location.set_input_name sourcefile;
403784403784
let inputfile = preprocess sourcefile in
403785403785
let ast =
403786-
try file_aux ppf ~tool_name inputfile (parse kind) kind
403786+
try
403787+
(file_aux ppf inputfile (parse kind) kind)
403787403788
with exn ->
403788403789
remove_preprocessed inputfile;
403789403790
raise exn
@@ -403794,11 +403795,11 @@ let parse_file ~tool_name kind ppf sourcefile =
403794403795

403795403796

403796403797
let parse_implementation ppf ~tool_name sourcefile =
403797-
parse_file ~tool_name
403798-
Structure ppf sourcefile
403798+
apply_rewriters ~restore:false ~tool_name Structure (parse_file
403799+
Structure ppf sourcefile)
403799403800
let parse_interface ppf ~tool_name sourcefile =
403800-
parse_file ~tool_name
403801-
Signature ppf sourcefile
403801+
apply_rewriters ~restore:false ~tool_name Signature (parse_file
403802+
Signature ppf sourcefile)
403802403803

403803403804
end
403804403805
module Pprintast : sig

0 commit comments

Comments
 (0)