Skip to content

Add missing parentheses around identifier 'let*' #1268

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 6 commits into from
Jan 9, 2025
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
This could happen with inline includes.
- Fix bug where source rendering would cause odoc to fail completely if it
encounters invalid syntax (@jonludlam #1208)
- Add missing parentheses in 'val (let*) : ...' (@Julow, #1268)

# 2.4.4

Expand Down
2 changes: 1 addition & 1 deletion src/html/generator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ module Toc = struct
in
let title_str =
List.map (Format.asprintf "%a" (Tyxml.Html.pp_elt ())) text
|> String.concat ""
|> String.concat ~sep:""
in
let href = Link.href ~config ~resolve url in
{ title; title_str; href; children = List.map section children }
Expand Down
4 changes: 2 additions & 2 deletions src/html/html_fragment_json.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Url = Odoc_document.Url

let json_of_html config h =
let htmlpp = Html.pp_elt ~indent:(Config.indent config) () in
String.concat "" (List.map (Format.asprintf "%a" htmlpp) h)
String.concat ~sep:"" (List.map (Format.asprintf "%a" htmlpp) h)

let json_of_breadcrumbs config (breadcrumbs : Types.breadcrumbs) : Json.json =
let breadcrumb (b : Types.breadcrumb) =
Expand Down Expand Up @@ -83,7 +83,7 @@ let make_src ~config ~url ~breadcrumbs ~sidebar content =
("global_toc", global_toc);
( "content",
`String
(String.concat ""
(String.concat ~sep:""
(List.map (Format.asprintf "%a" htmlpp) content)) );
]))
in
Expand Down
6 changes: 3 additions & 3 deletions src/html/html_page.ml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ let page_creator ~config ~url ~uses_katex ~global_toc header breadcrumbs

let head : Html_types.head Html.elt =
let title_string =
Printf.sprintf "%s (%s)" url.name (String.concat "." path)
Printf.sprintf "%s (%s)" url.name (String.concat ~sep:"." path)
in

let file_uri = file_uri ~config ~url in
Expand All @@ -157,7 +157,7 @@ let page_creator ~config ~url ~uses_katex ~global_toc header breadcrumbs
let search_urls =
let search_url name = Printf.sprintf "'%s'" name in
let search_urls = List.map search_url search_urls in
"[" ^ String.concat "," search_urls ^ "]"
"[" ^ String.concat ~sep:"," search_urls ^ "]"
in
(* The names of the search scripts are put into a js variable. Then
the code in [odoc_search.js] load them into a webworker. *)
Expand Down Expand Up @@ -259,7 +259,7 @@ let path_of_module_of_source ppf url =
match url.Url.Path.parent with
| Some parent ->
let path = Link.Path.for_printing parent in
Format.fprintf ppf " (%s)" (String.concat "." path)
Format.fprintf ppf " (%s)" (String.concat ~sep:"." path)
| None -> ()

let src_page_creator ~breadcrumbs ~config ~url ~header ~sidebar name content =
Expand Down
2 changes: 1 addition & 1 deletion src/html/sidebar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let toc_to_json
let inline =
let inline = Generator.inline ~config ~xref_base_uri:"" inline in
let inline =
String.concat ""
String.concat ~sep:""
@@ List.map (Format.asprintf "%a" (Tyxml.Html.pp_elt ())) inline
in
`String inline
Expand Down
2 changes: 1 addition & 1 deletion src/model/comment.ml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,6 @@ let to_string (l : link_content) =
and s_of_is is =
is
|> List.map (fun { Location_.value; _ } -> s_of_i value)
|> String.concat ""
|> String.concat ~sep:""
in
s_of_is l
35 changes: 19 additions & 16 deletions src/model/names.ml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
let parenthesise name =
match name with
| "asr" | "land" | "lor" | "lsl" | "lsr" | "lxor" | "mod" -> "(" ^ name ^ ")"
| _ ->
if String.length name > 0 then
match name.[0] with
| 'a' .. 'z'
| '\223' .. '\246'
| '\248' .. '\255'
| '_'
| 'A' .. 'Z'
| '\192' .. '\214'
| '\216' .. '\222' ->
name
| _ -> "(" ^ name ^ ")"
else name
open Odoc_utils

(** Returns [true] on chars that are part of operators. *)
let operator_char = function
(* https://ocaml.org/manual/5.2/lex.html#core-operator-char *)
| '$' | '&' | '*' | '+' | '-' | '/' | '=' | '>' | '@' | '^' | '|' | '~' | '!'
| '?' | '%' | '<' | ':' | '.'
(* https://ocaml.org/manual/5.2/lex.html#infix-symbol *)
| '#'
(* https://ocaml.org/manual/5.2/indexops.html#s:index-operators *)
| '(' | ')' | '[' | ']' | '{' | '}' ->
true
| _ -> false

let is_operator = function
| "asr" | "land" | "lor" | "lsl" | "lsr" | "lxor" | "mod" | "or" -> true
| name -> String.exists operator_char name

let parenthesise name = if is_operator name then "(" ^ name ^ ")" else name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to do "( " ^ name ^ " )" because of the ambiguous (*).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point!

Changing this code would change URLs, which is not fine. More work is needed to handle that in the generated code only. It's in src/document/generator.ml if you have some time to work on it.

let contains_double_underscore s =
let len = String.length s in
Expand Down
5 changes: 3 additions & 2 deletions src/model/semantics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ let leaf_inline_element :
match target with
| Some invalid_target
when String.trim invalid_target = ""
|| String.contains invalid_target '%'
|| String.contains invalid_target '}' ->
|| String.exists
(function '%' | '}' -> true | _ -> false)
invalid_target ->
Error.raise_warning
(invalid_raw_markup_target invalid_target location);

Expand Down
2 changes: 2 additions & 0 deletions src/ocamlary/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
(library
(name ocamlary)
(public_name odoc.ocamlary)
(enabled_if
(>= %{ocaml_version} 4.14.0))
(virtual_modules ocamlary))
13 changes: 13 additions & 0 deletions src/ocamlary/ocamlary.mli
Original file line number Diff line number Diff line change
Expand Up @@ -1068,3 +1068,16 @@ type new_t = ..
type new_t += C

module type TypeExtPruned = TypeExt with type t := new_t

module Op : sig
val ( let* ) : int
val ( and* ) : int
val ( .%{} ) : int
val ( .%{}<- ) : int
val ( .%{;..} ) : int
val ( .%{;..}<- ) : int
val ( !~ ) : int
val ( #~ ) : int
val ( or ) : int
val ( lsl ) : int
end
1 change: 0 additions & 1 deletion src/odoc/compile.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
open Astring
open Odoc_model
open Odoc_model.Names
open Or_error
Expand Down
2 changes: 1 addition & 1 deletion src/utils/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(library
(name odoc_utils)
(public_name odoc.odoc_utils)
(libraries result))
(libraries result astring))
2 changes: 2 additions & 0 deletions src/utils/odoc_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,5 @@ end
module Tree = Tree
module Forest = Tree.Forest
module Json = Json

include Astring
2 changes: 1 addition & 1 deletion test/generators/gen_rules/gen_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ let constraints =
[
("stop_dead_link_doc.mli", Min "4.04");
("bugs_post_406.mli", Min "4.06");
("ocamlary.mli", Min "4.07");
("ocamlary.mli", Min "4.14");
("recent.mli", Min "4.09");
("labels.mli", Min "4.09");
("recent_impl.ml", Min "4.09");
Expand Down
84 changes: 84 additions & 0 deletions test/generators/html/Ocamlary-Op.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Op (Ocamlary.Op)</title><meta charset="utf-8"/>
<link rel="stylesheet" href="odoc.css"/>
<meta name="generator" content="odoc %%VERSION%%"/>
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
<script src="highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Ocamlary.html">Up</a> –
<a href="index.html">🏠</a> &#x00BB;
<a href="Ocamlary.html">Ocamlary</a> &#x00BB; Op
</nav>
<header class="odoc-preamble">
<h1>Module <code><span>Ocamlary.Op</span></code></h1>
</header>
<div class="odoc-content">
<div class="odoc-spec">
<div class="spec value anchored" id="val-(let*)">
<a href="#val-(let*)" class="anchor"></a>
<code><span><span class="keyword">val</span> (let*) : int</span></code>
</div>
</div>
<div class="odoc-spec">
<div class="spec value anchored" id="val-(and*)">
<a href="#val-(and*)" class="anchor"></a>
<code><span><span class="keyword">val</span> (and*) : int</span></code>
</div>
</div>
<div class="odoc-spec">
<div class="spec value anchored" id="val-(.%{})">
<a href="#val-(.%{})" class="anchor"></a>
<code><span><span class="keyword">val</span> (.%{}) : int</span></code>
</div>
</div>
<div class="odoc-spec">
<div class="spec value anchored" id="val-(.%{}&lt;-)">
<a href="#val-(.%{}&lt;-)" class="anchor"></a>
<code><span><span class="keyword">val</span> (.%{}&lt;-) : int</span>
</code>
</div>
</div>
<div class="odoc-spec">
<div class="spec value anchored" id="val-(.%{;..})">
<a href="#val-(.%{;..})" class="anchor"></a>
<code><span><span class="keyword">val</span> (.%{;..}) : int</span>
</code>
</div>
</div>
<div class="odoc-spec">
<div class="spec value anchored" id="val-(.%{;..}&lt;-)">
<a href="#val-(.%{;..}&lt;-)" class="anchor"></a>
<code><span><span class="keyword">val</span> (.%{;..}&lt;-) : int</span>
</code>
</div>
</div>
<div class="odoc-spec">
<div class="spec value anchored" id="val-(!~)">
<a href="#val-(!~)" class="anchor"></a>
<code><span><span class="keyword">val</span> (!~) : int</span></code>
</div>
</div>
<div class="odoc-spec">
<div class="spec value anchored" id="val-(#~)">
<a href="#val-(#~)" class="anchor"></a>
<code><span><span class="keyword">val</span> (#~) : int</span></code>
</div>
</div>
<div class="odoc-spec">
<div class="spec value anchored" id="val-(or)">
<a href="#val-(or)" class="anchor"></a>
<code><span><span class="keyword">val</span> (or) : int</span></code>
</div>
</div>
<div class="odoc-spec">
<div class="spec value anchored" id="val-(lsl)">
<a href="#val-(lsl)" class="anchor"></a>
<code><span><span class="keyword">val</span> (lsl) : int</span></code>
</div>
</div>
</div>
</body>
</html>
13 changes: 13 additions & 0 deletions test/generators/html/Ocamlary.html
Original file line number Diff line number Diff line change
Expand Up @@ -2960,6 +2960,19 @@ <h2 id="new-reference-syntax">
</code>
</div>
</div>
<div class="odoc-spec">
<div class="spec module anchored" id="module-Op">
<a href="#module-Op" class="anchor"></a>
<code>
<span><span class="keyword">module</span>
<a href="Ocamlary-Op.html">Op</a>
</span>
<span> : <span class="keyword">sig</span> ...
<span class="keyword">end</span>
</span>
</code>
</div>
</div>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions test/generators/html/ocamlary.targets
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,4 @@ Ocamlary-M.html
Ocamlary-Only_a_module.html
Ocamlary-module-type-TypeExt.html
Ocamlary-module-type-TypeExtPruned.html
Ocamlary-Op.html
12 changes: 12 additions & 0 deletions test/generators/latex/Ocamlary.tex
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,18 @@ \subsection{New reference syntax\label{new-reference-syntax}}%
\label{Ocamlary-module-type-TypeExtPruned-val-f}\ocamlcodefragment{\ocamltag{keyword}{val} f : \hyperref[Ocamlary-type-new_t]{\ocamlinlinecode{new\_\allowbreak{}t}} \ocamltag{arrow}{$\rightarrow$} unit}\\
\end{ocamlindent}%
\ocamlcodefragment{\ocamltag{keyword}{end}}\\
\label{Ocamlary-module-Op}\ocamlcodefragment{\ocamltag{keyword}{module} \hyperref[Ocamlary-Op]{\ocamlinlinecode{Op}}}\ocamlcodefragment{ : \ocamltag{keyword}{sig}}\begin{ocamlindent}\label{Ocamlary-Op-val-(let*)}\ocamlcodefragment{\ocamltag{keyword}{val} (let*) : int}\\
\label{Ocamlary-Op-val-(and*)}\ocamlcodefragment{\ocamltag{keyword}{val} (and*) : int}\\
\label{Ocamlary-Op-val-(.+p++ob++cb+)}\ocamlcodefragment{\ocamltag{keyword}{val} (.\allowbreak{}\%\{\}) : int}\\
\label{Ocamlary-Op-val-(.+p++ob++cb+<-)}\ocamlcodefragment{\ocamltag{keyword}{val} (.\allowbreak{}\%\{\}<-) : int}\\
\label{Ocamlary-Op-val-(.+p++ob+;..+cb+)}\ocamlcodefragment{\ocamltag{keyword}{val} (.\allowbreak{}\%\{;\allowbreak{}.\allowbreak{}.\allowbreak{}\}) : int}\\
\label{Ocamlary-Op-val-(.+p++ob+;..+cb+<-)}\ocamlcodefragment{\ocamltag{keyword}{val} (.\allowbreak{}\%\{;\allowbreak{}.\allowbreak{}.\allowbreak{}\}<-) : int}\\
\label{Ocamlary-Op-val-(!+t+)}\ocamlcodefragment{\ocamltag{keyword}{val} (!\textasciitilde{}) : int}\\
\label{Ocamlary-Op-val-(#+t+)}\ocamlcodefragment{\ocamltag{keyword}{val} (\#\textasciitilde{}) : int}\\
\label{Ocamlary-Op-val-(or)}\ocamlcodefragment{\ocamltag{keyword}{val} (or) : int}\\
\label{Ocamlary-Op-val-(lsl)}\ocamlcodefragment{\ocamltag{keyword}{val} (lsl) : int}\\
\end{ocamlindent}%
\ocamlcodefragment{\ocamltag{keyword}{end}}\\

\input{Ocamlary.ModuleWithSignature.tex}
\input{Ocamlary.ModuleWithSignatureAlias.tex}
Expand Down
Loading
Loading