@@ -230,9 +230,9 @@ let check_comments (conf : Conf.t) cmts ~old:t_old ~new_:t_new =
230
230
| Ok () -> ()
231
231
| Error e -> internal_error (List. map e ~f: (fun x -> `Comment x)) []
232
232
233
- let format (type a b ) (fg : a Extended_ast.t ) ( std_fg : b Std_ast .t )
234
- ?output_file ~input_name ~prev_source ~ parsed ~ std_parsed ( conf : Conf.t )
235
- =
233
+ let format (type ext std ) (ext_fg : ext Extended_ast.t )
234
+ ( std_fg : std Std_ast.t ) ?output_file ~input_name ~prev_source
235
+ ~ ext_parsed ~ std_parsed ( conf : Conf.t ) =
236
236
let dump_ast fg ~suffix ast =
237
237
if conf.opr_opts.debug.v then
238
238
Some
@@ -247,23 +247,24 @@ let format (type a b) (fg : a Extended_ast.t) (std_fg : b Std_ast.t)
247
247
in
248
248
Location. input_name := input_name ;
249
249
(* iterate until formatting stabilizes *)
250
- let rec print_check ~i ~(conf : Conf.t ) ~prev_source t std_t =
250
+ let rec print_check ~i ~(conf : Conf.t ) ~prev_source ext_t std_t =
251
251
let format ~box_debug =
252
252
let open Fmt in
253
253
let cmts_t =
254
- Cmts. init fg ~debug: conf.opr_opts.debug.v t.source t.ast t.comments
254
+ Cmts. init ext_fg ~debug: conf.opr_opts.debug.v ext_t.source ext_t.ast
255
+ ext_t.comments
255
256
in
256
257
let contents =
257
258
with_buffer_formatter
258
259
~buffer_size: (String. length prev_source)
259
260
( set_margin conf.fmt_opts.margin.v
260
261
$ set_max_indent conf.fmt_opts.max_indent.v
261
262
$ fmt_if_k
262
- (not (String. is_empty t .prefix))
263
- (str t .prefix $ fmt " @." )
263
+ (not (String. is_empty ext_t .prefix))
264
+ (str ext_t .prefix $ fmt " @." )
264
265
$ with_optional_box_debug ~box_debug
265
- (Fmt_ast. fmt_ast fg ~debug: conf.opr_opts.debug.v t.source
266
- cmts_t conf t .ast ) )
266
+ (Fmt_ast. fmt_ast ext_fg ~debug: conf.opr_opts.debug.v
267
+ ext_t.source cmts_t conf ext_t .ast ) )
267
268
in
268
269
(contents, cmts_t)
269
270
in
@@ -289,22 +290,22 @@ let format (type a b) (fg : a Extended_ast.t) (std_fg : b Std_ast.t)
289
290
if conf.opr_opts.margin_check.v then
290
291
check_margin conf ~fmted
291
292
~filename: (Option. value output_file ~default: input_name) ;
292
- let strlocs = collect_strlocs fg t .ast in
293
+ let strlocs = collect_strlocs ext_fg ext_t .ast in
293
294
Ok (strlocs, fmted) )
294
295
else
295
296
let exn_args () =
296
297
[(" output file" , dump_formatted ~suffix: " .invalid-ast" fmted)]
297
298
|> List. filter_map ~f: (fun (s , f_opt ) ->
298
299
Option. map f_opt ~f: (fun f -> (s, String. sexp_of_t f)) )
299
300
in
300
- let * t_new =
301
+ let * ext_t_new =
301
302
match
302
- parse (parse_ast conf) ~disable_w50: true fg conf ~input_name
303
+ parse (parse_ast conf) ~disable_w50: true ext_fg conf ~input_name
303
304
~source: fmted
304
305
with
305
306
| exception Sys_error msg -> Error (Error. User_error msg)
306
307
| exception exn -> internal_error [`Cannot_parse exn ] (exn_args () )
307
- | t_new -> Ok t_new
308
+ | ext_t_new -> Ok ext_t_new
308
309
in
309
310
let * std_t_new =
310
311
match
@@ -324,7 +325,8 @@ let format (type a b) (fg : a Extended_ast.t) (std_fg : b Std_ast.t)
324
325
(Normalize_std_ast. equal std_fg conf std_t.ast std_t_new.ast
325
326
~ignore_doc_comments: (not conf.opr_opts.comment_check.v) ) )
326
327
&& not
327
- (Normalize_extended_ast. equal fg conf t.ast t_new.ast
328
+ (Normalize_extended_ast. equal ext_fg conf ext_t.ast
329
+ ext_t_new.ast
328
330
~ignore_doc_comments: (not conf.opr_opts.comment_check.v) )
329
331
then
330
332
let old_ast =
@@ -364,7 +366,7 @@ let format (type a b) (fg : a Extended_ast.t) (std_fg : b Std_ast.t)
364
366
| Some file ->
365
367
if i = 1 then Format. eprintf " [DEBUG] AST structure: %s\n " file
366
368
| None -> () ) ;
367
- check_comments conf cmts_t ~old: t ~new_: t_new ;
369
+ check_comments conf cmts_t ~old: ext_t ~new_: ext_t_new ;
368
370
(* Too many iteration ? *)
369
371
if i > = conf.opr_opts.max_iters.v then (
370
372
Stdlib. flush_all () ;
@@ -373,9 +375,9 @@ let format (type a b) (fg : a Extended_ast.t) (std_fg : b Std_ast.t)
373
375
) )
374
376
else
375
377
(* All good, continue *)
376
- print_check ~i: (i + 1 ) ~conf ~prev_source: fmted t_new std_t_new
378
+ print_check ~i: (i + 1 ) ~conf ~prev_source: fmted ext_t_new std_t_new
377
379
in
378
- try print_check ~i: 1 ~conf ~prev_source parsed std_parsed with
380
+ try print_check ~i: 1 ~conf ~prev_source ext_parsed std_parsed with
379
381
| Sys_error msg -> Error (User_error msg)
380
382
| exn -> Error (Ocamlformat_bug {exn ; input_name})
381
383
@@ -384,20 +386,21 @@ let parse_result ?disable_w50 f fragment conf ~source ~input_name =
384
386
| exception exn -> Error (Error. Invalid_source {exn ; input_name})
385
387
| parsed -> Ok parsed
386
388
387
- let parse_and_format (type a b ) (fg : a Extended_ast.t )
388
- (std_fg : b Std_ast.t ) ?output_file ~input_name ~source (conf : Conf.t ) =
389
+ let parse_and_format (type ext std ) (ext_fg : ext Extended_ast.t )
390
+ (std_fg : std Std_ast.t ) ?output_file ~input_name ~source (conf : Conf.t )
391
+ =
389
392
Location. input_name := input_name ;
390
393
let line_endings = conf.fmt_opts.line_endings.v in
391
- let * parsed =
392
- parse_result (parse_ast conf) ~disable_w50: true fg conf ~source
394
+ let * ext_parsed =
395
+ parse_result (parse_ast conf) ~disable_w50: true ext_fg conf ~source
393
396
~input_name
394
397
in
395
398
let * std_parsed =
396
399
parse_result Std_ast.Parse. ast std_fg conf ~source ~input_name
397
400
in
398
401
let + strlocs, formatted =
399
- format fg std_fg ?output_file ~input_name ~prev_source: source ~parsed
400
- ~std_parsed conf
402
+ format ext_fg std_fg ?output_file ~input_name ~prev_source: source
403
+ ~ext_parsed ~ std_parsed conf
401
404
in
402
405
Eol_compat. normalize_eol ~exclude_locs: strlocs ~line_endings formatted
403
406
0 commit comments