Skip to content

Commit 69bb3d9

Browse files
sim642Julow
andcommitted
Add raise tag reference
Co-authored-by: Jules Aguillon <[email protected]>
1 parent 5a741da commit 69bb3d9

File tree

11 files changed

+50
-26
lines changed

11 files changed

+50
-26
lines changed

src/document/comment.ml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,11 @@ let tag : Comment.tag -> Description.one =
274274
let sp = inline (Text " ") in
275275
let item ?value ~tag definition =
276276
let tag_name = inline ~attr:[ "at-tag" ] (Text tag) in
277-
let tag_value =
278-
match value with
279-
| None -> []
280-
| Some t -> [ sp; inline ~attr:[ "value" ] t ]
281-
in
277+
let tag_value = match value with None -> [] | Some t -> sp :: t in
282278
let key = tag_name :: tag_value in
283279
{ Description.attr = [ tag ]; key; definition }
284280
in
281+
let mk_value desc = [ inline ~attr:[ "value" ] desc ] in
285282
let text_def s = [ block (Block.Inline [ inline @@ Text s ]) ] in
286283
let content_to_inline ?(prefix = []) content =
287284
match content with
@@ -293,23 +290,23 @@ let tag : Comment.tag -> Description.one =
293290
| `Deprecated content ->
294291
item ~tag:"deprecated" (nestable_block_element_list content)
295292
| `Param (name, content) ->
296-
let value = Inline.Text name in
293+
let value = mk_value (Inline.Text name) in
297294
item ~tag:"parameter" ~value (nestable_block_element_list content)
298-
| `Raise (name, content) ->
299-
let value = Inline.Text name in
295+
| `Raise (kind, content) ->
296+
let value = inline_element (kind :> Comment.inline_element) in
300297
item ~tag:"raises" ~value (nestable_block_element_list content)
301298
| `Return content -> item ~tag:"returns" (nestable_block_element_list content)
302299
| `See (kind, target, content) ->
303300
let value =
304301
match kind with
305-
| `Url -> Inline.Link (target, [ inline @@ Text target ])
306-
| `File -> Inline.Source (source_of_code target)
307-
| `Document -> Inline.Text target
302+
| `Url -> mk_value (Inline.Link (target, [ inline @@ Text target ]))
303+
| `File -> mk_value (Inline.Source (source_of_code target))
304+
| `Document -> mk_value (Inline.Text target)
308305
in
309306
item ~tag:"see" ~value (nestable_block_element_list content)
310307
| `Since s -> item ~tag:"since" (text_def s)
311308
| `Before (version, content) ->
312-
let value = Inline.Text version in
309+
let value = mk_value (Inline.Text version) in
313310
item ~tag:"before" ~value (nestable_block_element_list content)
314311
| `Version s -> item ~tag:"version" (text_def s)
315312
| `Alert ("deprecated", content) ->

src/model/comment.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ type non_link_inline_element =
2424
cross-referencer. *)
2525
type link_content = non_link_inline_element with_location list
2626

27+
type reference_element = [ `Reference of Reference.t * link_content ]
28+
2729
type inline_element =
2830
[ leaf_inline_element
2931
| `Styled of style * inline_element with_location list
30-
| `Reference of Reference.t * link_content
32+
| reference_element
3133
| `Link of string * link_content ]
3234

3335
type paragraph = inline_element with_location list
@@ -53,7 +55,9 @@ type tag =
5355
[ `Author of string
5456
| `Deprecated of nestable_block_element with_location list
5557
| `Param of string * nestable_block_element with_location list
56-
| `Raise of string * nestable_block_element with_location list
58+
| `Raise of
59+
[ `Code_span of string | reference_element ]
60+
* nestable_block_element with_location list
5761
| `Return of nestable_block_element with_location list
5862
| `See of
5963
[ `Url | `File | `Document ]

src/model/semantics.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,17 @@ let tag :
271271
ok (`Deprecated (nestable_block_elements status content))
272272
| `Param (name, content) ->
273273
ok (`Param (name, nestable_block_elements status content))
274-
| `Raise (name, content) ->
275-
ok (`Raise (name, nestable_block_elements status content))
274+
| `Raise (name, content) -> (
275+
match Error.raise_warnings (Reference.parse location name) with
276+
(* TODO: location for just name *)
277+
| Result.Ok target ->
278+
ok
279+
(`Raise
280+
(`Reference (target, []), nestable_block_elements status content))
281+
| Result.Error error ->
282+
Error.raise_warning error;
283+
let placeholder = `Code_span name in
284+
ok (`Raise (placeholder, nestable_block_elements status content)))
276285
| `Return content -> ok (`Return (nestable_block_elements status content))
277286
| `See (kind, target, content) ->
278287
ok (`See (kind, target, nestable_block_elements status content))

src/model_desc/comment_desc.ml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ and general_tag =
3333
[ `Author of string
3434
| `Deprecated of general_docs
3535
| `Param of string * general_docs
36-
| `Raise of string * general_docs
36+
| `Raise of
37+
[ `Code_span of string
38+
| `Reference of Paths.Reference.t * general_link_content ]
39+
* general_docs
3740
| `Return of general_docs
3841
| `See of [ `Url | `File | `Document ] * string * general_docs
3942
| `Since of string
@@ -124,7 +127,11 @@ and tag : general_tag t =
124127
| `Author x -> C ("`Author", x, string)
125128
| `Deprecated x -> C ("`Deprecated", x, docs)
126129
| `Param (x1, x2) -> C ("`Param", (x1, x2), Pair (string, docs))
127-
| `Raise (x1, x2) -> C ("`Raise", (x1, x2), Pair (string, docs))
130+
| `Raise (x1, x2) ->
131+
C
132+
( "`Raise",
133+
((x1 :> general_inline_element), x2),
134+
Pair (inline_element, docs) )
128135
| `Return x -> C ("`Return", x, docs)
129136
| `See (x1, x2, x3) ->
130137
C ("`See", (x1, x2, x3), Triple (url_kind, string, docs))

test/generators/html/Markup.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ <h2 id="math"><a href="#math" class="anchor"></a>Math</h2>
240240
</ul>
241241
<ul class="at-tags">
242242
<li class="raises"><span class="at-tag">raises</span>
243-
<span class="value">Failure</span> <p>always</p>
243+
<code>Failure</code> <p>always</p>
244244
</li>
245245
</ul>
246246
<ul class="at-tags">

test/generators/html/Ocamlary.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ <h4 id="basic-type-and-value-stuff-with-advanced-doc-comments">
447447
<div class="spec-doc">
448448
<ul class="at-tags">
449449
<li class="raises"><span class="at-tag">raises</span>
450-
<span class="value">Not_found</span> <p>That's all it does</p>
450+
<code>Not_found</code> <p>That's all it does</p>
451451
</li>
452452
</ul>
453453
</div>

test/generators/html/Tag_link.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ <h1>Module <code><span>Tag_link</span></code></h1>
3030
</li>
3131
</ul>
3232
<ul class="at-tags">
33-
<li class="raises"><span class="at-tag">raises</span>
34-
<span class="value">Foo</span>
35-
<p><a href="#val-foo"><code>foo</code></a></p>
33+
<li class="raises"><span class="at-tag">raises</span> <code>Foo</code>
34+
<p><a href="#val-foo"><code>foo</code></a></p>
3635
</li>
3736
</ul>
3837
<ul class="at-tags">

test/generators/latex/Markup.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ \subsection{Tags\label{tags}}%
119119
}\end{description}%
120120
\begin{description}\kern-\topsep
121121
\makeatletter\advance\@topsepadd-\topsep\makeatother% topsep is hardcoded
122-
\item[{raises Failure}]{always
122+
\item[{raises \ocamlinlinecode{Failure}}]{always
123123

124124
}\end{description}%
125125
\begin{description}\kern-\topsep

test/generators/latex/Ocamlary.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ \subsubsection{Basic type and value stuff with advanced doc comments\label{basic
147147
\label{module-Ocamlary-val-fun_maybe}\ocamlcodefragment{\ocamltag{keyword}{val} fun\_\allowbreak{}maybe : ?yes:unit \ocamltag{arrow}{$\rightarrow$} unit \ocamltag{arrow}{$\rightarrow$} int}\\
148148
\label{module-Ocamlary-val-not_found}\ocamlcodefragment{\ocamltag{keyword}{val} not\_\allowbreak{}found : unit \ocamltag{arrow}{$\rightarrow$} unit}\begin{ocamlindent}\begin{description}\kern-\topsep
149149
\makeatletter\advance\@topsepadd-\topsep\makeatother% topsep is hardcoded
150-
\item[{raises Not\_\allowbreak{}found}]{That's all it does}\end{description}%
150+
\item[{raises \ocamlinlinecode{Not\_\allowbreak{}found}}]{That's all it does}\end{description}%
151151
\end{ocamlindent}%
152152
\medbreak
153153
\label{module-Ocamlary-val-ocaml_org}\ocamlcodefragment{\ocamltag{keyword}{val} ocaml\_\allowbreak{}org : string}\begin{ocamlindent}\begin{description}\kern-\topsep

test/generators/latex/Tag_link.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ \section{Module \ocamlinlinecode{Tag\_\allowbreak{}link}}\label{module-Tag_link}
1212
}\end{description}%
1313
\begin{description}\kern-\topsep
1414
\makeatletter\advance\@topsepadd-\topsep\makeatother% topsep is hardcoded
15-
\item[{raises Foo}]{\hyperref[module-Tag_link-val-foo]{\ocamlinlinecode{\ocamlinlinecode{foo}}[p\pageref*{module-Tag_link-val-foo}]}
15+
\item[{raises \ocamlinlinecode{Foo}}]{\hyperref[module-Tag_link-val-foo]{\ocamlinlinecode{\ocamlinlinecode{foo}}[p\pageref*{module-Tag_link-val-foo}]}
1616

1717
}\end{description}%
1818
\begin{description}\kern-\topsep

0 commit comments

Comments
 (0)