@@ -539,46 +539,40 @@ and fmt_attribute_or_extension c key (pre, pld) =
539
539
$ fmt_payload c (Pld pld) pld
540
540
$ fmt_if (Exposed.Right. payload pld) " " )
541
541
542
+ and fmt_attribute c ~key {attr_name; attr_payload; attr_loc} =
543
+ hvbox 0 @@ Cmts. fmt c attr_loc
544
+ @@
545
+ match (attr_name, attr_payload) with
546
+ | ( {txt= (" ocaml.doc" | " ocaml.text" ) as txt; loc= {loc_ghost= true ; _}}
547
+ , PStr
548
+ [ { pstr_desc=
549
+ Pstr_eval
550
+ ( { pexp_desc= Pexp_constant (Pconst_string (doc, _, None ))
551
+ ; pexp_attributes= []
552
+ ; _ }
553
+ , [] )
554
+ ; _ } ] ) ->
555
+ fmt_or (String. equal txt " ocaml.text" ) " @ " " "
556
+ $ wrap " (**" " *)" (str doc)
557
+ | name , pld ->
558
+ let indent =
559
+ match pld with
560
+ | (PStr _ | PSig _ ) when String. equal key " @@@" ->
561
+ c.conf.stritem_extension_indent
562
+ | _ -> c.conf.extension_indent
563
+ in
564
+ hvbox indent (fmt_attribute_or_extension c key (name, pld))
565
+
542
566
and fmt_attributes c ?pre ?suf ~key attrs =
543
- let pre =
544
- match pre with
545
- (* Breaking before an attribute can confuse ocp-indent that will produce
546
- a suboptimal indentation. *)
547
- | Some Space when c.conf.ocp_indent_compat -> Some Blank
548
- | Some pre -> Some pre
549
- | None -> None
550
- in
551
- let pre = Option. map pre ~f: sp in
552
- let fmt_attribute c pre = function
553
- | ( {txt= (" ocaml.doc" | " ocaml.text" ) as txt; loc= {loc_ghost= true ; _}}
554
- , PStr
555
- [ { pstr_desc=
556
- Pstr_eval
557
- ( { pexp_desc= Pexp_constant (Pconst_string (doc, _, None ))
558
- ; pexp_attributes= []
559
- ; _ }
560
- , [] )
561
- ; _ } ] ) ->
562
- fmt_or (String. equal txt " ocaml.text" ) " @ " " "
563
- $ wrap " (**" " *)" (str doc)
564
- | name , pld ->
565
- let indent =
566
- match pld with
567
- | (PStr _ | PSig _ ) when String. equal pre " @@@" ->
568
- c.conf.stritem_extension_indent
569
- | _ -> c.conf.extension_indent
570
- in
571
- hvbox indent (fmt_attribute_or_extension c pre (name, pld))
572
- in
573
567
let num = List. length attrs in
574
- let fmt_attr ~first ~last {attr_name; attr_payload; attr_loc} =
575
- fmt_or_k first (open_hvbox 0 ) (fmt " @ " )
576
- $ hvbox 0
577
- (Cmts. fmt c attr_loc (fmt_attribute c key (attr_name, attr_payload)))
578
- $ fmt_if_k last (close_box $ fmt_opt suf)
579
- in
580
568
fmt_if_k (num > 0 )
581
- (fmt_opt pre $ hvbox_if (num > 1 ) 0 (list_fl attrs fmt_attr))
569
+ ( opt pre (function
570
+ (* Breaking before an attribute can confuse ocp-indent that will
571
+ produce a suboptimal indentation. *)
572
+ | Space when c.conf.ocp_indent_compat -> sp Blank
573
+ | pre -> sp pre )
574
+ $ hvbox_if (num > 1 ) 0
575
+ (hvbox 0 (list attrs " @ " (fmt_attribute c ~key )) $ opt suf str) )
582
576
583
577
and fmt_payload c ctx pld =
584
578
protect c (Pld pld)
@@ -1574,7 +1568,7 @@ and fmt_expression c ?(box = true) ?pro ?epi ?eol ?parens ?(indent_wrap = 0)
1574
1568
( str " %"
1575
1569
$ hovbox 2
1576
1570
( fmt_str_loc c name $ str " fun "
1577
- $ fmt_attributes c ~suf: (str " " ) call.pexp_attributes
1571
+ $ fmt_attributes c ~suf: " " call.pexp_attributes
1578
1572
~key: " @"
1579
1573
$ fmt_fun_args c xargs $ fmt_opt fmt_cstr $ fmt " @ ->"
1580
1574
)
@@ -1608,7 +1602,7 @@ and fmt_expression c ?(box = true) ?pro ?epi ?eol ?parens ?(indent_wrap = 0)
1608
1602
( str " %"
1609
1603
$ hovbox 2
1610
1604
( fmt_str_loc c name $ str " fun "
1611
- $ fmt_attributes c ~suf: (str " " ) retn.pexp_attributes
1605
+ $ fmt_attributes c ~suf: " " retn.pexp_attributes
1612
1606
~key: " @"
1613
1607
$ fmt_fun_args c xargs $ fmt_opt fmt_cstr $ fmt " @ ->"
1614
1608
)
@@ -1717,8 +1711,7 @@ and fmt_expression c ?(box = true) ?pro ?epi ?eol ?parens ?(indent_wrap = 0)
1717
1711
( fmt_expression c (sub_exp ~ctx op)
1718
1712
$ fmt " @ " $ cmts_before $ fmt_if parens_r " ("
1719
1713
$ str " fun " )
1720
- $ fmt_attributes c ~key: " @" pexp_attributes
1721
- ~suf: (str " " )
1714
+ $ fmt_attributes c ~key: " @" pexp_attributes ~suf: " "
1722
1715
$ hvbox_if
1723
1716
(not c.conf.wrap_fun_args)
1724
1717
4
@@ -1844,7 +1837,7 @@ and fmt_expression c ?(box = true) ?pro ?epi ?eol ?parens ?(indent_wrap = 0)
1844
1837
( hvbox 2
1845
1838
( fmt " (fun@ "
1846
1839
$ fmt_attributes c ~key: " @"
1847
- eN1.pexp_attributes ~suf: (str " " )
1840
+ eN1.pexp_attributes ~suf: " "
1848
1841
$ fmt_fun_args c xargs $ fmt_opt fmt_cstr
1849
1842
)
1850
1843
$ fmt " @ ->" ) )
@@ -2082,7 +2075,7 @@ and fmt_expression c ?(box = true) ?pro ?epi ?eol ?parens ?(indent_wrap = 0)
2082
2075
( hovbox 2
2083
2076
( hovbox 4
2084
2077
( str " fun "
2085
- $ fmt_attributes c ~key: " @" pexp_attributes ~suf: (str " " )
2078
+ $ fmt_attributes c ~key: " @" pexp_attributes ~suf: " "
2086
2079
$ hvbox_if
2087
2080
(not c.conf.wrap_fun_args)
2088
2081
0 (fmt_fun_args c xargs)
@@ -2747,7 +2740,7 @@ and fmt_class_expr c ?eol ?(box = true) ({ast= exp; _} as xexp) =
2747
2740
( hovbox 2
2748
2741
( box_fun_decl_args c 0
2749
2742
( str " fun "
2750
- $ fmt_attributes c ~key: " @" pcl_attributes ~suf: (str " " )
2743
+ $ fmt_attributes c ~key: " @" pcl_attributes ~suf: " "
2751
2744
$ wrap_fun_decl_args c (fmt_fun_args c xargs)
2752
2745
$ fmt " @ " )
2753
2746
$ str " ->" )
@@ -3403,8 +3396,8 @@ and fmt_extension_constructor c sep ctx ec =
3403
3396
let doc, atrs = doc_atrs pext_attributes in
3404
3397
let suf =
3405
3398
match pext_kind with
3406
- | Pext_decl (_ , None ) | Pext_rebind _ -> noop
3407
- | Pext_decl (_ , Some _ ) -> str " "
3399
+ | Pext_decl (_ , None ) | Pext_rebind _ -> None
3400
+ | Pext_decl (_ , Some _ ) -> Some " "
3408
3401
in
3409
3402
Cmts. fmt c pext_loc
3410
3403
@@ hvbox 4
@@ -3418,7 +3411,7 @@ and fmt_extension_constructor c sep ctx ec =
3418
3411
| Pext_decl (args , res ) ->
3419
3412
fmt_constructor_arguments_result c ctx args res
3420
3413
| Pext_rebind lid -> str " = " $ fmt_longident_loc c lid )
3421
- $ fmt_attributes c ~pre: (Break (1 , 0 )) ~key: " @" atrs ~ suf
3414
+ $ fmt_attributes c ~pre: (Break (1 , 0 )) ~key: " @" atrs ? suf
3422
3415
$ fmt_docstring_padded c doc )
3423
3416
3424
3417
and fmt_functor_arg c {loc; txt = arg } =
0 commit comments