summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoroctachron <octa@polychoron.fr>2017-02-18 13:57:39 +0100
committeroctachron <octa@polychoron.fr>2017-07-31 23:01:02 +0200
commite5f94ee9d4e1e328df5eea2ae04b500612c08a03 (patch)
tree8fef5443e29a3d20c2e2134731efaa36ae24223c
parentcc27e58ea2aa23dbeb2736ebf1ee9a3cae6b1dbb (diff)
downloadocaml-e5f94ee9d4e1e328df5eea2ae04b500612c08a03.tar.gz
Factorize first comment before elements code
-rw-r--r--ocamldoc/odoc_ast.ml11
-rw-r--r--ocamldoc/odoc_sig.ml19
-rw-r--r--ocamldoc/odoc_sig.mli9
3 files changed, 21 insertions, 18 deletions
diff --git a/ocamldoc/odoc_ast.ml b/ocamldoc/odoc_ast.ml
index 4b3c25eac8..b1a027d403 100644
--- a/ocamldoc/odoc_ast.ml
+++ b/ocamldoc/odoc_ast.ml
@@ -1870,15 +1870,8 @@ module Analyser =
prepare_file source_file input_file;
(* We create the t_module for this file. *)
let mod_name = String.capitalize_ascii (Filename.basename (Filename.chop_extension source_file)) in
- let len, info_opt =
- let info = My_ir.first_special !file_name !file in
- (* Only use as module preamble documentation comments that occur before
- any module elements *)
- match parsetree with
- | a :: _ when a.Parsetree.pstr_loc.Location.loc_start.Lexing.pos_cnum <
- fst info ->
- (0,None)
- | _ -> info in
+ let len, info_opt = Sig.preamble !file_name !file
+ (fun x -> x.Parsetree.pstr_loc) parsetree in
(* we must complete the included modules *)
let elements = analyse_structure Odoc_env.empty mod_name len (String.length !file) parsetree tree_structure in
let included_modules_from_tt = tt_get_included_module_list tree_structure in
diff --git a/ocamldoc/odoc_sig.ml b/ocamldoc/odoc_sig.ml
index c88351a4dc..7dc9b3a51f 100644
--- a/ocamldoc/odoc_sig.ml
+++ b/ocamldoc/odoc_sig.ml
@@ -185,6 +185,14 @@ module Analyser =
!file_name
(get_string_of_file pos_start pos_end)
+ let preamble filename file proj ast =
+ let info = My_ir.first_special filename file in
+ (* Only use as module preamble documentation comments that occur before
+ any module elements *)
+ match ast with
+ | a :: _ when Loc.start (proj a) < fst info -> (0,None)
+ | _ -> info
+
let merge_infos = Odoc_merge.merge_info_opt Odoc_types.all_merge_options
(** Module for extracting documentation comments for record from different
@@ -1626,15 +1634,8 @@ module Analyser =
let mod_name = String.capitalize_ascii
(Filename.basename (try Filename.chop_extension source_file with _ -> source_file))
in
- let len, info_opt =
- let info = My_ir.first_special !file_name !file in
- (* Only use as module preamble documentation comments that occur before
- any module elements *)
- match ast with
- | a :: _ when a.Parsetree.psig_loc.Location.loc_start.Lexing.pos_cnum <
- fst info ->
- (0,None)
- | _ -> info in
+ let len, info_opt = preamble !file_name !file
+ (fun x -> x.Parsetree.psig_loc) ast in
let elements =
analyse_parsetree Odoc_env.empty signat mod_name len (String.length !file) ast
in
diff --git a/ocamldoc/odoc_sig.mli b/ocamldoc/odoc_sig.mli
index ddd1160739..8864e9963d 100644
--- a/ocamldoc/odoc_sig.mli
+++ b/ocamldoc/odoc_sig.mli
@@ -127,6 +127,15 @@ module Analyser :
[input_f] into [file].*)
val prepare_file : string -> string -> unit
+ (** [preamble f input_f loc ast ] retrieves the position and contents of
+ the preamble for the file [f]: i.e, the first documentation comment
+ before any elements in [ast].
+ If there is no such preamble, [0,None] is returned.
+ The function [loc] is used to obtain the location of this
+ first element of [ast].*)
+ val preamble: string -> string -> ('a -> Location.t) -> 'a list
+ -> int * Odoc_types.info option
+
(** The function used to get the comments in a class. *)
val get_comments_in_class : int -> int ->
(Odoc_types.info option * Odoc_class.class_element list)