Skip to content

Commit

Permalink
Provide an interface for ocamldoc's odoc_parameter module
Browse files Browse the repository at this point in the history
  • Loading branch information
shindere committed Jun 30, 2022
1 parent bfd54b0 commit 0d8a766
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 27 deletions.
25 changes: 15 additions & 10 deletions ocamldoc/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ odoc_ast.cmo : \
odoc_types.cmi \
odoc_type.cmo \
odoc_sig.cmi \
odoc_parameter.cmo \
odoc_parameter.cmi \
odoc_module.cmo \
odoc_messages.cmi \
odoc_global.cmi \
Expand Down Expand Up @@ -160,7 +160,7 @@ odoc_class.cmo : \
../typing/types.cmi \
odoc_value.cmo \
odoc_types.cmi \
odoc_parameter.cmo \
odoc_parameter.cmi \
odoc_name.cmi
odoc_class.cmx : \
../typing/types.cmx \
Expand Down Expand Up @@ -217,7 +217,7 @@ odoc_cross.cmo : \
odoc_type.cmo \
odoc_search.cmi \
odoc_scan.cmo \
odoc_parameter.cmo \
odoc_parameter.cmi \
odoc_name.cmi \
odoc_module.cmo \
odoc_misc.cmi \
Expand Down Expand Up @@ -380,7 +380,7 @@ odoc_info.cmo : \
odoc_search.cmi \
odoc_scan.cmo \
odoc_print.cmi \
odoc_parameter.cmo \
odoc_parameter.cmi \
odoc_name.cmi \
odoc_module.cmo \
odoc_misc.cmi \
Expand Down Expand Up @@ -424,7 +424,7 @@ odoc_info.cmi : \
odoc_types.cmi \
odoc_type.cmo \
odoc_search.cmi \
odoc_parameter.cmo \
odoc_parameter.cmi \
odoc_module.cmo \
odoc_global.cmi \
odoc_extension.cmo \
Expand Down Expand Up @@ -476,7 +476,7 @@ odoc_merge.cmo : \
odoc_value.cmo \
odoc_types.cmi \
odoc_type.cmo \
odoc_parameter.cmo \
odoc_parameter.cmi \
odoc_module.cmo \
odoc_messages.cmi \
odoc_global.cmi \
Expand Down Expand Up @@ -567,10 +567,15 @@ odoc_ocamlhtml.cmo :
odoc_ocamlhtml.cmx :
odoc_parameter.cmo : \
../typing/types.cmi \
odoc_types.cmi
odoc_types.cmi \
odoc_parameter.cmi
odoc_parameter.cmx : \
../typing/types.cmx \
odoc_types.cmx
odoc_types.cmx \
odoc_parameter.cmi
odoc_parameter.cmi : \
../typing/types.cmi \
odoc_types.cmi
odoc_parser.cmo : \
odoc_types.cmi \
odoc_comments_global.cmi \
Expand Down Expand Up @@ -648,7 +653,7 @@ odoc_sig.cmo : \
odoc_value.cmo \
odoc_types.cmi \
odoc_type.cmo \
odoc_parameter.cmo \
odoc_parameter.cmi \
odoc_module.cmo \
odoc_misc.cmi \
odoc_messages.cmi \
Expand Down Expand Up @@ -820,7 +825,7 @@ odoc_types.cmi : \
odoc_value.cmo : \
../typing/types.cmi \
odoc_types.cmi \
odoc_parameter.cmo \
odoc_parameter.cmi \
odoc_name.cmi \
odoc_misc.cmi \
../parsing/asttypes.cmi
Expand Down
2 changes: 1 addition & 1 deletion ocamldoc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ OCAMLDOC_LIBCMXA=odoc_info.cmxa
OCAMLDOC_LIBA=odoc_info.$(A)

OCAMLDOC_LIBMLIS=$(addsuffix .mli,\
odoc_info odoc_text_lexer odoc_messages)
odoc_info odoc_text_lexer odoc_messages odoc_parameter)
OCAMLDOC_LIBCMIS=$(OCAMLDOC_LIBMLIS:.mli=.cmi)
OCAMLDOC_LIBCMTS=$(OCAMLDOC_LIBMLIS:.mli=.cmt) $(OCAMLDOC_LIBMLIS:.mli=.cmti)

Expand Down
16 changes: 0 additions & 16 deletions ocamldoc/odoc_parameter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,20 @@

(** Types *)

(** Representation of a simple parameter name *)
type simple_name = {
sn_name : string ;
sn_type : Types.type_expr ;
mutable sn_text : Odoc_types.text option ;
}

(** Representation of parameter names. We need it to represent parameter names in tuples.
The value [Tuple ([], t)] stands for an anonymous parameter.*)
type param_info =
| Simple_name of simple_name
| Tuple of param_info list * Types.type_expr

(** A parameter is just a param_info.*)
type parameter = param_info

(** Functions *)

(** access to the name as a string. For tuples, parentheses and commas are added. *)
let complete_name p =
let rec iter pi =
match pi with
Expand All @@ -48,14 +43,11 @@ let complete_name p =
in
iter p

(** access to the complete type *)
let typ pi =
match pi with
Simple_name sn -> sn.sn_type
| Tuple (_, typ) -> typ

(** Update the text of a parameter using a function returning
the optional text associated to a parameter name.*)
let update_parameter_text f p =
let rec iter pi =
match pi with
Expand All @@ -66,8 +58,6 @@ let update_parameter_text f p =
in
iter p

(** access to the description of a specific name.
@raise Not_found if no description is associated to the given name. *)
let desc_by_name pi name =
let rec iter acc pi =
match pi with
Expand All @@ -79,9 +69,6 @@ let desc_by_name pi name =
let l = iter [] pi in
List.assoc name l


(** access to the list of names ; only one for a simple parameter, or
a list for tuples. *)
let names pi =
let rec iter acc pi =
match pi with
Expand All @@ -92,8 +79,6 @@ let names pi =
in
iter [] pi

(** access to the type of a specific name.
@raise Not_found if no type is associated to the given name. *)
let type_by_name pi name =
let rec iter acc pi =
match pi with
Expand All @@ -105,7 +90,6 @@ let type_by_name pi name =
let l = iter [] pi in
List.assoc name l

(** access to the optional description of a parameter name from an optional info structure.*)
let desc_from_info_opt info_opt s =
match info_opt with
None -> None
Expand Down
63 changes: 63 additions & 0 deletions ocamldoc/odoc_parameter.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Sebastien Hinderer, projet Cambium, INRIA Paris *)
(* *)
(* Copyright 2022 Institut National de Recherche en Informatique et *)
(* en Automatique. *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)

(** Representation and manipulation of method / function / class parameters. *)

(** Types *)

type simple_name = {
sn_name : string;
sn_type : Types.type_expr;
mutable sn_text : Odoc_types.text option;
}
(** Representation of a simple parameter name *)

type param_info =
Simple_name of simple_name
| Tuple of param_info list * Types.type_expr
(** Representation of parameter names. We need it to represent parameter names in tuples.
The value [Tuple ([], t)] stands for an anonymous parameter.*)

type parameter = param_info
(** A parameter is just a param_info.*)

(** Functions *)

val complete_name : parameter -> string
(** access to the name as a string. For tuples, parentheses and commas are added. *)

val typ : parameter -> Types.type_expr
(** access to the complete type *)

val update_parameter_text :
(string -> Odoc_types.text option) -> parameter -> unit
(** Update the text of a parameter using a function returning
the optional text associated to a parameter name.*)

val desc_by_name : parameter -> string -> Odoc_types.text option
(** access to the description of a specific name.
@raise Not_found if no description is associated to the given name. *)

val names : parameter -> string list
(** access to the list of names ; only one for a simple parameter, or
a list for tuples. *)

val type_by_name : parameter -> string -> Types.type_expr
(** access to the type of a specific name.
@raise Not_found if no type is associated to the given name. *)

val desc_from_info_opt :
Odoc_types.info option -> string -> Odoc_types.text option
(** access to the optional description of a parameter name from an optional info structure.*)

0 comments on commit 0d8a766

Please sign in to comment.