@@ -462,16 +462,19 @@ type if_then_else =
462462 ; box_expr : bool option
463463 ; expr_pro : Fmt .t option
464464 ; expr_eol : Fmt .t option
465+ ; branch_expr : expression Ast .xt
465466 ; break_end_branch : Fmt .t
466467 ; space_between_branches : Fmt .t }
467468
468469let get_if_then_else (c : Conf.t ) ~first ~last ~parens_bch ~parens_prev_bch
469470 ~xcond ~xbch ~expr_loc ~fmt_extension_suffix ~fmt_attributes ~fmt_cond =
470471 let imd = c.fmt_opts.indicate_multiline_delimiters.v in
471- let beginend =
472- match xbch.Ast. ast with
473- | {pexp_desc = Pexp_beginend _ ; _} -> true
474- | _ -> false
472+ let beginend, branch_expr =
473+ let ast = xbch.Ast. ast in
474+ match ast with
475+ | {pexp_desc = Pexp_beginend nested_exp ; pexp_attributes = [] ; _} ->
476+ (true , sub_exp ~ctx: (Exp ast) nested_exp)
477+ | _ -> (false , xbch)
475478 in
476479 let wrap_parens ~wrap_breaks k =
477480 if beginend then wrap " begin" " end" (wrap_breaks k)
@@ -517,6 +520,7 @@ let get_if_then_else (c : Conf.t) ~first ~last ~parens_bch ~parens_prev_bch
517520 ; box_expr= Some false
518521 ; expr_pro= None
519522 ; expr_eol= None
523+ ; branch_expr
520524 ; break_end_branch= noop
521525 ; space_between_branches= fmt " @ " }
522526 | `K_R ->
@@ -528,6 +532,7 @@ let get_if_then_else (c : Conf.t) ~first ~last ~parens_bch ~parens_prev_bch
528532 ; box_expr= Some false
529533 ; expr_pro= None
530534 ; expr_eol= Some (fmt " @;<1 2>" )
535+ ; branch_expr
531536 ; break_end_branch=
532537 fmt_if_k (parens_bch || beginend || not last) (break 1000 0 )
533538 ; space_between_branches= fmt_if (beginend || parens_bch) " " }
@@ -552,6 +557,7 @@ let get_if_then_else (c : Conf.t) ~first ~last ~parens_bch ~parens_prev_bch
552557 (not (Location. is_single_line expr_loc c.fmt_opts.margin.v))
553558 (break_unless_newline 1000 2 ) )
554559 ; expr_eol= Some (fmt " @;<1 2>" )
560+ ; branch_expr
555561 ; break_end_branch= noop
556562 ; space_between_branches=
557563 fmt
@@ -571,6 +577,7 @@ let get_if_then_else (c : Conf.t) ~first ~last ~parens_bch ~parens_prev_bch
571577 ; box_expr= None
572578 ; expr_pro= Some (break_unless_newline 1000 2 )
573579 ; expr_eol= None
580+ ; branch_expr
574581 ; break_end_branch= noop
575582 ; space_between_branches=
576583 fmt
@@ -600,6 +607,7 @@ let get_if_then_else (c : Conf.t) ~first ~last ~parens_bch ~parens_prev_bch
600607 ; box_expr= Some false
601608 ; expr_pro= None
602609 ; expr_eol= None
610+ ; branch_expr
603611 ; break_end_branch= noop
604612 ; space_between_branches= fmt " @ " }
605613
0 commit comments