diff options
author | Damien Doligez <damien.doligez-inria.fr> | 2005-03-24 17:20:54 +0000 |
---|---|---|
committer | Damien Doligez <damien.doligez-inria.fr> | 2005-03-24 17:20:54 +0000 |
commit | e6007f6057d1d4e68a5618f232953344b683a168 (patch) | |
tree | ee5baa59e5eb0ebc4354bd215bd3c682986bf632 /ocamldoc | |
parent | 958bd6c49292afa23e5fee51770c45d1f8499faa (diff) | |
download | ocaml-e6007f6057d1d4e68a5618f232953344b683a168.tar.gz |
fusion des changements jusqu'a 3.08.3
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@6824 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'ocamldoc')
-rw-r--r-- | ocamldoc/Changes.txt | 4 | ||||
-rw-r--r-- | ocamldoc/Makefile | 2 | ||||
-rw-r--r-- | ocamldoc/odoc_args.ml | 36 | ||||
-rw-r--r-- | ocamldoc/odoc_args.mli | 48 | ||||
-rw-r--r-- | ocamldoc/odoc_info.mli | 187 | ||||
-rw-r--r-- | ocamldoc/odoc_man.ml | 33 | ||||
-rw-r--r-- | ocamldoc/odoc_messages.ml | 47 | ||||
-rw-r--r-- | ocamldoc/odoc_misc.ml | 85 | ||||
-rw-r--r-- | ocamldoc/odoc_misc.mli | 10 | ||||
-rw-r--r-- | ocamldoc/odoc_sig.ml | 2 | ||||
-rw-r--r-- | ocamldoc/odoc_str.ml | 49 |
11 files changed, 273 insertions, 230 deletions
diff --git a/ocamldoc/Changes.txt b/ocamldoc/Changes.txt index e7f1045b5f..ce6bf4e543 100644 --- a/ocamldoc/Changes.txt +++ b/ocamldoc/Changes.txt @@ -4,6 +4,10 @@ TODO: - utilisation nouvelles infos de Xavier: "début de rec", etc. ===== +Release 3.08.2: + - fix: error "Lexing: empty token" (PR#3173) + +===== Release 3.08.1: - add: new -intf and -impl options supported (PR#3036) - fix: display of class parameters in HTML and LaTeX (PR#2994) diff --git a/ocamldoc/Makefile b/ocamldoc/Makefile index 5e44036c92..a5d47a7b92 100644 --- a/ocamldoc/Makefile +++ b/ocamldoc/Makefile @@ -312,7 +312,7 @@ test_texi: dummy stdlib_man/Pervasives.3o: $(STDLIB_MLIS) $(MKDIR) stdlib_man $(OCAMLDOC_RUN) -man -d stdlib_man $(INCLUDES) \ - -t "OCaml library" -man-mini -man-suffix 3o \ + -t "OCaml library" -man-mini \ $(STDLIB_MLIS) autotest_stdlib: dummy diff --git a/ocamldoc/odoc_args.ml b/ocamldoc/odoc_args.ml index 903a4c3dca..05d9e55c11 100644 --- a/ocamldoc/odoc_args.ml +++ b/ocamldoc/odoc_args.ml @@ -45,6 +45,7 @@ let dot_reduce = ref false let dot_colors = ref (List.flatten M.default_dot_colors) let man_suffix = ref M.default_man_suffix +let man_section = ref M.default_man_section let man_mini = ref false @@ -76,7 +77,7 @@ let analyse_merge_options s = (M.merge_return_value, [Odoc_types.Merge_return_value]) ; (M.merge_custom, [Odoc_types.Merge_custom]) ; (M.merge_all, Odoc_types.all_merge_options) - ] + ] in analyse_option_string l s @@ -122,9 +123,9 @@ let index_only = ref false let colorize_code = ref false -let with_header = ref true +let with_header = ref true -let with_trailer = ref true +let with_trailer = ref true let separate_files = ref false @@ -136,7 +137,7 @@ let latex_titles = ref [ 5, "subparagraph" ; ] -let with_toc = ref true +let with_toc = ref true let with_index = ref true @@ -157,19 +158,19 @@ let f_latex_title s = latex_titles := List.remove_assoc n !latex_titles ; latex_titles := (n, command) :: !latex_titles with - Not_found - | Invalid_argument _ -> + Not_found + | Invalid_argument _ -> incr Odoc_global.errors ; prerr_endline (M.wrong_format s) let add_hidden_modules s = let l = Str.split (Str.regexp ",") s in - List.iter + List.iter (fun n -> let name = Str.global_replace (Str.regexp "[ \n\r\t]+") "" n in match name with "" -> () - | _ -> + | _ -> match name.[0] with 'A'..'Z' -> hidden_modules := name :: !hidden_modules | _ -> @@ -231,7 +232,7 @@ let options = ref [ "-t", Arg.String (fun s -> title := Some s), M.option_title ; "-intro", Arg.String (fun s -> intro_file := Some s), M.option_intro ; "-hide", Arg.String add_hidden_modules, M.hide_modules ; - "-m", Arg.String (fun s -> merge_options := !merge_options @ (analyse_merge_options s)), + "-m", Arg.String (fun s -> merge_options := !merge_options @ (analyse_merge_options s)), M.merge_options ^ "\n\n *** choosing a generator ***\n"; @@ -239,7 +240,7 @@ let options = ref [ "-html", Arg.Unit (fun () -> set_doc_generator !default_html_generator), M.generate_html ; "-latex", Arg.Unit (fun () -> set_doc_generator !default_latex_generator), M.generate_latex ; "-texi", Arg.Unit (fun () -> set_doc_generator !default_texi_generator), M.generate_texinfo ; - "-man", Arg.Unit (fun () -> set_doc_generator !default_man_generator), M.generate_man ; + "-man", Arg.Unit (fun () -> set_doc_generator !default_man_generator), M.generate_man ; "-dot", Arg.Unit (fun () -> set_doc_generator !default_dot_generator), M.generate_dot ; "-customdir", Arg.Unit (fun () -> Printf.printf "%s\n" Odoc_config.custom_generators_path; exit 0), M.display_custom_generators_dir ; @@ -270,7 +271,7 @@ let options = ref [ "-latex-module-type-prefix", Arg.String (fun s -> latex_module_type_prefix := s), M.latex_module_type_prefix ; "-latex-class-prefix", Arg.String (fun s -> latex_class_prefix := s), M.latex_class_prefix ; "-latex-class-type-prefix", Arg.String (fun s -> latex_class_type_prefix := s), M.latex_class_type_prefix ; - "-notoc", Arg.Unit (fun () -> with_toc := false), + "-notoc", Arg.Unit (fun () -> with_toc := false), M.no_toc ^ "\n\n *** texinfo options ***\n"; @@ -278,8 +279,8 @@ let options = ref [ "-noindex", Arg.Clear with_index, M.no_index ; "-esc8", Arg.Set esc_8bits, M.esc_8bits ; "-info-section", Arg.String ((:=) info_section), M.info_section ; - "-info-entry", Arg.String (fun s -> info_entry := !info_entry @ [ s ]), - M.info_entry ^ + "-info-entry", Arg.String (fun s -> info_entry := !info_entry @ [ s ]), + M.info_entry ^ "\n\n *** dot options ***\n"; (* dot only options *) @@ -292,10 +293,11 @@ let options = ref [ (* man only options *) "-man-mini", Arg.Set man_mini, M.man_mini ; "-man-suffix", Arg.String (fun s -> man_suffix := s), M.man_suffix ; + "-man-section", Arg.String (fun s -> man_section := s), M.man_section ; -] +] -let add_option o = +let add_option o = let (s,_,_) = o in let rec iter = function [] -> [o] @@ -309,7 +311,7 @@ let add_option o = let parse ~html_generator ~latex_generator ~texi_generator ~man_generator ~dot_generator = let anonymous f = - let sf = + let sf = if Filename.check_suffix f "ml" then Impl_file f else @@ -330,6 +332,6 @@ let parse ~html_generator ~latex_generator ~texi_generator ~man_generator ~dot_g (M.usage^M.options_are) in (* we sort the hidden modules by name, to be sure that for example, - A.B is before A, so we will match against A.B before A in + A.B is before A, so we will match against A.B before A in Odoc_name.hide_modules.*) hidden_modules := List.sort (fun a -> fun b -> - (compare a b)) !hidden_modules diff --git a/ocamldoc/odoc_args.mli b/ocamldoc/odoc_args.mli index 3dc6399697..e7f2dda8b1 100644 --- a/ocamldoc/odoc_args.mli +++ b/ocamldoc/odoc_args.mli @@ -21,38 +21,38 @@ type source_file = (** The include_dirs in the OCaml compiler. *) val include_dirs : string list ref -(** Indicate if we are in bytecode mode or not. +(** Indicate if we are in bytecode mode or not. (For the [ocamldoc] command).*) val bytecode_mode : bool ref (** The class type of documentation generators. *) class type doc_generator = object method generate : Odoc_module.t_module list -> unit end - + (** The function to be used to create a generator. *) val doc_generator : doc_generator option ref - + (** The merge options to be used. *) val merge_options : Odoc_types.merge_option list ref (** Classic mode or not. *) val classic : bool ref - + (** The file used by the generators outputting only one file. *) val out_file : string ref (** The optional file name to dump the collected information into.*) val dump : string option ref - + (** The list of information files to load. *) val load : string list ref - + (** Verbose mode or not. *) val verbose : bool ref - + (** We must sort the list of top modules or not.*) val sort_modules : bool ref - + (** We must not stop at the stop special comments. Default is false (we stop).*) val no_stop : bool ref @@ -67,10 +67,10 @@ val keep_code : bool ref (** To inverse implementation and interface files when merging. *) val inverse_merge_ml_mli : bool ref - + (** The optional title to use in the generated documentation. *) val title : string option ref - + (** The optional file whose content can be used as intro text. *) val intro_file : string option ref @@ -83,7 +83,7 @@ val hidden_modules : string list ref (** The directory where files have to be generated. *) val target_dir : string ref - + (** An optional file to use where a CSS style is defined (for HTML). *) val css_style : string option ref @@ -95,10 +95,10 @@ val colorize_code : bool ref (** The flag which indicates if we must generate a header (for LaTeX). *) val with_header : bool ref - + (** The flag which indicates if we must generate a trailer (for LaTeX). *) val with_trailer : bool ref - + (** The flag to indicate if we must generate one file per module (for LaTeX). *) val separate_files : bool ref @@ -162,25 +162,27 @@ val dot_colors : string list ref (** The suffix for man pages. *) val man_suffix : string ref +(** The section for man pages. *) +val man_section : string ref + (** The flag to generate all man pages or only for modules and classes.*) val man_mini : bool ref (** The files to be analysed. *) val files : source_file list ref - + (** To set the documentation generator. *) val set_doc_generator : doc_generator option -> unit - + (** Add an option specification. *) val add_option : string * Arg.spec * string -> unit - -(** Parse the args. + +(** Parse the args. [byte] indicate if we are in bytecode mode (default is [true]).*) val parse : - html_generator:doc_generator -> - latex_generator:doc_generator -> - texi_generator:doc_generator -> - man_generator:doc_generator -> - dot_generator:doc_generator -> + html_generator:doc_generator -> + latex_generator:doc_generator -> + texi_generator:doc_generator -> + man_generator:doc_generator -> + dot_generator:doc_generator -> unit - diff --git a/ocamldoc/odoc_info.mli b/ocamldoc/odoc_info.mli index 4175a7842b..b6eb967c50 100644 --- a/ocamldoc/odoc_info.mli +++ b/ocamldoc/odoc_info.mli @@ -57,14 +57,14 @@ and text_element = Odoc_types.text_element = and text = text_element list (** The different forms of references in \@see tags. *) -type see_ref = Odoc_types.see_ref = +type see_ref = Odoc_types.see_ref = See_url of string | See_file of string | See_doc of string (** Raised when parsing string to build a {!Odoc_info.text} structure. [(line, char, string)] *) -exception Text_syntax of int * int * string +exception Text_syntax of int * int * string (** The information in a \@see tag. *) type see = see_ref * text @@ -87,13 +87,13 @@ type info = Odoc_types.info = { i_raised_exceptions : raised_exception list; (** The list of raised exceptions. *) i_return_value : text option; (** The description text of the return value. *) i_custom : (string * text) list ; (** A text associated to a custom @-tag. *) - } + } (** Location of elements in implementation and interface files. *) type location = Odoc_types.location = { loc_impl : (string * int) option ; (** implementation file name and position *) loc_inter : (string * int) option ; (** interface file name and position *) - } + } (** A dummy location. *) val dummy_loc : location @@ -130,9 +130,9 @@ module Parameter : sn_name : string ; sn_type : Types.type_expr ; mutable sn_text : text option ; - } + } - (** Representation of parameter names. We need it to represent parameter names in tuples. + (** 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 = Odoc_parameter.param_info = Simple_name of simple_name @@ -156,55 +156,55 @@ module Parameter : @raise Not_found if no description is associated to the given name. *) val desc_by_name : parameter -> string -> text option - (** Access to the type of a specific name. + (** Access to the type of a specific name. @raise Not_found if no type is associated to the given name. *) val type_by_name : parameter -> string -> Types.type_expr end - + (** Representation and manipulation of exceptions. *) module Exception : sig (** Used when the exception is a rebind of another exception, when we have [exception Ex = Target_ex].*) - type exception_alias = Odoc_exception.exception_alias = + type exception_alias = Odoc_exception.exception_alias = { ea_name : Name.t ; (** The complete name of the target exception. *) mutable ea_ex : t_exception option ; (** The target exception, if we found it.*) - } - + } + and t_exception = Odoc_exception.t_exception = { ex_name : Name.t ; mutable ex_info : info option ; (** Information found in the optional associated comment. *) ex_args : Types.type_expr list ; (** The types of the parameters. *) ex_alias : exception_alias option ; (** [None] when the exception is not a rebind. *) - mutable ex_loc : location ; + mutable ex_loc : location ; mutable ex_code : string option ; - } + } end (** Representation and manipulation of types.*) module Type : sig (** Description of a variant type constructor. *) - type variant_constructor = Odoc_type.variant_constructor = + type variant_constructor = Odoc_type.variant_constructor = { vc_name : string ; (** Name of the constructor. *) vc_args : Types.type_expr list ; (** Arguments of the constructor. *) mutable vc_text : text option ; (** Optional description in the associated comment. *) - } + } (** Description of a record type field. *) - type record_field = Odoc_type.record_field = + type record_field = Odoc_type.record_field = { rf_name : string ; (** Name of the field. *) rf_mutable : bool ; (** [true] if mutable. *) rf_type : Types.type_expr ; (** Type of the field. *) mutable rf_text : text option ; (** Optional description in the associated comment.*) - } + } (** The various kinds of a type. *) - type type_kind = Odoc_type.type_kind = + type type_kind = Odoc_type.type_kind = Type_abstract (** Type is abstract, for example [type t]. *) | Type_variant of variant_constructor list * bool (** constructors * bool *) @@ -212,17 +212,17 @@ module Type : (** fields * bool *) (** Representation of a type. *) - type t_type = Odoc_type.t_type = + type t_type = Odoc_type.t_type = { ty_name : Name.t ; (** Complete name of the type. *) mutable ty_info : info option ; (** Information found in the optional associated comment. *) - ty_parameters : (Types.type_expr * bool * bool) list ; + ty_parameters : (Types.type_expr * bool * bool) list ; (** type parameters: (type, covariant, contravariant) *) ty_kind : type_kind ; (** Type kind. *) ty_manifest : Types.type_expr option; (** Type manifest. *) mutable ty_loc : location ; mutable ty_code : string option; - } + } end @@ -230,7 +230,7 @@ module Type : module Value : sig (** Representation of a value. *) - type t_value = Odoc_value.t_value = + type t_value = Odoc_value.t_value = { val_name : Name.t ; (** Complete name of the value. *) mutable val_info : info option ; (** Information found in the optional associated comment. *) @@ -239,23 +239,23 @@ module Value : mutable val_parameters : Odoc_parameter.parameter list ; (** The parameters, if any. *) mutable val_code : string option ; (** The code of the value, if we had the only the implementation file. *) mutable val_loc : location ; - } + } (** Representation of a class attribute. *) - type t_attribute = Odoc_value.t_attribute = + type t_attribute = Odoc_value.t_attribute = { att_value : t_value ; (** an attribute has almost all the same information as a value *) att_mutable : bool ; (** [true] if the attribute is mutable. *) } (** Representation of a class method. *) - type t_method = Odoc_value.t_method = + type t_method = Odoc_value.t_method = { met_value : t_value ; (** a method has almost all the same information as a value *) met_private : bool ; (** [true] if the method is private.*) met_virtual : bool ; (** [true] if the method is virtual. *) - } - + } + (** Return [true] if the value is a function, i.e. it has a functional type. *) val is_function : t_value -> bool @@ -274,34 +274,34 @@ module Class : | Class_comment of text (** Used when we can reference a t_class or a t_class_type. *) - type cct = Odoc_class.cct = + type cct = Odoc_class.cct = Cl of t_class | Cltype of t_class_type * Types.type_expr list (** Class type and type parameters. *) - and inherited_class = Odoc_class.inherited_class = + and inherited_class = Odoc_class.inherited_class = { ic_name : Name.t ; (** Complete name of the inherited class. *) mutable ic_class : cct option ; (** The associated t_class or t_class_type. *) ic_text : text option ; (** The inheritance description, if any. *) - } + } - and class_apply = Odoc_class.class_apply = + and class_apply = Odoc_class.class_apply = { capp_name : Name.t ; (** The complete name of the applied class. *) mutable capp_class : t_class option; (** The associated t_class if we found it. *) capp_params : Types.type_expr list; (** The type of expressions the class is applied to. *) capp_params_code : string list ; (** The code of these exprssions. *) - } - - and class_constr = Odoc_class.class_constr = + } + + and class_constr = Odoc_class.class_constr = { cco_name : Name.t ; (** The complete name of the applied class. *) - mutable cco_class : cct option; + mutable cco_class : cct option; (** The associated class or class type if we found it. *) cco_type_parameters : Types.type_expr list; (** The type parameters of the class, if needed. *) - } + } - and class_kind = Odoc_class.class_kind = + and class_kind = Odoc_class.class_kind = Class_structure of inherited_class list * class_element list (** An explicit class structure, used in implementation and interface. *) | Class_apply of class_apply @@ -316,7 +316,7 @@ module Class : (** A class definition with a constraint. *) (** Representation of a class. *) - and t_class = Odoc_class.t_class = + and t_class = Odoc_class.t_class = { cl_name : Name.t ; (** Complete name of the class. *) mutable cl_info : info option ; (** Information found in the optional associated comment. *) @@ -326,21 +326,21 @@ module Class : mutable cl_kind : class_kind ; (** The way the class is defined. *) mutable cl_parameters : Parameter.parameter list ; (** The parameters of the class. *) mutable cl_loc : location ; - } + } - and class_type_alias = Odoc_class.class_type_alias = + and class_type_alias = Odoc_class.class_type_alias = { cta_name : Name.t ; (** Complete name of the target class type. *) mutable cta_class : cct option ; (** The target t_class or t_class_type, if we found it.*) cta_type_parameters : Types.type_expr list ; (** The type parameters. A VOIR : mettre des string ? *) - } + } - and class_type_kind = Odoc_class.class_type_kind = + and class_type_kind = Odoc_class.class_type_kind = Class_signature of inherited_class list * class_element list | Class_type of class_type_alias (** A class type eventually applied to type args. *) - + (** Representation of a class type. *) - and t_class_type = Odoc_class.t_class_type = + and t_class_type = Odoc_class.t_class_type = { clt_name : Name.t ; (** Complete name of the type. *) mutable clt_info : info option ; (** Information found in the optional associated comment. *) @@ -349,7 +349,7 @@ module Class : clt_virtual : bool ; (** [true] if the class type is virtual *) mutable clt_kind : class_type_kind ; (** The way the class type is defined. *) mutable clt_loc : location ; - } + } (** {3 Functions} *) @@ -389,7 +389,7 @@ module Module : sig (** {3 Types} *) (** To keep the order of elements in a module. *) - type module_element = Odoc_module.module_element = + type module_element = Odoc_module.module_element = Element_module of t_module | Element_module_type of t_module_type | Element_included_module of included_module @@ -405,36 +405,36 @@ module Module : | Mod of t_module | Modtype of t_module_type - and included_module = Odoc_module.included_module = + and included_module = Odoc_module.included_module = { im_name : Name.t ; (** Complete name of the included module. *) mutable im_module : mmt option ; (** The included module or module type, if we found it. *) mutable im_info : Odoc_types.info option ; (** comment associated to the includ directive *) - } - - and module_alias = Odoc_module.module_alias = + } + + and module_alias = Odoc_module.module_alias = { ma_name : Name.t ; (** Complete name of the target module. *) mutable ma_module : mmt option ; (** The real module or module type if we could associate it. *) - } + } and module_parameter = Odoc_module.module_parameter = { mp_name : string ; (** the name *) mp_type : Types.module_type ; (** the type *) mp_type_code : string ; (** the original code *) mp_kind : module_type_kind ; (** the way the parameter was built *) - } + } (** Different kinds of a module. *) - and module_kind = Odoc_module.module_kind = + and module_kind = Odoc_module.module_kind = | Module_struct of module_element list (** A complete module structure. *) | Module_alias of module_alias (** Complete name and corresponding module if we found it *) - | Module_functor of module_parameter * module_kind + | Module_functor of module_parameter * module_kind (** A functor, with its parameter and the rest of its definition *) | Module_apply of module_kind * module_kind (** A module defined by application of a functor. *) | Module_with of module_type_kind * string - (** A module whose type is a with ... constraint. + (** A module whose type is a with ... constraint. Should appear in interface files only. *) | Module_constraint of module_kind * module_type_kind (** A module constraint by a module type. *) @@ -452,16 +452,16 @@ module Module : mutable m_top_deps : Name.t list ; (** The toplevels module names this module depends on. *) mutable m_code : string option ; (** The whole code of the module *) mutable m_code_intf : string option ; (** The whole code of the interface of the module *) - } + } and module_type_alias = Odoc_module.module_type_alias = { mta_name : Name.t ; (** Complete name of the target module type. *) mutable mta_module : t_module_type option ; (** The real module type if we could associate it. *) - } + } (** Different kinds of module type. *) - and module_type_kind = Odoc_module.module_type_kind = + and module_type_kind = Odoc_module.module_type_kind = | Module_type_struct of module_element list (** A complete module signature. *) | Module_type_functor of module_parameter * module_type_kind (** A functor, with its parameter and the rest of its definition *) @@ -478,12 +478,12 @@ module Module : mt_type : Types.module_type option ; (** [None] means that the module type is abstract. *) mt_is_interface : bool ; (** [true] for modules read from interface files. *) mt_file : string ; (** The file the module type is defined in. *) - mutable mt_kind : module_type_kind option ; + mutable mt_kind : module_type_kind option ; (** The way the module is defined. [None] means that module type is abstract. It is always [None] when the module type was extracted from the implementation file. That means module types are only analysed in interface files. *) mutable mt_loc : location ; - } + } (** {3 Functions for modules} *) @@ -582,10 +582,10 @@ module Module : (** {3 Getting strings from values} *) - + (** This function is used to reset the names of type variables. It must be called when printing the whole type of a function, - but not when printing the type of its parameters. Same for + but not when printing the type of its parameters. Same for classes (call it) and methods and attributes (don't call it).*) val reset_type_names : unit -> unit @@ -611,12 +611,12 @@ val string_of_type_list : ?par: bool -> string -> Types.type_expr list -> string for the given type. *) val string_of_type_param_list : Type.t_type -> string -(** This function returns a string to represent the given list of +(** This function returns a string to represent the given list of type parameters of a class or class type, with a given separator. *) val string_of_class_type_param_list : Types.type_expr list -> string -(** This function returns a string representing a [Types.module_type]. +(** This function returns a string representing a [Types.module_type]. @param complete indicates if we must print complete signatures or just [sig end]. Default if [false]. @param code if [complete = false] and the type contains something else @@ -624,7 +624,7 @@ val string_of_class_type_param_list : Types.type_expr list -> string *) val string_of_module_type : ?code: string -> ?complete: bool -> Types.module_type -> string -(** This function returns a string representing a [Types.class_type]. +(** This function returns a string representing a [Types.class_type]. @param complete indicates if we must print complete signatures or just [object end]. Default if [false]. *) @@ -673,12 +673,12 @@ val text_no_title_no_list : text -> text the text [sep]. *) val text_concat : Odoc_types.text -> Odoc_types.text list -> Odoc_types.text -(** Return the list of titles in a [text]. +(** Return the list of titles in a [text]. A title is a title level, an optional label and a text.*) val get_titles_in_text : text -> (int * string option * text) list (** Take a sorted list of elements, a function to get the name - of an element and return the list of list of elements, + of an element and return the list of list of elements, where each list group elements beginning by the same letter. Since the original list is sorted, elements whose name does not begin with a letter should be in the first returned list.*) @@ -696,16 +696,16 @@ val is_optional : string -> bool i.e. removes the beginning '?' if present.*) val label_name : string -> string -(** Return the given name where the module name or - part of it was removed, according to the list of modules +(** Return the given name where the module name or + part of it was removed, according to the list of modules which must be hidden (cf {!Odoc_args.hidden_modules})*) val use_hidden_modules : Name.t -> Name.t - + (** Print the given string if the verbose mode is activated. *) val verbose : string -> unit (** Print a warning message to stderr. - If warnings must be treated as errors, then the + If warnings must be treated as errors, then the error counter is incremented. *) val warning : string -> unit @@ -718,23 +718,23 @@ val errors : int ref (** Apply a function to an optional value. *) val apply_opt : ('a -> 'b) -> 'a option -> 'b option -(** Apply a function to a first value if it is +(** Apply a function to a first value if it is not different from a second value. If the two values are different, return the second one.*) val apply_if_equal : ('a -> 'a) -> 'a -> 'a -> 'a (** [text_of_string s] returns the text structure from the - given string. + given string. @raise Text_syntax if a syntax error is encountered. *) val text_of_string : string -> text (** [text_string_of_text text] returns the string representing the given [text]. This string can then be parsed again - by {!Odoc_info.text_of_string}.*) + by {!Odoc_info.text_of_string}.*) val text_string_of_text : text -> string (** [info_of_string s] parses the given string - like a regular ocamldoc comment and return an + like a regular ocamldoc comment and return an {!Odoc_info.info} structure. @return an empty structure if there was a syntax error. TODO: change this *) @@ -742,11 +742,11 @@ val info_of_string : string -> info (** [info_string_of_info info] returns the string representing the given [info]. This string can then be parsed again - by {!Odoc_info.info_of_string}.*) + by {!Odoc_info.info_of_string}.*) val info_string_of_info : info -> string (** [info_of_comment_file file] parses the given file - and return an {!Odoc_info.info} structure. The content of the + and return an {!Odoc_info.info} structure. The content of the file must have the same syntax as the content of a special comment. @raise Failure is the file could not be opened or there is a syntax error. @@ -819,14 +819,14 @@ module Scan : method scan_attribute : Value.t_attribute -> unit method scan_method : Value.t_method -> unit method scan_included_module : Module.included_module -> unit - - (** Scan of a class. *) + + (** Scan of a class. *) (** Scan of a comment inside a class. *) method scan_class_comment : text -> unit (** Override this method to perform controls on the class comment - and params. This method is called before scanning the class elements. + and params. This method is called before scanning the class elements. @return true if the class elements must be scanned.*) method scan_class_pre : Class.t_class -> bool @@ -843,7 +843,7 @@ module Scan : method scan_class_type_comment : text -> unit (** Override this method to perform controls on the class type comment - and form. This method is called before scanning the class type elements. + and form. This method is called before scanning the class type elements. @return true if the class type elements must be scanned.*) method scan_class_type_pre : Class.t_class_type -> bool @@ -860,7 +860,7 @@ module Scan : method scan_module_comment : text -> unit (** Override this method to perform controls on the module comment - and form. This method is called before scanning the module elements. + and form. This method is called before scanning the module elements. @return true if the module elements must be scanned.*) method scan_module_pre : Module.t_module -> bool @@ -877,7 +877,7 @@ module Scan : method scan_module_type_comment : text -> unit (** Override this method to perform controls on the module type comment - and form. This method is called before scanning the module type elements. + and form. This method is called before scanning the module type elements. @return true if the module type elements must be scanned. *) method scan_module_type_pre : Module.t_module_type -> bool @@ -929,13 +929,13 @@ module Args : (** Verbose mode or not. *) val verbose : bool ref - + (** The optional title to use in the generated documentation. *) val title : string option ref (** To keep the code while merging, when we have both .ml and .mli files for a module. *) val keep_code : bool ref - + (** The optional file whose content can be used as intro text. *) val intro_file : string option ref @@ -948,7 +948,7 @@ module Args : (** The directory where files have to be generated. *) val target_dir : string ref - + (** An optional file to use where a CSS style is defined (for HTML). *) val css_style : string option ref @@ -960,10 +960,10 @@ module Args : (** The flag which indicates if we must generate a header (for LaTeX). *) val with_header : bool ref - + (** The flag which indicates if we must generate a trailer (for LaTeX). *) val with_trailer : bool ref - + (** The flag to indicate if we must generate one file per module (for LaTeX). *) val separate_files : bool ref @@ -1027,15 +1027,18 @@ module Args : (** The suffix for man pages. *) val man_suffix : string ref + (** The section for man pages. *) + val man_section : string ref + (** The flag to generate all man pages or only for modules and classes.*) val man_mini : bool ref (** The files to be analysed. *) val files : source_file list ref - + (** To set the documentation generator. *) val set_doc_generator : doc_generator option -> unit - + (** Add an option specification. *) val add_option : string * Arg.spec * string -> unit end @@ -1053,10 +1056,10 @@ val analyse_files : Args.source_file list -> Module.t_module list -(** Dump of a list of modules into a file. +(** Dump of a list of modules into a file. @raise Failure if an error occurs.*) val dump_modules : string -> Odoc_module.t_module list -> unit -(** Load of a list of modules from a file. +(** Load of a list of modules from a file. @raise Failure if an error occurs.*) val load_modules : string -> Odoc_module.t_module list diff --git a/ocamldoc/odoc_man.ml b/ocamldoc/odoc_man.ml index 6a0fae1327..9254115845 100644 --- a/ocamldoc/odoc_man.ml +++ b/ocamldoc/odoc_man.ml @@ -654,10 +654,9 @@ class man = try let chanout = self#open_out file in let b = new_buf () in - bs b ".TH \""; - bs b Odoc_messages.clas; - bs b ("\" "^cl.cl_name^" "); - bs b ("\""^(Odoc_misc.string_of_date ~hour: false date)^"\" "); + bs b (".TH \""^cl.cl_name^"\" "); + bs b !Odoc_args.man_section ; + bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^"\" "); bs b "OCamldoc "; bs b ("\""^(match !Args.title with Some t -> t | None -> "")^"\"\n"); @@ -714,9 +713,9 @@ class man = try let chanout = self#open_out file in let b = new_buf () in - bs b (".TH \""^Odoc_messages.class_type^"\" "); - bs b (ct.clt_name^" "); - bs b ("\""^(Odoc_misc.string_of_date ~hour: false date)^"\" "); + bs b (".TH \""^ct.clt_name^"\" "); + bs b !Odoc_args.man_section ; + bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^"\" "); bs b "OCamldoc "; bs b ("\""^(match !Args.title with Some t -> t | None -> "")^"\"\n"); @@ -771,9 +770,9 @@ class man = try let chanout = self#open_out file in let b = new_buf () in - bs b (".TH \""^Odoc_messages.module_type^"\" "); - bs b (mt.mt_name^" "); - bs b ("\""^(Odoc_misc.string_of_date ~hour: false date)^"\" "); + bs b (".TH \""^mt.mt_name^"\" "); + bs b !Odoc_args.man_section ; + bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^"\" "); bs b "OCamldoc "; bs b ("\""^(match !Args.title with Some t -> t | None -> "")^"\"\n"); @@ -849,11 +848,9 @@ class man = try let chanout = self#open_out file in let b = new_buf () in - bs b ".TH \""; - bs b Odoc_messages.modul; - bs b "\" "; - bs b (m.m_name^" "); - bs b ("\""^(Odoc_misc.string_of_date ~hour: false date)^"\" "); + bs b (".TH \""^m.m_name^"\" "); + bs b !Odoc_args.man_section ; + bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^"\" "); bs b "OCamldoc "; bs b ("\""^(match !Args.title with Some t -> t | None -> "")^"\"\n"); @@ -978,9 +975,9 @@ class man = try let chanout = self#open_out file in let b = new_buf () in - bs b (".TH \""^name^"\" "); - bs b "man "; - bs b ("\""^(Odoc_misc.string_of_date ~hour: false date)^"\" "); + bs b (".TH \""^name^"\" "); + bs b !Odoc_args.man_section ; + bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^"\" "); bs b "OCamldoc "; bs b ("\""^(match !Args.title with Some t -> t | None -> "")^"\"\n"); bs b ".SH NAME\n"; diff --git a/ocamldoc/odoc_messages.ml b/ocamldoc/odoc_messages.ml index f7e5be1f0b..a59cf76729 100644 --- a/ocamldoc/odoc_messages.ml +++ b/ocamldoc/odoc_messages.ml @@ -60,37 +60,41 @@ let generate_dot = "\t\tGenerate dot code of top modules dependencies" let option_not_in_native_code op = "Option "^op^" not available in native code version." let default_out_file = "ocamldoc.out" -let out_file = +let out_file = "<file>\tSet the ouput file name, used by texi, latex and dot generators\n"^ "\t\t(default is "^default_out_file^")" -let dot_include_all = +let dot_include_all = "\n\t\tInclude all modules in the dot output, not only the\n"^ "\t\tmodules given on the command line" let dot_types = "\tGenerate dependency graph for types instead of modules" -let default_dot_colors = +let default_dot_colors = [ [ "darkturquoise" ; "darkgoldenrod2" ; "cyan" ; "green" ; ] ; [ "magenta" ; "yellow" ; "burlywood1" ; "aquamarine" ; "floralwhite" ; "lightpink" ] ; [ "lightblue" ; "mediumturquoise" ; "salmon" ; "slategray3"] ; - ] + ] -let dot_colors = +let dot_colors = "<c1,c2,...,cn>\n\t\tUse colors c1,c1,...,cn in the dot output\n"^ "\t\t(default list is "^ (String.concat ",\n\t\t" (List.map (String.concat ", ") default_dot_colors))^")" -let dot_reduce = +let dot_reduce = "\tPerform a transitive reduction on the selected dependency graph\n"^ "\t\tbefore the dot output" let man_mini = "\tGenerate man pages only for modules, module types, classes\n"^ "\t\tand class types "^man_only -let default_man_suffix = "o" +let default_man_section = "3" +let man_section = "<section>\n\t\tUse <section> in man page files "^ + "(default is "^default_man_section^") "^man_only^"\n" + +let default_man_suffix = default_man_section^"o" let man_suffix = "<suffix>\n\t\tUse <suffix> for man page files "^ "(default is "^default_man_suffix^") "^man_only^"\n" let option_title = "<title>\tUse <title> as title for the generated documentation" -let option_intro = +let option_intro = "<file>\tUse content of <file> as ocamldoc text to use as introduction\n"^ "\t\t"^(html_latex_texi_only) let with_parameter_list = "\tDisplay the complete list of parameters for functions and\n"^ @@ -99,7 +103,7 @@ let hide_modules = "<M1,M2.M3,...>\n\t\tHide the given complete module names in let no_header = "\tSuppress header in generated documentation\n\t\t"^latex_texi_only let no_trailer = "\tSuppress trailer in generated documentation\n\t\t"^latex_texi_only let separate_files = "\tGenerate one file per toplevel module "^latex_only -let latex_title ref_titles = +let latex_title ref_titles = "n,style\n\t\tAssociate {n } to the given sectionning style\n"^ "\t\t(e.g. 'section') in the latex output "^latex_only^"\n"^ "\t\tDefault sectionning is:\n\t\t"^ @@ -107,32 +111,32 @@ let latex_title ref_titles = (List.map (fun (n,t) -> Printf.sprintf " %d -> %s" n t) !ref_titles)) let default_latex_value_prefix = "val:" -let latex_value_prefix = +let latex_value_prefix = "<string>\n\t\tUse <string> as prefix for the LaTeX labels of values.\n"^ "\t\t(default is \""^default_latex_value_prefix^"\")" let default_latex_type_prefix = "type:" -let latex_type_prefix = +let latex_type_prefix = "<string>\n\t\tUse <string> as prefix for the LaTeX labels of types.\n"^ "\t\t(default is \""^default_latex_type_prefix^"\")" let default_latex_exception_prefix = "exception:" -let latex_exception_prefix = +let latex_exception_prefix = "<string>\n\t\tUse <string> as prefix for the LaTeX labels of exceptions.\n"^ "\t\t(default is \""^default_latex_exception_prefix^"\")" let default_latex_module_prefix = "module:" -let latex_module_prefix = +let latex_module_prefix = "<string>\n\t\tUse <string> as prefix for the LaTeX labels of modules.\n"^ "\t\t(default is \""^default_latex_module_prefix^"\")" let default_latex_module_type_prefix = "moduletype:" -let latex_module_type_prefix = +let latex_module_type_prefix = "<string>\n\t\tUse <string> as prefix for the LaTeX labels of module types.\n"^ "\t\t(default is \""^default_latex_module_type_prefix^"\")" let default_latex_class_prefix = "class:" -let latex_class_prefix = +let latex_class_prefix = "<string>\n\t\tUse <string> as prefix for the LaTeX labels of classes.\n"^ "\t\t(default is \""^default_latex_class_prefix^"\")" @@ -142,12 +146,12 @@ let latex_class_type_prefix = "\t\t(default is \""^default_latex_class_type_prefix^"\")" let default_latex_attribute_prefix = "val:" -let latex_attribute_prefix = +let latex_attribute_prefix = "<string>\n\t\tUse <string> as prefix for the LaTeX labels of attributes.\n"^ "\t\t(default is \""^default_latex_attribute_prefix^"\")" let default_latex_method_prefix = "method:" -let latex_method_prefix = +let latex_method_prefix = "<string>\n\t\tUse <string> as prefix for the LaTeX labels of methods.\n"^ "\t\t(default is \""^default_latex_method_prefix^"\")" @@ -176,12 +180,12 @@ let info_section = "Specify section of Info directory "^texi_only let info_entry = "\tSpecify Info directory entry "^texi_only let options_can_be = "<options> can be one or more of the following characters:" -let string_of_options_list l = +let string_of_options_list l = List.fold_left (fun acc -> fun (c, m) -> acc^"\n\t\t"^(String.make 1 c)^" "^m) "" l -let merge_options = +let merge_options = "<options>\tspecify merge options between .mli and .ml\n\t\t"^ options_can_be^ (string_of_options_list @@ -202,11 +206,11 @@ let merge_options = (** Error and warning messages *) let warning = "Warning" -let pwarning s = +let pwarning s = prerr_endline (warning^": "^s); if !Odoc_global.warn_error then incr Odoc_global.errors -let bad_magic_number = +let bad_magic_number = "Bad magic number for this ocamldoc dump!\n"^ "This dump was not created by this version of OCamldoc." @@ -346,4 +350,3 @@ let index_of_module_types = index_of^" module types" let previous = "Previous" let next = "Next" let up = "Up" - diff --git a/ocamldoc/odoc_misc.ml b/ocamldoc/odoc_misc.ml index 28f06ee1c8..d3d970490b 100644 --- a/ocamldoc/odoc_misc.ml +++ b/ocamldoc/odoc_misc.ml @@ -79,13 +79,13 @@ let get_fields type_expr = fields let rec string_of_text t = - let rec iter t_ele = + let rec iter t_ele = match t_ele with | Odoc_types.Raw s | Odoc_types.Code s | Odoc_types.CodePre s | Odoc_types.Verbatim s -> s - | Odoc_types.Bold t + | Odoc_types.Bold t | Odoc_types.Italic t | Odoc_types.Center t | Odoc_types.Left t @@ -121,7 +121,7 @@ let rec string_of_text t = (List.map (fun s -> Odoc_types.Code s) l) ) | Odoc_types.Index_list -> - "" + "" in String.concat "" (List.map iter t) @@ -158,7 +158,7 @@ let string_of_raised_exceptions l = )^"\n" let string_of_see (see_ref, t) = - let t_ref = + let t_ref = match see_ref with Odoc_types.See_url s -> [ Odoc_types.Link (s, t) ] | Odoc_types.See_file s -> (Odoc_types.Code s) :: (Odoc_types.Raw " ") :: t @@ -190,7 +190,7 @@ let string_of_info i = None -> "" | Some d -> Odoc_messages.deprecated^"! "^(string_of_text d)^"\n")^ (match i.M.i_desc with - None -> "" + None -> "" | Some d when d = [Odoc_types.Raw ""] -> "" | Some d -> (string_of_text d)^"\n" )^ @@ -205,14 +205,14 @@ let apply_opt f v_opt = None -> None | Some v -> Some (f v) -let string_of_date ?(hour=true) d = +let string_of_date ?(hour=true) d = let add_0 s = if String.length s < 2 then "0"^s else s in let t = Unix.localtime d in (string_of_int (t.Unix.tm_year + 1900))^"-"^ (add_0 (string_of_int (t.Unix.tm_mon + 1)))^"-"^ (add_0 (string_of_int t.Unix.tm_mday))^ ( - if hour then + if hour then " "^ (add_0 (string_of_int t.Unix.tm_hour))^":"^ (add_0 (string_of_int t.Unix.tm_min)) @@ -229,14 +229,14 @@ let rec text_list_concat sep l = t @ (sep :: (text_list_concat sep q)) let rec text_no_title_no_list t = - let rec iter t_ele = + let rec iter t_ele = match t_ele with | Odoc_types.Title (_,_,t) -> text_no_title_no_list t | Odoc_types.List l - | Odoc_types.Enum l -> + | Odoc_types.Enum l -> (Odoc_types.Raw " ") :: (text_list_concat - (Odoc_types.Raw ", ") + (Odoc_types.Raw ", ") (List.map text_no_title_no_list l)) | Odoc_types.Raw _ | Odoc_types.Code _ @@ -256,7 +256,7 @@ let rec text_no_title_no_list t = | Odoc_types.Superscript t -> [Odoc_types.Superscript (text_no_title_no_list t)] | Odoc_types.Subscript t -> [Odoc_types.Subscript (text_no_title_no_list t)] | Odoc_types.Module_list l -> - list_concat (Odoc_types.Raw ", ") + list_concat (Odoc_types.Raw ", ") (List.map (fun s -> Odoc_types.Ref (s, Some Odoc_types.RK_module)) l @@ -271,7 +271,7 @@ let get_titles_in_text t = match ele with | Odoc_types.Title (n,lopt,t) -> l := (n,lopt,t) :: !l | Odoc_types.List l - | Odoc_types.Enum l -> List.iter iter_text l + | Odoc_types.Enum l -> List.iter iter_text l | Odoc_types.Raw _ | Odoc_types.Code _ | Odoc_types.CodePre _ @@ -287,17 +287,17 @@ let get_titles_in_text t = | Odoc_types.Emphasize t -> iter_text t | Odoc_types.Latex s -> () | Odoc_types.Link (_, t) - | Odoc_types.Superscript t + | Odoc_types.Superscript t | Odoc_types.Subscript t -> iter_text t | Odoc_types.Module_list _ -> () | Odoc_types.Index_list -> () - and iter_text te = + and iter_text te = List.iter iter_ele te in iter_text t; List.rev !l -let text_concat (sep : Odoc_types.text) l = +let text_concat (sep : Odoc_types.text) l = let rec iter = function [] -> [] | [last] -> last @@ -329,8 +329,8 @@ let rec first_sentence_text t = [] -> (false, [], []) | ele :: q -> let (stop, ele2, ele3_opt) = first_sentence_text_ele ele in - if stop then - (stop, [ele2], + if stop then + (stop, [ele2], match ele3_opt with None -> q | Some e -> e :: q) else let (stop2, q2, rest) = first_sentence_text q in @@ -339,11 +339,11 @@ let rec first_sentence_text t = and first_sentence_text_ele text_ele = match text_ele with - | Odoc_types.Raw s -> + | Odoc_types.Raw s -> let b, s2, s_after = get_before_dot s in (b, Odoc_types.Raw s2, Some (Odoc_types.Raw s_after)) - | Odoc_types.Code _ - | Odoc_types.CodePre _ + | Odoc_types.Code _ + | Odoc_types.CodePre _ | Odoc_types.Verbatim _ -> (false, text_ele, None) | Odoc_types.Bold t -> let (b, t2, t3) = first_sentence_text t in @@ -363,28 +363,28 @@ and first_sentence_text_ele text_ele = | Odoc_types.Emphasize t -> let (b, t2, t3) = first_sentence_text t in (b, Odoc_types.Emphasize t2, Some (Odoc_types.Emphasize t3)) - | Odoc_types.Block t -> + | Odoc_types.Block t -> let (b, t2, t3) = first_sentence_text t in (b, Odoc_types.Block t2, Some (Odoc_types.Block t3)) | Odoc_types.Title (n, l_opt, t) -> let (b, t2, t3) = first_sentence_text t in - (b, - Odoc_types.Title (n, l_opt, t2), + (b, + Odoc_types.Title (n, l_opt, t2), Some (Odoc_types.Title (n, l_opt, t3))) | Odoc_types.Newline -> (true, Odoc_types.Raw "", Some Odoc_types.Newline) | Odoc_types.List _ | Odoc_types.Enum _ | Odoc_types.Latex _ - | Odoc_types.Link _ - | Odoc_types.Ref _ - | Odoc_types.Superscript _ - | Odoc_types.Subscript _ - | Odoc_types.Module_list _ + | Odoc_types.Link _ + | Odoc_types.Ref _ + | Odoc_types.Superscript _ + | Odoc_types.Subscript _ + | Odoc_types.Module_list _ | Odoc_types.Index_list -> (false, text_ele, None) -let first_sentence_of_text t = - let (_,t2,_) = first_sentence_text t in +let first_sentence_of_text t = + let (_,t2,_) = first_sentence_text t in t2 let first_sentence_and_rest_of_text t = @@ -400,6 +400,25 @@ let remove_ending_newline s = '\n' -> String.sub s 0 (len-1) | _ -> s +let search_string_backward ~pat = + let lenp = String.length pat in + let rec iter s = + let len = String.length s in + match compare len lenp with + -1 -> raise Not_found + | 0 -> if pat = s then 0 else raise Not_found + | _ -> + let pos = len - lenp in + let s2 = String.sub s pos lenp in + if s2 = pat then + pos + else + iter (String.sub s 0 pos) + in + fun ~s -> iter s + + + (*********************************************************) let create_index_lists elements string_of_ele = @@ -436,11 +455,11 @@ let remove_option typ = | Types.Tvar | Types.Tunivar | Types.Tpoly _ - | Types.Tarrow _ - | Types.Ttuple _ + | Types.Tarrow _ + | Types.Ttuple _ | Types.Tobject _ | Types.Tfield _ - | Types.Tnil + | Types.Tnil | Types.Tvariant _ -> t | Types.Tlink t2 | Types.Tsubst t2 -> iter t2.Types.desc diff --git a/ocamldoc/odoc_misc.mli b/ocamldoc/odoc_misc.mli index 2acedb2cbb..d3037519b9 100644 --- a/ocamldoc/odoc_misc.mli +++ b/ocamldoc/odoc_misc.mli @@ -69,7 +69,7 @@ val first_sentence_of_text : Odoc_types.text -> Odoc_types.text and the remaining text after. Don't stop in the middle of [Code], [Verbatim], [List], [Lnum], [Latex], [Link], or [Ref]. *) -val first_sentence_and_rest_of_text : +val first_sentence_and_rest_of_text : Odoc_types.text -> Odoc_types.text * Odoc_types.text (** Return the given [text] without any title or list. *) @@ -79,12 +79,12 @@ val text_no_title_no_list : Odoc_types.text -> Odoc_types.text the text [sep]. *) val text_concat : Odoc_types.text -> Odoc_types.text list -> Odoc_types.text -(** Return the list of titles in a [text]. +(** Return the list of titles in a [text]. A title is a title level, an optional label and a text.*) val get_titles_in_text : Odoc_types.text -> (int * string option * Odoc_types.text) list (** Take a sorted list of elements, a function to get the name - of an element and return the list of list of elements, + of an element and return the list of list of elements, where each list group elements beginning by the same letter. Since the original list is sorted, elements whose name does not begin with a letter should be in the first returned list.*) @@ -93,6 +93,10 @@ val create_index_lists : 'a list -> ('a -> string) -> 'a list list (** [remove_ending_newline s] returns [s] without the optional ending newline. *) val remove_ending_newline : string -> string +(** [search_string_backward pat s] searches backward string [pat] in string [s]. + Return position in string [s] where [pat] appears, orelse raise [Not_found]. *) +val search_string_backward : pat: string -> s: string -> int + (** Take a type and remove the option top constructor. This is useful when printing labels, we we then remove the top option contructor for optional labels.*) diff --git a/ocamldoc/odoc_sig.ml b/ocamldoc/odoc_sig.ml index 979579bbfb..f316e50bff 100644 --- a/ocamldoc/odoc_sig.ml +++ b/ocamldoc/odoc_sig.ml @@ -1322,5 +1322,3 @@ module Analyser = } end - -(* eof $Id$ *) diff --git a/ocamldoc/odoc_str.ml b/ocamldoc/odoc_str.ml index c36d4b9571..fb1d2b31d4 100644 --- a/ocamldoc/odoc_str.ml +++ b/ocamldoc/odoc_str.ml @@ -25,6 +25,14 @@ let string_of_variance t (co,cn) = | _ -> "" else "" +let rec is_arrow_type t = + match t.Types.desc with + Types.Tarrow _ -> true + | Types.Tlink t2 | Types.Tsubst t2 -> is_arrow_type t2 + | Types.Ttuple _ + | Types.Tconstr _ + | Types.Tvar | Types.Tunivar | Types.Tobject _ | Types.Tpoly _ + | Types.Tfield _ | Types.Tnil | Types.Tvariant _ -> false let raw_string_of_type_list sep type_list = let buf = Buffer.create 256 in @@ -41,7 +49,7 @@ let raw_string_of_type_list sep type_list = let print_one_type variance t = Printtyp.mark_loops t; if need_parent t then - ( + ( Format.fprintf fmt "(%s" variance; Printtyp.type_scheme_max ~b_reset_names: false fmt t; Format.fprintf fmt ")" @@ -59,8 +67,8 @@ let raw_string_of_type_list sep type_list = Format.fprintf fmt "@[<hov 2>"; print_one_type variance ty; List.iter - (fun (variance, t) -> - Format.fprintf fmt "@,%s" sep; + (fun (variance, t) -> + Format.fprintf fmt "@,%s" sep; print_one_type variance t ) tyl; @@ -84,7 +92,7 @@ let string_of_type_list ?par sep type_list = (if par then ")" else "") let string_of_type_param_list t = - let par = + let par = match t.Odoc_type.ty_parameters with [] | [_] -> false | _ -> true @@ -92,7 +100,7 @@ let string_of_type_param_list t = Printf.sprintf "%s%s%s" (if par then "(" else "") (raw_string_of_type_list ", " - (List.map + (List.map (fun (typ, co, cn) -> (string_of_variance t (co, cn), typ)) t.Odoc_type.ty_parameters ) @@ -100,7 +108,7 @@ let string_of_type_param_list t = (if par then ")" else "") let string_of_class_type_param_list l = - let par = + let par = match l with [] | [_] -> false | _ -> true @@ -108,7 +116,7 @@ let string_of_class_type_param_list l = Printf.sprintf "%s%s%s" (if par then "[" else "") (raw_string_of_type_list ", " - (List.map + (List.map (fun typ -> ("", typ)) l ) @@ -119,21 +127,24 @@ let string_of_class_params c = let b = Buffer.create 256 in let rec iter = function Types.Tcty_fun (label, t, ctype) -> - Printf.bprintf b "%s%s -> " + let parent = is_arrow_type t in + Printf.bprintf b "%s%s%s%s -> " ( match label with "" -> "" | s -> s^":" ) + (if parent then "(" else "") (Odoc_print.string_of_type_expr (if Odoc_misc.is_optional label then Odoc_misc.remove_option t else t ) - ); + ) + (if parent then ")" else ""); iter ctype - | Types.Tcty_signature _ + | Types.Tcty_signature _ | Types.Tcty_constr _ -> () in iter c.Odoc_class.cl_type; @@ -143,8 +154,8 @@ let string_of_type t = let module M = Odoc_type in "type "^ (String.concat "" - (List.map - (fun (p, co, cn) -> + (List.map + (fun (p, co, cn) -> (string_of_variance t (co, cn))^ (Odoc_print.string_of_type_expr p)^" " ) @@ -157,18 +168,18 @@ let string_of_type t = | Some typ -> "= "^(Odoc_print.string_of_type_expr typ)^" " )^ (match t.M.ty_kind with - M.Type_abstract -> + M.Type_abstract -> "" | M.Type_variant (l, priv) -> "="^(if priv then " private" else "")^"\n"^ (String.concat "" - (List.map + (List.map (fun cons -> " | "^cons.M.vc_name^ (match cons.M.vc_args with - [] -> "" - | l -> - " of "^(String.concat " * " + [] -> "" + | l -> + " of "^(String.concat " * " (List.map (fun t -> "("^(Odoc_print.string_of_type_expr t)^")") l)) )^ (match cons.M.vc_text with @@ -184,7 +195,7 @@ let string_of_type t = | M.Type_record (l, priv) -> "= "^(if priv then "private " else "")^"{\n"^ (String.concat "" - (List.map + (List.map (fun record -> " "^(if record.M.rf_mutable then "mutable " else "")^ record.M.rf_name^" : "^(Odoc_print.string_of_type_expr record.M.rf_type)^";"^ @@ -210,7 +221,7 @@ let string_of_exception e = (match e.M.ex_args with [] -> "" | _ ->" : "^ - (String.concat " -> " + (String.concat " -> " (List.map (fun t -> "("^(Odoc_print.string_of_type_expr t)^")") e.M.ex_args) ) )^ |