Skip to content

Commit eb62d2e

Browse files
authored
Merge pull request #1693 from lpw25/fix-mpr7701
Keep documentation comments in structures with no other items (MPR#7701 cont.)
2 parents 305b1d0 + 1ca072a commit eb62d2e

9 files changed

Lines changed: 630 additions & 230 deletions

File tree

manual/manual/cmds/ocamldoc.etex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ type weather2 =
494494

495495
(** The comment for type my_record *)
496496
type my_record = {
497-
val foo : int ; (** Comment for field foo *)
498-
val bar : string ; (** Comment for field bar *)
497+
foo : int ; (** Comment for field foo *)
498+
bar : string ; (** Comment for field bar *)
499499
}
500500
(** Continuation of comment for type my_record *)
501501

@@ -541,8 +541,8 @@ class type my_class_type =
541541
end
542542

543543
(** The comment for module Foo *)
544-
module Foo =
545-
struct
544+
module Foo :
545+
sig
546546
(** The comment for x *)
547547
val x : int
548548

@@ -556,8 +556,8 @@ module type my_module_type =
556556
val x : int
557557

558558
(** The comment for module M. *)
559-
module M =
560-
struct
559+
module M :
560+
sig
561561
(** The comment for value y. *)
562562
val y : int
563563

@@ -606,8 +606,8 @@ type weather =
606606

607607
(** The comment for type my_record *)
608608
type my_record = {
609-
val foo : int ; (** Comment for field foo *)
610-
val bar : string ; (** Comment for field bar *)
609+
foo : int ; (** Comment for field foo *)
610+
bar : string ; (** Comment for field bar *)
611611
}
612612

613613
(** The comment for class my_class *)

parsing/docstrings.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ let get_text pos =
243243
get_docstrings dsl
244244
with Not_found -> []
245245

246+
let get_post_text pos =
247+
try
248+
let dsl = Hashtbl.find post_table pos in
249+
get_docstrings dsl
250+
with Not_found -> []
251+
246252
(* Maps from positions to extra docstrings *)
247253

248254
let pre_extra_table : (Lexing.position, docstring list) Hashtbl.t =
@@ -315,6 +321,9 @@ let symbol_text_lazy () =
315321
let rhs_text pos =
316322
get_text (Parsing.rhs_start_pos pos)
317323

324+
let rhs_post_text pos =
325+
get_post_text (Parsing.rhs_end_pos pos)
326+
318327
let rhs_text_lazy pos =
319328
let pos = Parsing.rhs_start_pos pos in
320329
lazy (get_text pos)

parsing/docstrings.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,6 @@ val rhs_pre_extra_text : int -> text
155155

156156
(** Fetch additional text following the symbol at the given position *)
157157
val rhs_post_extra_text : int -> text
158+
159+
(** Fetch text following the symbol at the given position *)
160+
val rhs_post_text : int -> text

parsing/parser.mly

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,15 @@ let text_csig pos = Ctf.text (rhs_text pos)
290290
let text_def pos = [Ptop_def (Str.text (rhs_text pos))]
291291

292292
let extra_text text pos items =
293-
let pre_extras = rhs_pre_extra_text pos in
294-
let post_extras = rhs_post_extra_text pos in
295-
text pre_extras @ items @ text post_extras
293+
match items with
294+
| [] ->
295+
let post = rhs_post_text pos in
296+
let post_extras = rhs_post_extra_text pos in
297+
text post @ text post_extras
298+
| _ :: _ ->
299+
let pre_extras = rhs_pre_extra_text pos in
300+
let post_extras = rhs_post_extra_text pos in
301+
text pre_extras @ items @ text post_extras
296302

297303
let extra_str pos items = extra_text Str.text pos items
298304
let extra_sig pos items = extra_text Sig.text pos items

testsuite/tests/docstrings/empty.compilers.reference

Lines changed: 0 additions & 52 deletions
This file was deleted.

testsuite/tests/docstrings/empty.ml

Lines changed: 0 additions & 13 deletions
This file was deleted.

testsuite/tests/docstrings/ocamltests

Lines changed: 0 additions & 1 deletion
This file was deleted.

testsuite/tests/parsing/docstrings.compilers.reference

Lines changed: 0 additions & 146 deletions
This file was deleted.

0 commit comments

Comments
 (0)