Skip to content

Commit

Permalink
Add missing parentheses around identifier 'let*'
Browse files Browse the repository at this point in the history
  • Loading branch information
Julow committed Dec 20, 2024
1 parent 0677e3f commit 20010b2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
26 changes: 13 additions & 13 deletions src/model/names.ml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
(** 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 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
| _ -> if String.exists operator_char name then "(" ^ name ^ ")" else name

let contains_double_underscore s =
let len = String.length s in
Expand Down
12 changes: 6 additions & 6 deletions test/generators/html/Ocamlary-Op.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ <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 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 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">
Expand Down
4 changes: 2 additions & 2 deletions test/generators/latex/Ocamlary.tex
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,8 @@ \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-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}\\
Expand Down
4 changes: 2 additions & 2 deletions test/generators/man/Ocamlary.Op.3o
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Ocamlary\.Op
.SH Documentation
.sp
.nf
\f[CB]val\fR let* : int
\f[CB]val\fR (let*) : int
.sp
\f[CB]val\fR and* : int
\f[CB]val\fR (and*) : int
.sp
\f[CB]val\fR (\.%{}) : int
.sp
Expand Down

0 comments on commit 20010b2

Please sign in to comment.