| Expected | Ocp-indent output | |
|---|---|---|
| 0 | let () = | let () = |
| 1 | foo.bar <- | foo.bar <- |
| 2 | f x | f x |
| 3 | y z | y z |
| 4 | ||
| 5 | let should_check_can_sell_and_marking regulatory_regime = | let should_check_can_sell_and_marking regulatory_regime = |
| 6 | match z with | match z with |
| 7 | | `foo | | `foo |
| 8 | -> some_function | -> some_function |
| 9 | argument | argument |
| 10 | (* pszilagyi: The above typically occurs in a multi-pattern match clause, so the | (* pszilagyi: The above typically occurs in a multi-pattern match clause, so the |
| 11 | clause expression is on a line by itself. This is the more typical way a | clause expression is on a line by itself. This is the more typical way a |
| 12 | long single-pattern match clause would be written: *) | long single-pattern match clause would be written: *) |
| 13 | let should_check_can_sell_and_marking regulatory_regime = | let should_check_can_sell_and_marking regulatory_regime = |
| 14 | match z with | match z with |
| 15 | | `foo -> | | `foo -> |
| 16 | some_function | some_function |
| 17 | argument | argument |
| 18 | ||
| 19 | let f = fun x -> | let f = fun x -> |
| 20 | ghi | ghi |
| 21 | x | x |
| 22 | ||
| 23 | (* common *) | (* common *) |
| 24 | let x = | let x = |
| 25 | try x with | try x with |
| 26 | | a -> b | | a -> b |
| 27 | | c -> d | | c -> d |
| 28 | let x = try x with | let x = try x with |
| 29 | | a -> b | | a -> b |
| 30 | | c -> d | | c -> d |
| 31 | let x = | let x = |
| 32 | try x | try x |
| 33 | with | with |
| 34 | | a -> b | | a -> b |
| 35 | | c -> d | | c -> d |
| 36 | ||
| 37 | let z = | let z = |
| 38 | some_function | some_function |
| 39 | argument | argument |
| 40 | ||
| 41 | ||
| 42 | ||
| 43 | let () = | let () = |
| 44 | f a b ~c:c | f a b ~c:c |
| 45 | d | d |
| 46 | ||
| 47 | let () = | let () = |
| 48 | f a b ~c:1. | f a b ~c:1. |
| 49 | d | d |
| 50 | ||
| 51 | let () = | let () = |
| 52 | My_module.f a b ~c:c | My_module.f a b ~c:c |
| 53 | d | d |
| 54 | ||
| 55 | (* This last case is where Tuareg is inconsistent with the others. *) | (* This last case is where Tuareg is inconsistent with the others. *) |
| 56 | let () = | let () = |
| 57 | My_module.f a b ~c:1. | My_module.f a b ~c:1. |
| 58 | d | d |
| 59 | ||
| 60 | ||
| 61 | ||
| 62 | let () = | let () = |
| 63 | messages := | messages := |
| 64 | Message_store.create (Session_id.of_string "") | Message_store.create (Session_id.of_string "") |
| 65 | (* Tuareg indents these lines too far to the left. *) | (* Tuareg indents these lines too far to the left. *) |
| 66 | "herd-retransmitter" | "herd-retransmitter" |
| 67 | Message_store.Message_size.Byte | Message_store.Message_size.Byte |
| 68 | ||
| 69 | ||
| 70 | ||
| 71 | let () = | let () = |
| 72 | raise (Bug ("foo" | raise (Bug ("foo" |
| 73 | (* In this and similar cases, we want the subsequent lines to | (* In this and similar cases, we want the subsequent lines to |
| 74 | align with the first expression. *) | align with the first expression. *) |
| 75 | ^ "bar")); | ^ "bar")); |
| 76 | raise (Bug ("foo" ^ "quux" | raise (Bug ("foo" ^ "quux" |
| 77 | ^ "bar")); | ^ "bar")); |
| 78 | raise (Bug (foo + quux | raise (Bug (foo + quux |
| 79 | ^ "bar")); | ^ "bar")); |
| 80 | raise (Bug ((foo + quux) | raise (Bug ((foo + quux) |
| 81 | ^ "bar")) | ^ "bar")) |
| 82 | ||
| 83 | (* Except in specific cases, we want the argument indented relative to the | (* Except in specific cases, we want the argument indented relative to the |
| 84 | function being called. (Exceptions include "fun" arguments where the line | function being called. (Exceptions include "fun" arguments where the line |
| 85 | ends with "->" and subsequent lines beginning with operators, like above.) *) | ends with "->" and subsequent lines beginning with operators, like above.) *) |
| 86 | let () = | let () = |
| 87 | Some (Message_store.create s | Some (Message_store.create s |
| 88 | "herd-retransmitter" ~unlink:true Message_store.Message_size.Byte) | "herd-retransmitter" ~unlink:true Message_store.Message_size.Byte) |
| 89 | ||
| 90 | ||
| 91 | ||
| 92 | (* We like the indentation of most arguments, but want to get back towards the | (* We like the indentation of most arguments, but want to get back towards the |
| 93 | left margin in a few special cases: *) | left margin in a few special cases: *) |
| 94 | let _ = | let _ = |
| 95 | foo (bar (fun x -> (* special: "fun _ ->" at EOL *) | foo (bar (fun x -> (* special: "fun _ ->" at EOL *) |
| 96 | baz)) (* assume no more arguments to "bar" *) | baz)) (* assume no more arguments to "bar" *) |
| 97 | let _ = | let _ = |
| 98 | foo | foo |
| 99 | ~a_long_field_name:(check (fun bar -> | ~a_long_field_name:(check (fun bar -> |
| 100 | baz)) | baz)) |
| 101 | let _ = | let _ = |
| 102 | foo ~a_long_field_name:(check (fun bar -> | foo ~a_long_field_name:(check (fun bar -> |
| 103 | baz)) | baz)) |
| 104 | let _ = | let _ = |
| 105 | foo (bar (quux (fnord (fun x -> (* any depth *) | foo (bar (quux (fnord (fun x -> (* any depth *) |
| 106 | baz)))) | baz)))) |
| 107 | ||
| 108 | (* We also wanted to tweak the operator indentation, making operators like <= | (* We also wanted to tweak the operator indentation, making operators like <= |
| 109 | not special cases in contexts like this: *) | not special cases in contexts like this: *) |
| 110 | let _ = | let _ = |
| 111 | assert (foo (bar + baz | assert (foo (bar + baz |
| 112 | <= quux)) (* lined up under left argument to op, | <= quux)) (* lined up under left argument to op, |
| 113 | sim. to ^ above *) | sim. to ^ above *) |
| 114 | (* Sim. indentation of if conditions: *) | (* Sim. indentation of if conditions: *) |
| 115 | let _ = | let _ = |
| 116 | if (a | if (a |
| 117 | <= b) | <= b) |
| 118 | then () | then () |
| 119 | let _ = | let _ = |
| 120 | if a | if a |
| 121 | <= b | <= b |
| 122 | then () | then () |
| 123 | let _ = | let _ = |
| 124 | if Edge_adjustment.is_zero arb.cfg.extra_edge | if Edge_adjustment.is_zero arb.cfg.extra_edge |
| 125 | && 0. = sys.plugs.edge_backoff | && 0. = sys.plugs.edge_backoff |
| 126 | && 0. = zero_acvol_edge_backoff | && 0. = zero_acvol_edge_backoff |
| 127 | then 0. | then 0. |
| 128 | else 1. | else 1. |
| 129 | let _ = | let _ = |
| 130 | if | if |
| 131 | Edge_adjustment.is_zero arb.cfg.extra_edge | Edge_adjustment.is_zero arb.cfg.extra_edge |
| 132 | && 0. = sys.plugs.edge_backoff | && 0. = sys.plugs.edge_backoff |
| 133 | && 0. = zero_acvol_edge_backoff | && 0. = zero_acvol_edge_backoff |
| 134 | then 0. | then 0. |
| 135 | else 1. | else 1. |
| 136 | let _ = | let _ = |
| 137 | let entries = List.filter (Lazy.force transferstati) ~f:(fun ts -> | let entries = List.filter (Lazy.force transferstati) ~f:(fun ts -> |
| 138 | Pcre.pmatch ~pat ts.RQ.description | Pcre.pmatch ~pat ts.RQ.description |
| 139 | ) in | ) in |
| 140 | x | x |
| 141 | ||
| 142 | (* combination of operator at BOL and -> at EOL: *) | (* combination of operator at BOL and -> at EOL: *) |
| 143 | let _ = | let _ = |
| 144 | Shell.ssh_lines x | Shell.ssh_lines x |
| 145 | |! List.map ~f:(f (g (fun x -> | |! List.map ~f:(f (g (fun x -> |
| 146 | ·······let·name,·path·=·String.lsplit2_exn·~on:'|'·x·in | ····let·name,·path·=·String.lsplit2_exn·~on:'|'·x·in |
| 147 | ·······String.strip·name,·String.strip·path))) | ····String.strip·name,·String.strip·path))) |
| 148 | ||
| 149 | (* open paren ending line like begin *) | (* open paren ending line like begin *) |
| 150 | let _ = | let _ = |
| 151 | if a (p ^/ "s") [ e ] = Ok () then `S ( | if a (p ^/ "s") [ e ] = Ok () then `S ( |
| 152 | let label count = | let label count = |
| 153 | sprintf "%d s" c ^ if c = 1 then ":" else "s" | sprintf "%d s" c ^ if c = 1 then ":" else "s" |
| 154 | in | in |
| 155 | x | x |
| 156 | ) | ) |
| Expected | Ocp-indent output | |
|---|---|---|
| 0 | module M = | module M = |
| 1 | Foo (G) | Foo (G) |
| 2 | (H) | (H) |
| 3 | ||
| 4 | module M = | module M = |
| 5 | Foo | Foo |
| 6 | (G) | (G) |
| 7 | (struct | (struct |
| 8 | let x | let x |
| 9 | end) | end) |
| 10 | (H) | (H) |
| 11 | ||
| 12 | (* To me, this looks fine as it is. The rule seems fine as "indent arguments by | (* To me, this looks fine as it is. The rule seems fine as "indent arguments by |
| 13 | 2". To illustrate, with a case where the functor name is longer: *) | 2". To illustrate, with a case where the functor name is longer: *) |
| 14 | module M = | module M = |
| 15 | Functor (G) | Functor (G) |
| 16 | (H) | (H) |
| 17 | (I) | (I) |
| 18 | ||
| 19 | ||
| 20 | ||
| 21 | include Foo (struct | include Foo (struct |
| 22 | let x | let x |
| 23 | end) (struct | end) (struct |
| 24 | let y | let y |
| 25 | end) | end) |
| 26 | ||
| 27 | include | include |
| 28 | Foo (struct | Foo (struct |
| 29 | let x | let x |
| 30 | end) (struct | end) (struct |
| 31 | let y | let y |
| 32 | end) | end) |
| 33 | ||
| 34 | module M = | module M = |
| 35 | Foo (struct | Foo (struct |
| 36 | let x | let x |
| 37 | end) (struct | end) (struct |
| 38 | let y | let y |
| 39 | end) | end) |
| 40 | ||
| 41 | module M : S = | module M : S = |
| 42 | Make (M) | Make (M) |
| 43 | module M : S with type t := int = | module M : S with type t := int = |
| 44 | Make (M) | Make (M) |
| 45 | ||
| 46 | ||
| 47 | ||
| 48 | module Simple_command(Arg:sig | module Simple_command(Arg:sig |
| 49 | end) = struct end | end) = struct end |
| 50 | ||
| 51 | module Simple_command(Arg : sig | module Simple_command(Arg : sig |
| 52 | end) = struct end | end) = struct end |
| 53 | ||
| 54 | module Simple_command (Arg:sig | module Simple_command (Arg:sig |
| 55 | end) = struct end | end) = struct end |
| 56 | ||
| 57 | module Simple_command (Arg : sig | module Simple_command (Arg : sig |
| 58 | end) = struct end | end) = struct end |
| 59 | ||
| 60 | module Simple_command | module Simple_command |
| 61 | ··(Arg·:·sig | ····(Arg·:·sig |
| 62 | ···end)·=·struct·end | ·····end)·=·struct·end |
| Expected | Ocp-indent output | |
|---|---|---|
| 0 | type x = | type x = |
| 1 | { foo : int | { foo : int |
| 2 | ; bar : int | ; bar : int |
| 3 | } | } |
| 4 | ||
| 5 | let x = | let x = |
| 6 | { x with | { x with |
| 7 | foo = 3 | foo = 3 |
| 8 | ; bar = 5 | ; bar = 5 |
| 9 | } | } |
| 10 | ||
| 11 | let x = | let x = |
| 12 | { (* blah blah blah *) | { (* blah blah blah *) |
| 13 | foo = 3 | foo = 3 |
| 14 | ; bar = 5 | ; bar = 5 |
| 15 | } | } |
| 16 | ;; | ;; |
| 17 | ||
| 18 | let x = | let x = |
| 19 | [{ x with | [{ x with |
| 20 | foo = 3 | foo = 3 |
| 21 | ; bar = 5 | ; bar = 5 |
| 22 | }] | }] |
| 23 | ||
| 24 | let x = | let x = |
| 25 | [{ (* blah blah blah *) | [{ (* blah blah blah *) |
| 26 | ·····foo·=·3 | ····foo·=·3 |
| 27 | ···;·bar·=·5 | ··;·bar·=·5 |
| 28 | ···}] | ··}] |
| 29 | ;; | ;; |
| 30 | ||
| 31 | let x = | let x = |
| 32 | { M.x with | { M.x with |
| 33 | M. | M. |
| 34 | foo = 3 | foo = 3 |
| 35 | } | } |
| 36 | ;; | ;; |
| 37 | ||
| 38 | let x = | let x = |
| 39 | { x with | { x with |
| 40 | M. | M. |
| 41 | foo = 3 | foo = 3 |
| 42 | } | } |
| 43 | ;; | ;; |
| 44 | ||
| 45 | let x = | let x = |
| 46 | { M. | { M. |
| 47 | foo = 3 | foo = 3 |
| 48 | } | } |
| 49 | ;; | ;; |
| 50 | ||
| 51 | let _ = | let _ = |
| 52 | { foo with | { foo with |
| 53 | Bar. | Bar. |
| 54 | field1 = value1 | field1 = value1 |
| 55 | ; field2 = value2 | ; field2 = value2 |
| 56 | } | } |
| 57 | ;; | ;; |
| 58 | let _ = | let _ = |
| 59 | { foo | { foo |
| 60 | with Bar. | with Bar. |
| 61 | ····field1·=·value1 | ······field1·=·value1 |
| 62 | ··;·field2·=·value2 | ····;·field2·=·value2 |
| 63 | } | } |
| 64 | ;; | ;; |
| 65 | ||
| 66 | (* multicomponent record module pathname *) | (* multicomponent record module pathname *) |
| 67 | let _ = | let _ = |
| 68 | { A.B. | { A.B. |
| 69 | a = b | a = b |
| 70 | ; c = d | ; c = d |
| 71 | } | } |
| 72 | ;; | ;; |
| Expected | Ocp-indent output | |
|---|---|---|
| 0 | (* Indentation that Jane Street needs to think about and make precise. | (* Indentation that Jane Street needs to think about and make precise. |
| 1 | ||
| 2 | These are long term ideas, possibly even conflicting with other tests. *) | These are long term ideas, possibly even conflicting with other tests. *) |
| 3 | ||
| 4 | ||
| 5 | ||
| 6 | (* js-args *) | (* js-args *) |
| 7 | ||
| 8 | let _ = | let _ = |
| 9 | let min_closing_backoff = | let min_closing_backoff = |
| 10 | -. ( Hidden_float.expose (arb.cfg.base_edge @! Buy) | -. ( Hidden_float.expose (arb.cfg.base_edge @! Buy) |
| 11 | ········+.·Hidden_float.expose·(arb.cfg.base_edge·@!·Sell)) | ···········+.·Hidden_float.expose·(arb.cfg.base_edge·@!·Sell)) |
| 12 | in | in |
| 13 | 0 | 0 |
| 14 | ||
| 15 | ||
| 16 | ||
| 17 | (* js-type *) | (* js-type *) |
| 18 | ||
| 19 | (* The following tests incorporate several subtle and different indentation | (* The following tests incorporate several subtle and different indentation |
| 20 | ideas. Please consider this only a proposal for discussion, for now. | ideas. Please consider this only a proposal for discussion, for now. |
| 21 | ||
| 22 | First, notice the display treatment of "(,)" tuples, analogous to "[;]" | First, notice the display treatment of "(,)" tuples, analogous to "[;]" |
| 23 | lists. While "(,)" is an intensional combination of "()" and ",", unlike | lists. While "(,)" is an intensional combination of "()" and ",", unlike |
| 24 | "[;]" lists, we believe "(,)" isn't too big a departure. Value expression | "[;]" lists, we believe "(,)" isn't too big a departure. Value expression |
| 25 | analogies are included in js-type.ml, (meant to be) consistent with the | analogies are included in js-type.ml, (meant to be) consistent with the |
| 26 | proposed type indentation. | proposed type indentation. |
| 27 | ||
| 28 | Second, and more divergently, the proposed indentation of function types is | Second, and more divergently, the proposed indentation of function types is |
| 29 | based on the idea of aligning the arguments, even the first argument, even | based on the idea of aligning the arguments, even the first argument, even |
| 30 | where that means automatically inserting spaces within lines. This applies | where that means automatically inserting spaces within lines. This applies |
| 31 | to the extra spaces in ":__unit" and "(____Config.Network.t" below. | to the extra spaces in ":__unit" and "(____Config.Network.t" below. |
| 32 | ||
| 33 | We believe this fits into a more general incorporation of alignment into | We believe this fits into a more general incorporation of alignment into |
| 34 | ocp-indent, to replace our internal alignment tool with a syntax-aware one. | ocp-indent, to replace our internal alignment tool with a syntax-aware one. |
| 35 | We like to align things for readability, like big records, record types, | We like to align things for readability, like big records, record types, |
| 36 | lists used to build tables, etc. | lists used to build tables, etc. |
| 37 | ||
| 38 | The proposal also includes indenting "->" in the circumstances below relative | The proposal also includes indenting "->" in the circumstances below relative |
| 39 | to the enclosing "()", by two spaces. In a sense, this happens first, and | to the enclosing "()", by two spaces. In a sense, this happens first, and |
| 40 | then the first argument is aligned accordingly. So, there's no manual | then the first argument is aligned accordingly. So, there's no manual |
| 41 | indentation or spacing below. *) | indentation or spacing below. *) |
| 42 | ||
| 43 | val instances | val instances |
| 44 | : unit | : unit |
| 45 | -> ( Config.Network.t | -> ( Config.Network.t |
| 46 | ·······->·(App.t·*·Config.instance·*·Config.app)·list | ··········->·(App.t·*·Config.instance·*·Config.app)·list |
| 47 | ·······->·verbose:bool | ··········->·verbose:bool |
| 48 | ·······->·'m | ··········->·'m |
| 49 | , 'm | , 'm |
| 50 | ) Command.Spec.t | ) Command.Spec.t |
| 51 | ||
| 52 | val instances | val instances |
| 53 | : unit | : unit |
| 54 | -> ( Config.Network.t | -> ( Config.Network.t |
| 55 | ·······->·(App.t·*·Config.instance·*·Config.app)·list | ··········->·(App.t·*·Config.instance·*·Config.app)·list |
| 56 | ·······->·verbose:bool·->·'m | ··········->·verbose:bool·->·'m |
| 57 | , 'm | , 'm |
| 58 | ) Command.Spec.t | ) Command.Spec.t |
| 59 | ||
| 60 | (* presumed analog with stars *) | (* presumed analog with stars *) |
| 61 | val instances : | val instances : |
| 62 | unit | unit |
| 63 | * ( Config.Network.t | * ( Config.Network.t |
| 64 | ······*·(App.t·*·Config.instance·*·Config.app)·list | ········*·(App.t·*·Config.instance·*·Config.app)·list |
| 65 | ······*·bool | ········*·bool |
| 66 | ······*·'m | ········*·'m |
| 67 | , 'm | , 'm |
| 68 | ) Command.Spec.t | ) Command.Spec.t |
| Expected | Ocp-indent output | |
|---|---|---|
| 0 | let f x = | let f x = |
| 1 | stop | stop |
| 2 | (* We don't do this as a matter of style, but the indentation reveals a common | (* We don't do this as a matter of style, but the indentation reveals a common |
| 3 | mistake. *) | mistake. *) |
| 4 | >>> fun () -> don't_wait_for (close fd); | >>> fun () -> don't_wait_for (close fd); |
| 5 | ················bind·fd | ··bind·fd |
| 6 | ||
| 7 | let f x = | let f x = |
| 8 | stop | stop |
| 9 | (* This is what was intended, which is indented correctly, although it's bad | (* This is what was intended, which is indented correctly, although it's bad |
| 10 | style on my part. *) | style on my part. *) |
| 11 | >>> (fun () -> don't_wait_for (close fd)); | >>> (fun () -> don't_wait_for (close fd)); |
| 12 | bind | bind |