@@ -679,22 +679,17 @@ let transform_type ~mode ~loc rec_flag type_name pattern_str _td =
679
679
680
680
let pp_func_name = " pp_" ^ type_name in
681
681
682
- let rec build_pp_expr ~ top_lvl (node : _ Location.loc ) =
682
+ let rec build_pp_expr (node : _ Location.loc ) =
683
683
match node.txt with
684
684
| Regexp_types. Code s -> [% expr Format. pp_print_string ppf [% e estring ~loc @@ unescape_literal s]]
685
685
| Seq es ->
686
- let exprs = List. map ( build_pp_expr ~top_lvl: false ) es in
686
+ let exprs = List. map build_pp_expr es in
687
687
List. fold_left
688
688
(fun acc e ->
689
689
[% expr
690
690
[% e acc];
691
691
[% e e]])
692
692
[% expr () ] exprs
693
- | Alt _ when top_lvl ->
694
- Util. error ~loc
695
- " Top-level alternations in type definitions are problematic. Consider wrapping the entire alternation in a capture group, though \
696
- note that the pretty-printer will only be able to reconstruct one branch."
697
- re
698
693
| Alt branches ->
699
694
(* branch selection based on populated fields *)
700
695
build_alt_pp_expr branches
@@ -724,8 +719,8 @@ let transform_type ~mode ~loc rec_flag type_name pattern_str _td =
724
719
match find_capture e with
725
720
| Some name ->
726
721
let field_access = pexp_field ~loc [% expr v] { txt = Lident name; loc } in
727
- [% expr match [% e field_access] with None -> () | Some _ -> [% e build_pp_expr ~top_lvl: false e]]
728
- | None -> build_pp_expr ~top_lvl: false e
722
+ [% expr match [% e field_access] with None -> () | Some _ -> [% e build_pp_expr e]]
723
+ | None -> build_pp_expr e
729
724
end
730
725
| Repeat (range , e ) ->
731
726
let min_reps, max_reps_opt = range.txt in
@@ -736,7 +731,7 @@ let transform_type ~mode ~loc rec_flag type_name pattern_str _td =
736
731
[% expr
737
732
let count = [% e eint ~loc min_reps] in
738
733
for _ = 1 to count do
739
- [% e build_pp_expr ~top_lvl: false e]
734
+ [% e build_pp_expr e]
740
735
done ]
741
736
| _ ->
742
737
let rec repeat_n n expr =
@@ -747,7 +742,7 @@ let transform_type ~mode ~loc rec_flag type_name pattern_str _td =
747
742
[% e expr];
748
743
[% e repeat_n (n - 1 ) expr]]
749
744
in
750
- repeat_n min_reps (build_pp_expr ~top_lvl: false e)
745
+ repeat_n min_reps (build_pp_expr e)
751
746
end
752
747
| _ -> [% expr () ]
753
748
(* determine branch based on populated fields *)
@@ -778,7 +773,7 @@ let transform_type ~mode ~loc rec_flag type_name pattern_str _td =
778
773
| [ cond ] -> cond
779
774
| conds -> List. fold_left (fun acc cond -> [% expr [% e acc] || [% e cond]]) (List. hd conds) (List. tl conds) )
780
775
in
781
- condition, build_pp_expr ~top_lvl: false branch)
776
+ condition, build_pp_expr branch)
782
777
branches
783
778
in
784
779
@@ -791,7 +786,7 @@ let transform_type ~mode ~loc rec_flag type_name pattern_str _td =
791
786
build_cascade branch_conditions
792
787
in
793
788
794
- let pp_body = build_pp_expr ~top_lvl: true r in
789
+ let pp_body = build_pp_expr r in
795
790
796
791
[
797
792
pstr_type ~loc rec_flag [ type_decl ];
0 commit comments