Skip to content

Fix spurious space around parentheses #832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/document/generator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ module Make (Syntax : SYNTAX) = struct
let params = O.list params ~sep:(O.txt "," ++ O.sp) ~f:type_expr in
let params =
match delim with
| `parens -> enclose ~l:"( " params ~r:" )"
| `brackets -> enclose ~l:"[ " params ~r:" ]"
| `parens -> enclose ~l:"(" params ~r:")"
| `brackets -> enclose ~l:"[" params ~r:"]"
in
Syntax.Type.handle_constructor_params path (O.box_hv params)

Expand All @@ -330,7 +330,7 @@ module Make (Syntax : SYNTAX) = struct
++ O.sp ++ type_expr dst
(* ++ O.end_hv *)
in
if not needs_parentheses then res else enclose ~l:"( " res ~r:" )"
if not needs_parentheses then res else enclose ~l:"(" res ~r:")"
| Arrow (Some lbl, src, dst) ->
let res =
O.span
Expand All @@ -340,7 +340,7 @@ module Make (Syntax : SYNTAX) = struct
++ O.txt " " ++ Syntax.Type.arrow)
++ O.sp ++ type_expr dst
in
if not needs_parentheses then res else enclose ~l:"( " res ~r:" )"
if not needs_parentheses then res else enclose ~l:"(" res ~r:")"
| Tuple lst ->
let res =
O.box_hv_no_indent
Expand Down
4 changes: 2 additions & 2 deletions test/generators/html/Module.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ <h1>Module <code><span>Module</span></code></h1><p>Foo.</p>
<span>('a, 'b) <a href="Module-module-type-S.html#type-w">w</a>
</span> :=
<span>
<span>( <span class="type-var">'a</span>,
<span class="type-var">'b</span> )
<span>(<span class="type-var">'a</span>,
<span class="type-var">'b</span>)
</span> <a href="#type-result">result</a>
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1>Module <code><span>InnerModuleA.InnerModuleA'</span></code></h1>
<a href="#type-t" class="anchor"></a>
<code><span><span class="keyword">type</span> t</span>
<span> =
<span><span>( unit, unit )</span>
<span><span>(unit, unit)</span>
<a href="Ocamlary.html#type-a_function">a_function</a>
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h1>Module <code><span>InnerModuleA.InnerModuleA'</span></code></h1>
<a href="#type-t" class="anchor"></a>
<code><span><span class="keyword">type</span> t</span>
<span> =
<span><span>( unit, unit )</span>
<span><span>(unit, unit)</span>
<a href="Ocamlary.html#type-a_function">a_function</a>
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1>Module <code><span>InnerModuleA.InnerModuleA'</span></code></h1>
<a href="#type-t" class="anchor"></a>
<code><span><span class="keyword">type</span> t</span>
<span> =
<span><span>( unit, unit )</span>
<span><span>(unit, unit)</span>
<a href="Ocamlary.html#type-a_function">a_function</a>
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h1>Module <code><span>InnerModuleA.InnerModuleA'</span></code></h1>
<a href="#type-t" class="anchor"></a>
<code><span><span class="keyword">type</span> t</span>
<span> =
<span><span>( unit, unit )</span>
<span><span>(unit, unit)</span>
<a href="Ocamlary.html#type-a_function">a_function</a>
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1>Module <code><span>InnerModuleA.InnerModuleA'</span></code></h1>
<a href="#type-t" class="anchor"></a>
<code><span><span class="keyword">type</span> t</span>
<span> =
<span><span>( unit, unit )</span>
<span><span>(unit, unit)</span>
<a href="Ocamlary.html#type-a_function">a_function</a>
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1>Module <code><span>InnerModuleA.InnerModuleA'</span></code></h1>
<a href="#type-t" class="anchor"></a>
<code><span><span class="keyword">type</span> t</span>
<span> =
<span><span>( unit, unit )</span>
<span><span>(unit, unit)</span>
<a href="Ocamlary.html#type-a_function">a_function</a>
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1>Module <code><span>InnerModuleA.InnerModuleA'</span></code></h1>
<a href="#type-t" class="anchor"></a>
<code><span><span class="keyword">type</span> t</span>
<span> =
<span><span>( unit, unit )</span>
<span><span>(unit, unit)</span>
<a href="Ocamlary.html#type-a_function">a_function</a>
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h1>Module <code><span>InnerModuleA.InnerModuleA'</span></code></h1>
<a href="#type-t" class="anchor"></a>
<code><span><span class="keyword">type</span> t</span>
<span> =
<span><span>( unit, unit )</span>
<span><span>(unit, unit)</span>
<a href="Ocamlary.html#type-a_function">a_function</a>
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h1>Module <code><span>InnerModuleA.InnerModuleA'</span></code></h1>
<a href="#type-t" class="anchor"></a>
<code><span><span class="keyword">type</span> t</span>
<span> =
<span><span>( unit, unit )</span>
<span><span>(unit, unit)</span>
<a href="Ocamlary.html#type-a_function">a_function</a>
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h1>Module <code><span>InnerModuleA.InnerModuleA'</span></code></h1>
<a href="#type-t" class="anchor"></a>
<code><span><span class="keyword">type</span> t</span>
<span> =
<span><span>( unit, unit )</span>
<span><span>(unit, unit)</span>
<a href="Ocamlary.html#type-a_function">a_function</a>
</span>
</span>
Expand Down
37 changes: 18 additions & 19 deletions test/generators/html/Ocamlary.html
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,14 @@ <h4 id="basic-type-and-value-stuff-with-advanced-doc-comments">
<a href="#val-fun_fun_fun" class="anchor"></a>
<code>
<span><span class="keyword">val</span> fun_fun_fun :

<span>
<span>(
<span><span>( int, int )</span>
<span>(
<span><span>(int, int)</span>
<a href="#type-a_function">a_function</a>
</span>,
<span><span>( unit, unit )</span>
<span><span>(unit, unit)</span>
<a href="#type-a_function">a_function</a>
</span> )
</span>)
</span> <a href="#type-a_function">a_function</a>
</span>
</span>
Expand Down Expand Up @@ -1097,7 +1096,7 @@ <h4 id="advanced-type-stuff">
<a href="#type-full_gadt.Tag" class="anchor"></a>
<code><span>| </span>
<span><span class="constructor">Tag</span> :
<span><span>( unit, unit )</span>
<span><span>(unit, unit)</span>
<a href="#type-full_gadt">full_gadt</a>
</span>
</span>
Expand All @@ -1111,7 +1110,7 @@ <h4 id="advanced-type-stuff">
<span><span class="constructor">First</span> :
<span class="type-var">'a</span>
<span class="arrow">&#45;&gt;</span>
<span><span>( <span class="type-var">'a</span>, unit )</span>
<span><span>(<span class="type-var">'a</span>, unit)</span>
<a href="#type-full_gadt">full_gadt</a>
</span>
</span>
Expand All @@ -1125,7 +1124,7 @@ <h4 id="advanced-type-stuff">
<span><span class="constructor">Second</span> :
<span class="type-var">'a</span>
<span class="arrow">&#45;&gt;</span>
<span><span>( unit, <span class="type-var">'a</span> )</span>
<span><span>(unit, <span class="type-var">'a</span>)</span>
<a href="#type-full_gadt">full_gadt</a>
</span>
</span>
Expand All @@ -1139,7 +1138,7 @@ <h4 id="advanced-type-stuff">
<span><span class="constructor">Exist</span> :
<span class="type-var">'a</span> * <span class="type-var">'b</span>
<span class="arrow">&#45;&gt;</span>
<span><span>( <span class="type-var">'b</span>, unit )</span>
<span><span>(<span class="type-var">'b</span>, unit)</span>
<a href="#type-full_gadt">full_gadt</a>
</span>
</span>
Expand Down Expand Up @@ -1190,10 +1189,10 @@ <h4 id="advanced-type-stuff">
<a href="#type-partial_gadt.ExistGadtTag" class="anchor"></a>
<code><span>| </span>
<span><span class="constructor">ExistGadtTag</span> :
<span>(
<span>(
<span><span class="type-var">'a</span>
<span class="arrow">&#45;&gt;</span>
</span> <span class="type-var">'b</span> )
</span> <span class="type-var">'b</span>)
</span> <span class="arrow">&#45;&gt;</span>
<span><span class="type-var">'a</span>
<a href="#type-partial_gadt">partial_gadt</a>
Expand Down Expand Up @@ -1552,8 +1551,8 @@ <h4 id="advanced-type-stuff">
</span>
<span> =
<span>
<span>( <span class="type-var">'a</span>,
<span class="type-var">'b</span> )
<span>(<span class="type-var">'a</span>,
<span class="type-var">'b</span>)
</span> <a href="#type-full_gadt">full_gadt</a>
</span>
</span><span> = </span>
Expand All @@ -1564,7 +1563,7 @@ <h4 id="advanced-type-stuff">
<a href="#type-full_gadt_alias.Tag" class="anchor"></a>
<code><span>| </span>
<span><span class="constructor">Tag</span> :
<span><span>( unit, unit )</span>
<span><span>(unit, unit)</span>
<a href="#type-full_gadt_alias">full_gadt_alias</a>
</span>
</span>
Expand All @@ -1578,7 +1577,7 @@ <h4 id="advanced-type-stuff">
<span><span class="constructor">First</span> :
<span class="type-var">'a</span>
<span class="arrow">&#45;&gt;</span>
<span><span>( <span class="type-var">'a</span>, unit )</span>
<span><span>(<span class="type-var">'a</span>, unit)</span>
<a href="#type-full_gadt_alias">full_gadt_alias</a>
</span>
</span>
Expand All @@ -1592,7 +1591,7 @@ <h4 id="advanced-type-stuff">
<span><span class="constructor">Second</span> :
<span class="type-var">'a</span>
<span class="arrow">&#45;&gt;</span>
<span><span>( unit, <span class="type-var">'a</span> )</span>
<span><span>(unit, <span class="type-var">'a</span>)</span>
<a href="#type-full_gadt_alias">full_gadt_alias</a>
</span>
</span>
Expand All @@ -1606,7 +1605,7 @@ <h4 id="advanced-type-stuff">
<span><span class="constructor">Exist</span> :
<span class="type-var">'a</span> * <span class="type-var">'b</span>
<span class="arrow">&#45;&gt;</span>
<span><span>( <span class="type-var">'b</span>, unit )</span>
<span><span>(<span class="type-var">'b</span>, unit)</span>
<a href="#type-full_gadt_alias">full_gadt_alias</a>
</span>
</span>
Expand Down Expand Up @@ -1663,10 +1662,10 @@ <h4 id="advanced-type-stuff">
<a href="#type-partial_gadt_alias.ExistGadtTag" class="anchor"></a>
<code><span>| </span>
<span><span class="constructor">ExistGadtTag</span> :
<span>(
<span>(
<span><span class="type-var">'a</span>
<span class="arrow">&#45;&gt;</span>
</span> <span class="type-var">'b</span> )
</span> <span class="type-var">'b</span>)
</span> <span class="arrow">&#45;&gt;</span>
<span><span class="type-var">'a</span>
<a href="#type-partial_gadt_alias">partial_gadt_alias</a>
Expand Down
13 changes: 5 additions & 8 deletions test/generators/html/Type.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h1>Module <code><span>Type</span></code></h1>
<code><span><span class="keyword">type</span> higher_order</span>
<span> =
<span>
<span>( <span>int <span class="arrow">&#45;&gt;</span></span> int )
<span>(<span>int <span class="arrow">&#45;&gt;</span></span> int)
</span> <span class="arrow">&#45;&gt;</span>
</span> int
</span>
Expand Down Expand Up @@ -89,12 +89,11 @@ <h1>Module <code><span>Type</span></code></h1>
<span><span class="keyword">type</span> labeled_higher_order</span>
<span> =
<span>
<span>( <span>l:int <span class="arrow">&#45;&gt;</span></span> int )
<span>(<span>l:int <span class="arrow">&#45;&gt;</span></span> int)
</span> <span class="arrow">&#45;&gt;</span>
</span>
<span>
<span>( <span>?l:int <span class="arrow">&#45;&gt;</span></span>
int )
<span>(<span>?l:int <span class="arrow">&#45;&gt;</span></span> int)
</span> <span class="arrow">&#45;&gt;</span>
</span> int
</span>
Expand Down Expand Up @@ -172,8 +171,7 @@ <h1>Module <code><span>Type</span></code></h1>
</span>

<span>
<span>( <span>string <span class="arrow">&#45;&gt;</span></span>
int )
<span>(<span>string <span class="arrow">&#45;&gt;</span></span> int)
</span> <span class="arrow">&#45;&gt;</span>
</span>

Expand Down Expand Up @@ -624,8 +622,7 @@ <h1>Module <code><span>Type</span></code></h1>
<a href="#type-using_binary" class="anchor"></a>
<code><span><span class="keyword">type</span> using_binary</span>
<span> =
<span><span>( int, int )</span> <a href="#type-binary">binary</a>
</span>
<span><span>(int, int)</span> <a href="#type-binary">binary</a></span>
</span>
</code>
</div>
Expand Down
2 changes: 1 addition & 1 deletion test/generators/latex/Ocamlary.FunctorTypeOf.tex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ \subsection{Parameters\label{parameters}}%
\label{module-Ocamlary-module-FunctorTypeOf-argument-1-Collection-type-element}\ocamlcodefragment{\ocamltag{keyword}{type} element}\\
\label{module-Ocamlary-module-FunctorTypeOf-argument-1-Collection-module-InnerModuleA}\ocamlcodefragment{\ocamltag{keyword}{module} \hyperref[module-Ocamlary-module-FunctorTypeOf-argument-1-Collection-module-InnerModuleA]{\ocamlinlinecode{InnerModuleA}}}\ocamlcodefragment{ : \ocamltag{keyword}{sig}}\begin{ocamlindent}\label{module-Ocamlary-module-FunctorTypeOf-argument-1-Collection-module-InnerModuleA-type-t}\ocamlcodefragment{\ocamltag{keyword}{type} t = \hyperref[module-Ocamlary-module-FunctorTypeOf-argument-1-Collection-type-collection]{\ocamlinlinecode{collection}}}\begin{ocamlindent}This comment is for \ocamlinlinecode{t}.\end{ocamlindent}%
\medbreak
\label{module-Ocamlary-module-FunctorTypeOf-argument-1-Collection-module-InnerModuleA-module-InnerModuleA'}\ocamlcodefragment{\ocamltag{keyword}{module} \hyperref[module-Ocamlary-module-FunctorTypeOf-argument-1-Collection-module-InnerModuleA-module-InnerModuleA']{\ocamlinlinecode{InnerModuleA'}}}\ocamlcodefragment{ : \ocamltag{keyword}{sig}}\begin{ocamlindent}\label{module-Ocamlary-module-FunctorTypeOf-argument-1-Collection-module-InnerModuleA-module-InnerModuleA'-type-t}\ocamlcodefragment{\ocamltag{keyword}{type} t = ( unit,\allowbreak{} unit ) \hyperref[module-Ocamlary-type-a+u+function]{\ocamlinlinecode{a\_\allowbreak{}function}}}\begin{ocamlindent}This comment is for \ocamlinlinecode{t}.\end{ocamlindent}%
\label{module-Ocamlary-module-FunctorTypeOf-argument-1-Collection-module-InnerModuleA-module-InnerModuleA'}\ocamlcodefragment{\ocamltag{keyword}{module} \hyperref[module-Ocamlary-module-FunctorTypeOf-argument-1-Collection-module-InnerModuleA-module-InnerModuleA']{\ocamlinlinecode{InnerModuleA'}}}\ocamlcodefragment{ : \ocamltag{keyword}{sig}}\begin{ocamlindent}\label{module-Ocamlary-module-FunctorTypeOf-argument-1-Collection-module-InnerModuleA-module-InnerModuleA'-type-t}\ocamlcodefragment{\ocamltag{keyword}{type} t = (unit,\allowbreak{} unit) \hyperref[module-Ocamlary-type-a+u+function]{\ocamlinlinecode{a\_\allowbreak{}function}}}\begin{ocamlindent}This comment is for \ocamlinlinecode{t}.\end{ocamlindent}%
\medbreak
\end{ocamlindent}%
\ocamlcodefragment{\ocamltag{keyword}{end}}\begin{ocamlindent}This comment is for \ocamlinlinecode{InnerModuleA'}.\end{ocamlindent}%
Expand Down
Loading