@@ -3472,8 +3472,8 @@ and fmt_class_params c ctx params =
34723472 ( wrap_fits_breaks c.conf " [" " ]" (list_fl params fmt_param)
34733473 $ space_break ) )
34743474
3475- and fmt_type_declaration c ?(kw = " " ) ?(nonrec_kw = " " ) ?name ?( eq = " = " )
3476- {ast = decl ; _} =
3475+ and fmt_type_declaration c ?(pro = noop ) ?(kw = " " ) ?( nonrec_kw = " " ) ? name
3476+ ?( eq = " = " ) {ast = decl ; _} =
34773477 protect c (Td decl)
34783478 @@
34793479 let { ptype_name= {txt; loc}
@@ -3513,7 +3513,7 @@ and fmt_type_declaration c ?(kw = "") ?(nonrec_kw = "") ?name ?(eq = "=")
35133513 in
35143514 let box_manifest k =
35153515 hvbox c.conf.fmt_opts.type_decl_indent.v
3516- ( str kw
3516+ ( pro $ str kw
35173517 $ fmt_extension_suffix c ext
35183518 $ fmt_attributes c attrs_before
35193519 $ str nonrec_kw $ str " "
@@ -3901,9 +3901,9 @@ and fmt_module_type c ?(rec_ = false) ({ast= mty; ctx= ctx0} as xmty) =
39013901 | Pmty_with _ ->
39023902 let wcs, mt = Sugar. mod_with (sub_mty ~ctx mty) in
39033903 let fmt_cstr ~first ~last :_ wc =
3904- let pre = if first then " with" else " and" in
3904+ let pro = if first then str " with" else str " and" in
39053905 fmt_or first space_break cut_break
3906- $ fmt_with_constraint c ctx ~pre wc
3906+ $ fmt_with_constraint c ctx ~pro wc
39073907 in
39083908 let fmt_cstrs ~first :_ ~last :_ (wcs_and , loc , attr ) =
39093909 Cmts. fmt c loc
@@ -4336,28 +4336,28 @@ and fmt_module_statement c ~attributes ?(epi = noop) ?keyword mod_expr =
43364336 $ fmt_item_attributes c ~pre: Blank attrs_after
43374337 $ epi $ doc_after
43384338
4339- and fmt_with_constraint c ctx ~pre = function
4339+ and fmt_with_constraint c ctx ~pro = function
43404340 | Pwith_type (lid , td ) ->
4341- fmt_type_declaration ~kw: (pre ^ " type" ) c ~name: lid (sub_td ~ctx td)
4341+ fmt_type_declaration ~pro ~ kw:" type" c ~name: lid (sub_td ~ctx td)
43424342 | Pwith_module (m1 , m2 ) ->
4343- str pre $ str " module " $ fmt_longident_loc c m1 $ str " = "
4343+ pro $ str " module " $ fmt_longident_loc c m1 $ str " = "
43444344 $ fmt_longident_loc c m2
43454345 | Pwith_typesubst (lid , td ) ->
4346- fmt_type_declaration ~kw: (pre ^ " type" ) c ~eq: " :=" ~name: lid
4346+ fmt_type_declaration ~pro ~ kw:" type" c ~eq: " :=" ~name: lid
43474347 (sub_td ~ctx td)
43484348 | Pwith_modsubst (m1 , m2 ) ->
4349- str pre $ str " module " $ fmt_longident_loc c m1 $ str " := "
4349+ pro $ str " module " $ fmt_longident_loc c m1 $ str " := "
43504350 $ fmt_longident_loc c m2
43514351 | Pwith_modtype (m1 , m2 ) ->
43524352 let m1 = {m1 with txt= Some (str_longident c m1.txt)} in
43534353 let m2 = Some (sub_mty ~ctx m2) in
4354- str pre $ break 1 2
4354+ pro $ break 1 2
43554355 $ fmt_module c ctx (str " module type" ) m1 [] None ~rec_flag: false m2
43564356 ~attrs: Ast_helper.Attr. empty_ext_attrs
43574357 | Pwith_modtypesubst (m1 , m2 ) ->
43584358 let m1 = {m1 with txt= Some (str_longident c m1.txt)} in
43594359 let m2 = Some (sub_mty ~ctx m2) in
4360- str pre $ break 1 2
4360+ pro $ break 1 2
43614361 $ fmt_module c ctx ~eqty: " :=" (str " module type" ) m1 [] None
43624362 ~rec_flag: false m2 ~attrs: Ast_helper.Attr. empty_ext_attrs
43634363
@@ -4624,17 +4624,19 @@ and fmt_structure c ctx itms =
46244624 let ast (x , _ ) = Str x in
46254625 fmt_item_list c ctx update_config ast fmt_item itms
46264626
4627- and fmt_type c ?eq rec_flag decls ctx =
4627+ and fmt_type c ?pro ?( epi = noop) ? eq rec_flag decls ctx =
46284628 let update_config c td = update_config_attrs c td.ptype_attributes in
46294629 let is_rec = Asttypes. is_recursive rec_flag in
4630- let fmt_decl c ctx ~prev ~next : _ decl =
4631- let first = Option. is_none prev in
4630+ let fmt_decl c ctx ~prev ~next decl =
4631+ let first = Option. is_none prev and last = Option. is_none next in
46324632 let kw, nonrec_kw =
46334633 if first then
46344634 if is_rec then (" type" , None ) else (" type" , Some " nonrec" )
46354635 else (" and" , None )
46364636 in
4637- fmt_type_declaration c ~kw ?nonrec_kw ?eq (sub_td ~ctx decl)
4637+ let pro = if first then pro else None in
4638+ fmt_type_declaration c ?pro ~kw ?nonrec_kw ?eq (sub_td ~ctx decl)
4639+ $ fmt_if last epi
46384640 in
46394641 let ast x = Td x in
46404642 fmt_item_list c ctx update_config ast fmt_decl decls
@@ -4700,7 +4702,7 @@ and fmt_structure_item' ~ctx0 c ~last:last_item ~semisemi ~pro ?epi ~ctx si =
47004702 fmt_recmodule c ctx mbs fmt_module_binding ~pro ?epi
47014703 (fun x -> Mb (ctx, x))
47024704 sub_mb
4703- | Pstr_type (rec_flag , decls ) -> fmt_type c rec_flag decls ctx
4705+ | Pstr_type (rec_flag , decls ) -> fmt_type c ~pro ?epi rec_flag decls ctx
47044706 | Pstr_typext te -> fmt_type_extension c ctx ~pro ?epi te
47054707 | Pstr_value {pvbs_rec = rec_flag ; pvbs_bindings = bindings } ->
47064708 let update_config c i =
0 commit comments