@@ -59,6 +59,7 @@ type t =
5959 ; max_iters : int
6060 ; module_item_spacing : [`Compact | `Preserve | `Sparse ]
6161 ; nested_match : [`Wrap | `Align ]
62+ ; ocaml_version : Ocaml_version .t
6263 ; ocp_indent_compat : bool
6364 ; parens_ite : bool
6465 ; parens_tuple : [`Always | `Multi_line_only ]
@@ -172,6 +173,14 @@ let info =
172173 in
173174 Term. info " ocamlformat" ~version: Version. version ~doc ~man
174175
176+ let ocaml_version_conv =
177+ let parse x =
178+ match Ocaml_version. of_string x with
179+ | Ok x -> `Ok x
180+ | Error (`Msg x ) -> `Error x
181+ in
182+ (parse, Ocaml_version. pp)
183+
175184(* * Options affecting formatting *)
176185module Formatting = struct
177186 let section = `Formatting
@@ -935,6 +944,16 @@ module Formatting = struct
935944 (fun conf x -> {conf with nested_match= x})
936945 (fun conf -> conf.nested_match)
937946
947+ let ocaml_version =
948+ let docv = " V" in
949+ let doc = " Version of OCaml syntax of the output." in
950+ let default = Ocaml_version. sys_version in
951+ let default_doc = " the currently installed OCaml version" in
952+ C. any ocaml_version_conv ~names: [" ocaml-version" ] ~default ~default_doc
953+ ~doc ~docv ~section
954+ (fun conf x -> {conf with ocaml_version= x})
955+ (fun conf -> conf.ocaml_version)
956+
938957 let ocp_indent_compat =
939958 let doc =
940959 " Attempt to generate output which does not change (much) when \
@@ -1456,6 +1475,7 @@ let ocamlformat_profile =
14561475 ; max_iters= 10
14571476 ; module_item_spacing= `Sparse
14581477 ; nested_match= `Wrap
1478+ ; ocaml_version= C. default Formatting. ocaml_version
14591479 ; ocp_indent_compat= false
14601480 ; parens_ite= false
14611481 ; parens_tuple= `Always
@@ -1528,6 +1548,7 @@ let conventional_profile =
15281548 ; max_iters= C. default max_iters
15291549 ; module_item_spacing= C. default Formatting. module_item_spacing
15301550 ; nested_match= C. default Formatting. nested_match
1551+ ; ocaml_version= C. default Formatting. ocaml_version
15311552 ; ocp_indent_compat= C. default Formatting. ocp_indent_compat
15321553 ; parens_ite= C. default Formatting. parens_ite
15331554 ; parens_tuple= C. default Formatting. parens_tuple
@@ -1653,6 +1674,7 @@ let janestreet_profile =
16531674 ; max_iters= ocamlformat_profile.max_iters
16541675 ; module_item_spacing= `Compact
16551676 ; nested_match= `Wrap
1677+ ; ocaml_version= C. default Formatting. ocaml_version
16561678 ; ocp_indent_compat= true
16571679 ; parens_ite= true
16581680 ; parens_tuple= `Multi_line_only
0 commit comments