2002-04-05 03:25:22 -08:00
|
|
|
|
(***********************************************************************)
|
|
|
|
|
(* OCamldoc *)
|
|
|
|
|
(* *)
|
2004-04-09 07:52:23 -07:00
|
|
|
|
(* Olivier Andrieu, base sur du code de Maxence Guesdon *)
|
2002-04-05 03:25:22 -08:00
|
|
|
|
(* *)
|
|
|
|
|
(* Copyright 2001 Institut National de Recherche en Informatique et *)
|
|
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
|
|
|
|
|
(** Generation of Texinfo documentation. *)
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
open Odoc_info
|
2002-04-05 03:25:22 -08:00
|
|
|
|
open Parameter
|
|
|
|
|
open Value
|
|
|
|
|
open Type
|
|
|
|
|
open Exception
|
2006-01-04 08:55:50 -08:00
|
|
|
|
open Class
|
2002-04-05 03:25:22 -08:00
|
|
|
|
open Module
|
|
|
|
|
|
|
|
|
|
(** {2 Some small helper functions} *)
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let puts_nl chan s =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
output_string chan s ;
|
|
|
|
|
output_char chan '\n'
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let puts chan s =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
output_string chan s
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let nl chan =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
output_char chan '\n'
|
|
|
|
|
|
|
|
|
|
let is = function
|
|
|
|
|
| None -> false
|
|
|
|
|
| Some _ -> true
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let pad_to n s =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
let len = String.length s in
|
|
|
|
|
if len < n
|
|
|
|
|
then
|
|
|
|
|
let s' = String.make n ' ' in
|
|
|
|
|
String.blit s 0 s' 0 len ; s'
|
|
|
|
|
else s
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let indent nb_sp s =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
let c = ref 0 in
|
|
|
|
|
let len = pred (String.length s) in
|
|
|
|
|
for i = 0 to len do if s.[i] = '\n' then incr c done ;
|
|
|
|
|
let s' = String.make (succ len + (succ !c) * nb_sp ) ' ' in
|
|
|
|
|
c := nb_sp ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
for i = 0 to len do
|
|
|
|
|
s'.[!c] <- s.[i] ;
|
2002-04-05 03:25:22 -08:00
|
|
|
|
if s.[i] = '\n' then c := !c + nb_sp ;
|
|
|
|
|
incr c
|
|
|
|
|
done ;
|
|
|
|
|
s'
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
type subparts = [
|
2002-04-05 03:25:22 -08:00
|
|
|
|
| `Module of Odoc_info.Module.t_module
|
|
|
|
|
| `Module_type of Odoc_info.Module.t_module_type
|
|
|
|
|
| `Class of Odoc_info.Class.t_class
|
|
|
|
|
| `Class_type of Odoc_info.Class.t_class_type
|
2002-11-07 00:36:00 -08:00
|
|
|
|
]
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
type menu_data = [
|
|
|
|
|
| subparts
|
2002-04-05 03:25:22 -08:00
|
|
|
|
| `Blank
|
|
|
|
|
| `Comment of string
|
|
|
|
|
| `Texi of string
|
|
|
|
|
| `Index of string
|
|
|
|
|
] list
|
|
|
|
|
|
|
|
|
|
let nothing = Verbatim ""
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let module_subparts =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
let rec iter acc = function
|
|
|
|
|
| [] -> List.rev acc
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(* skip aliases *)
|
|
|
|
|
| Element_module { m_kind = Module_alias _ } :: n ->
|
2002-07-23 07:12:03 -07:00
|
|
|
|
iter acc n
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| Element_module_type { mt_kind = Some (Module_type_alias _) } :: n ->
|
2002-07-23 07:12:03 -07:00
|
|
|
|
iter acc n
|
2002-04-05 03:25:22 -08:00
|
|
|
|
(* keep modules, module types, classes and class types *)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| Element_module m :: n ->
|
|
|
|
|
iter (`Module m :: acc) n
|
|
|
|
|
| Element_module_type mt :: n ->
|
2002-07-23 07:12:03 -07:00
|
|
|
|
iter (`Module_type mt :: acc) n
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| Element_class c :: n ->
|
2002-07-23 07:12:03 -07:00
|
|
|
|
iter (`Class c :: acc) n
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| Element_class_type ct :: n ->
|
2002-07-23 07:12:03 -07:00
|
|
|
|
iter (`Class_type ct :: acc) n
|
2002-04-05 03:25:22 -08:00
|
|
|
|
(* forget the rest *)
|
|
|
|
|
| _ :: n -> iter acc n
|
|
|
|
|
in
|
|
|
|
|
iter []
|
|
|
|
|
|
|
|
|
|
type indices = [
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| `Type
|
|
|
|
|
| `Exception
|
|
|
|
|
| `Value
|
|
|
|
|
| `Class_att
|
|
|
|
|
| `Method
|
|
|
|
|
| `Class
|
|
|
|
|
| `Class_type
|
|
|
|
|
| `Module
|
2002-04-05 03:25:22 -08:00
|
|
|
|
| `Module_type
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
let indices = function
|
|
|
|
|
| `Type -> "ty"
|
|
|
|
|
| `Exception -> "ex"
|
|
|
|
|
| `Value -> "va"
|
|
|
|
|
| `Class_att -> "ca"
|
|
|
|
|
| `Method -> "me"
|
|
|
|
|
| `Class -> "cl"
|
|
|
|
|
| `Class_type -> "ct"
|
|
|
|
|
| `Module -> "mo"
|
|
|
|
|
| `Module_type -> "mt"
|
|
|
|
|
|
|
|
|
|
let indices_names = [
|
2002-05-08 05:39:32 -07:00
|
|
|
|
"Types" , "ty" ;
|
|
|
|
|
"Exceptions" , "ex" ;
|
|
|
|
|
"Values" , "va" ;
|
2002-04-05 03:25:22 -08:00
|
|
|
|
"Class attributes", "ca" ;
|
2002-05-08 05:39:32 -07:00
|
|
|
|
"Methods" , "me" ;
|
|
|
|
|
"Classes" , "cl" ;
|
|
|
|
|
"Class types" , "ct" ;
|
|
|
|
|
"Modules" , "mo" ;
|
|
|
|
|
"Module types" , "mt" ; ]
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(** Module for generating various Texinfo things (menus, xrefs, ...) *)
|
|
|
|
|
module Texi =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
struct
|
|
|
|
|
(** Associations of strings to subsitute in Texinfo code. *)
|
|
|
|
|
let subst_strings = [
|
|
|
|
|
(Str.regexp "@", "@@") ;
|
|
|
|
|
(Str.regexp "{", "@{") ;
|
|
|
|
|
(Str.regexp "}", "@}") ;
|
|
|
|
|
(Str.regexp "\\.\\.\\.", "@dots{}") ;
|
|
|
|
|
] @
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(if !Args.esc_8bits
|
2002-04-05 03:25:22 -08:00
|
|
|
|
then [
|
|
|
|
|
(Str.regexp "<EFBFBD>", "@`a") ;
|
|
|
|
|
(Str.regexp "<EFBFBD>", "@^a") ;
|
|
|
|
|
(Str.regexp "<EFBFBD>", "@'e") ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(Str.regexp "<EFBFBD>", "@`e") ;
|
2002-04-05 03:25:22 -08:00
|
|
|
|
(Str.regexp "<EFBFBD>", "@^e") ;
|
|
|
|
|
(Str.regexp "<EFBFBD>", "@\"e") ;
|
|
|
|
|
(Str.regexp "<EFBFBD>", "@,{c}") ;
|
|
|
|
|
(Str.regexp "<EFBFBD>", "@^o") ;
|
|
|
|
|
(Str.regexp "<EFBFBD>", "@\"o") ;
|
|
|
|
|
(Str.regexp "<EFBFBD>", "@^i") ;
|
|
|
|
|
(Str.regexp "<EFBFBD>", "@\"i") ;
|
|
|
|
|
(Str.regexp "<EFBFBD>", "@`u") ;
|
|
|
|
|
(Str.regexp "<EFBFBD>", "@^u") ;
|
|
|
|
|
(Str.regexp "<EFBFBD>", "@ae{}" ) ;
|
|
|
|
|
(Str.regexp "<EFBFBD>", "@AE{}" ) ;
|
|
|
|
|
(Str.regexp "<EFBFBD>", "@ss{}" ) ;
|
|
|
|
|
(Str.regexp "<EFBFBD>", "@copyright{}" ) ;
|
|
|
|
|
]
|
|
|
|
|
else [])
|
|
|
|
|
|
|
|
|
|
(** Escape the strings which would clash with Texinfo syntax. *)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let escape s =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
List.fold_left
|
|
|
|
|
(fun acc (p, r) -> Str.global_replace p r acc)
|
|
|
|
|
s subst_strings
|
|
|
|
|
|
|
|
|
|
(** Removes dots (no good for a node name). *)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let fix_nodename s =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
Str.global_replace (Str.regexp "\\.") "/" (escape s)
|
|
|
|
|
|
|
|
|
|
(** Generates a Texinfo menu. *)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let generate_menu chan subpart_list =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
if subpart_list <> []
|
|
|
|
|
then begin
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let menu_line part_qual name =
|
2002-07-23 07:12:03 -07:00
|
|
|
|
let sname = Name.simple name in
|
|
|
|
|
if sname = name
|
|
|
|
|
then (
|
2006-01-04 08:55:50 -08:00
|
|
|
|
puts chan (pad_to 35
|
2002-07-23 07:12:03 -07:00
|
|
|
|
("* " ^ sname ^ ":: ")) ;
|
|
|
|
|
puts_nl chan part_qual )
|
|
|
|
|
else (
|
2006-01-04 08:55:50 -08:00
|
|
|
|
puts chan (pad_to 35
|
2002-07-23 07:12:03 -07:00
|
|
|
|
("* " ^ sname ^ ": " ^ (fix_nodename name) ^ ". " )) ;
|
|
|
|
|
puts_nl chan part_qual )
|
2002-04-05 03:25:22 -08:00
|
|
|
|
in
|
|
|
|
|
puts_nl chan "@menu" ;
|
|
|
|
|
List.iter
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(function
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| `Module { m_name = name } ->
|
2002-07-23 07:12:03 -07:00
|
|
|
|
menu_line Odoc_messages.modul name
|
|
|
|
|
| `Module_type { mt_name = name } ->
|
|
|
|
|
menu_line Odoc_messages.module_type name
|
|
|
|
|
| `Class { cl_name = name } ->
|
|
|
|
|
menu_line Odoc_messages.clas name
|
|
|
|
|
| `Class_type { clt_name = name } ->
|
2006-01-04 08:55:50 -08:00
|
|
|
|
menu_line Odoc_messages.class_type name
|
|
|
|
|
| `Blank -> nl chan
|
2002-07-23 07:12:03 -07:00
|
|
|
|
| `Comment c -> puts_nl chan (escape c)
|
|
|
|
|
| `Texi t -> puts_nl chan t
|
|
|
|
|
| `Index ind -> Printf.fprintf chan "* %s::\n" ind)
|
2002-04-05 03:25:22 -08:00
|
|
|
|
subpart_list ;
|
|
|
|
|
puts_nl chan "@end menu"
|
|
|
|
|
end
|
|
|
|
|
|
2002-05-08 05:39:32 -07:00
|
|
|
|
(** cross reference to node [name] *)
|
2002-04-05 03:25:22 -08:00
|
|
|
|
let xref ?xname name =
|
2006-01-04 08:55:50 -08:00
|
|
|
|
"@xref{" ^ (fix_nodename name) ^
|
|
|
|
|
(match xname with | None -> "" | Some s -> "," ^ s) ^
|
2002-04-05 03:25:22 -08:00
|
|
|
|
"}."
|
|
|
|
|
|
2002-05-08 05:39:32 -07:00
|
|
|
|
(** enclose the string between [\@ifinfo] tags *)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let ifinfo s =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
String.concat "\n"
|
|
|
|
|
[ "@ifinfo" ; s ; "@end ifinfo" ; "" ]
|
2003-02-21 05:49:35 -08:00
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(** [install-info] informations *)
|
2003-02-21 05:49:35 -08:00
|
|
|
|
let dirsection sec =
|
|
|
|
|
"@dircategory " ^ (escape sec)
|
|
|
|
|
|
|
|
|
|
let direntry ent =
|
2006-01-04 08:55:50 -08:00
|
|
|
|
[ "@direntry" ] @
|
|
|
|
|
(List.map escape ent) @
|
2003-02-21 05:49:35 -08:00
|
|
|
|
[ "@end direntry" ]
|
2002-04-05 03:25:22 -08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-05-08 05:39:32 -07:00
|
|
|
|
(** {2 Generation of Texinfo code} *)
|
|
|
|
|
|
|
|
|
|
(** This class generates Texinfo code from text structures *)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
class text =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
object(self)
|
|
|
|
|
|
2002-05-08 05:39:32 -07:00
|
|
|
|
(** Associations between a title number and texinfo code. *)
|
2002-04-05 03:25:22 -08:00
|
|
|
|
val titles = [
|
|
|
|
|
1, "@chapter " ;
|
|
|
|
|
2, "@section " ;
|
|
|
|
|
3, "@subsection " ;
|
|
|
|
|
4, "@subsubsection " ;
|
|
|
|
|
]
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
val fallback_title =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
"@unnumberedsubsubsec "
|
|
|
|
|
|
|
|
|
|
val headings = [
|
|
|
|
|
1, "@majorheading " ;
|
|
|
|
|
2, "@heading " ;
|
|
|
|
|
3, "@subheading " ;
|
|
|
|
|
4, "@subsubheading " ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
val fallback_heading =
|
|
|
|
|
"@subsubheading "
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method escape =
|
|
|
|
|
Texi.escape
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
2002-05-08 05:39:32 -07:00
|
|
|
|
(** this method is not used here but is virtual
|
|
|
|
|
in a class we will inherit later *)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method label ?(no_ : bool option) (_ : string) : string =
|
2004-11-28 18:27:25 -08:00
|
|
|
|
failwith "gni"
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
|
|
|
|
(** Return the Texinfo code corresponding to the [text] parameter.*)
|
|
|
|
|
method texi_of_text t =
|
|
|
|
|
String.concat ""
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(List.map self#texi_of_text_element t)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
|
2002-05-08 05:39:32 -07:00
|
|
|
|
|
|
|
|
|
(** {3 Conversion methods}
|
|
|
|
|
[texi_of_????] converts a [text_element] to a Texinfo string. *)
|
|
|
|
|
|
2002-04-05 03:25:22 -08:00
|
|
|
|
(** Return the Texinfo code for the [text_element] in parameter. *)
|
|
|
|
|
method texi_of_text_element = function
|
|
|
|
|
| Verbatim s | Latex s -> self#texi_of_Verbatim s
|
|
|
|
|
| Raw s -> self#texi_of_Raw s
|
|
|
|
|
| Code s -> self#texi_of_Code s
|
|
|
|
|
| CodePre s -> self#texi_of_CodePre s
|
|
|
|
|
| Bold t -> self#texi_of_Bold t
|
|
|
|
|
| Italic t -> self#texi_of_Italic t
|
|
|
|
|
| Emphasize t -> self#texi_of_Emphasize t
|
|
|
|
|
| Center t -> self#texi_of_Center t
|
|
|
|
|
| Left t -> self#texi_of_Left t
|
|
|
|
|
| Right t -> self#texi_of_Right t
|
|
|
|
|
| List tl -> self#texi_of_List tl
|
|
|
|
|
| Enum tl -> self#texi_of_Enum tl
|
|
|
|
|
| Newline -> self#texi_of_Newline
|
|
|
|
|
| Block t -> self#texi_of_Block t
|
|
|
|
|
| Title (n, _, t) -> self#texi_of_Title n t
|
|
|
|
|
| Link (s, t) -> self#texi_of_Link s t
|
|
|
|
|
| Ref (name, kind) ->self#texi_of_Ref name kind
|
|
|
|
|
| Superscript t -> self#texi_of_Superscript t
|
|
|
|
|
| Subscript t -> self#texi_of_Subscript t
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| Odoc_info.Module_list _ -> ""
|
|
|
|
|
| Odoc_info.Index_list -> ""
|
|
|
|
|
| Odoc_info.Custom (s,t) -> self#texi_of_custom_text s t
|
|
|
|
|
|
|
|
|
|
method texi_of_custom_text s t = ""
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
|
|
|
|
method texi_of_Verbatim s = s
|
|
|
|
|
method texi_of_Raw s = self#escape s
|
|
|
|
|
method texi_of_Code s = "@code{" ^ (self#escape s) ^ "}"
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method texi_of_CodePre s =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
String.concat "\n"
|
2002-07-23 07:12:03 -07:00
|
|
|
|
[ "" ; "@example" ; self#escape s ; "@end example" ; "" ]
|
2002-04-05 03:25:22 -08:00
|
|
|
|
method texi_of_Bold t = "@strong{" ^ (self#texi_of_text t) ^ "}"
|
|
|
|
|
method texi_of_Italic t = "@i{" ^ (self#texi_of_text t) ^ "}"
|
|
|
|
|
method texi_of_Emphasize t = "@emph{" ^ (self#texi_of_text t) ^ "}"
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method texi_of_Center t =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
let sl = Str.split (Str.regexp "\n") (self#texi_of_text t) in
|
|
|
|
|
String.concat ""
|
2002-07-23 07:12:03 -07:00
|
|
|
|
((List.map (fun s -> "\n@center "^s) sl) @ [ "\n" ])
|
2002-04-05 03:25:22 -08:00
|
|
|
|
method texi_of_Left t =
|
2006-01-04 08:55:50 -08:00
|
|
|
|
String.concat "\n"
|
2002-07-23 07:12:03 -07:00
|
|
|
|
[ "" ; "@flushleft" ; self#texi_of_text t ; "@end flushleft" ; "" ]
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method texi_of_Right t =
|
|
|
|
|
String.concat "\n"
|
2002-07-23 07:12:03 -07:00
|
|
|
|
[ "" ; "@flushright" ; self#texi_of_text t ; "@end flushright"; "" ]
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method texi_of_List tl =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
String.concat "\n"
|
2006-01-04 08:55:50 -08:00
|
|
|
|
( [ "" ; "@itemize" ] @
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(List.map (fun t -> "@item\n" ^ (self#texi_of_text t)) tl) @
|
|
|
|
|
[ "@end itemize"; "" ] )
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method texi_of_Enum tl =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
String.concat "\n"
|
2006-01-04 08:55:50 -08:00
|
|
|
|
( [ "" ; "@enumerate" ] @
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(List.map (fun t -> "@item\n" ^ (self#texi_of_text t)) tl) @
|
|
|
|
|
[ "@end enumerate"; "" ] )
|
2002-04-05 03:25:22 -08:00
|
|
|
|
method texi_of_Newline = "\n"
|
|
|
|
|
method texi_of_Block t =
|
|
|
|
|
String.concat "\n"
|
2002-07-23 07:12:03 -07:00
|
|
|
|
[ "@format" ; self#texi_of_text t ; "@end format" ; "" ]
|
2002-04-05 03:25:22 -08:00
|
|
|
|
method texi_of_Title n t =
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let t_begin =
|
|
|
|
|
try List.assoc n titles
|
2002-07-23 07:12:03 -07:00
|
|
|
|
with Not_found -> fallback_title in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
t_begin ^ (self#texi_of_text t) ^ "\n"
|
|
|
|
|
method texi_of_Link s t =
|
|
|
|
|
String.concat ""
|
2002-07-23 07:12:03 -07:00
|
|
|
|
[ "@uref{" ; s ; "," ; self#texi_of_text t ; "}" ]
|
2002-04-05 03:25:22 -08:00
|
|
|
|
method texi_of_Ref name kind =
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let xname =
|
2002-07-23 07:12:03 -07:00
|
|
|
|
match kind with
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| Some RK_module ->
|
2002-07-23 07:12:03 -07:00
|
|
|
|
Odoc_messages.modul ^ " " ^ (Name.simple name)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| Some RK_module_type ->
|
2002-07-23 07:12:03 -07:00
|
|
|
|
Odoc_messages.module_type ^ " " ^ (Name.simple name)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| Some RK_class ->
|
2002-07-23 07:12:03 -07:00
|
|
|
|
Odoc_messages.clas ^ " " ^ (Name.simple name)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| Some RK_class_type ->
|
2002-07-23 07:12:03 -07:00
|
|
|
|
Odoc_messages.class_type ^ " " ^ (Name.simple name)
|
|
|
|
|
| _ -> ""
|
2002-04-05 03:25:22 -08:00
|
|
|
|
in
|
|
|
|
|
if xname = "" then self#escape name else Texi.xref ~xname name
|
|
|
|
|
method texi_of_Superscript t =
|
|
|
|
|
"^@{" ^ (self#texi_of_text t) ^ "@}"
|
|
|
|
|
method texi_of_Subscript t =
|
|
|
|
|
"_@{" ^ (self#texi_of_text t) ^ "@}"
|
|
|
|
|
|
|
|
|
|
method heading n t =
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let f =
|
2002-07-23 07:12:03 -07:00
|
|
|
|
try List.assoc n headings
|
|
|
|
|
with Not_found -> fallback_heading
|
2002-04-05 03:25:22 -08:00
|
|
|
|
in
|
|
|
|
|
f ^ (self#texi_of_text t) ^ "\n"
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method fixedblock t =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
Block ( ( Verbatim "@t{" :: t ) @ [ Verbatim "}" ] )
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
2004-07-13 05:25:21 -07:00
|
|
|
|
exception Aliased_node
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
|
|
|
|
(** This class is used to create objects which can generate a simple
|
|
|
|
|
Texinfo documentation. *)
|
|
|
|
|
class texi =
|
|
|
|
|
object (self)
|
|
|
|
|
inherit text as to_texi
|
|
|
|
|
inherit Odoc_to_text.to_text as to_text
|
|
|
|
|
|
2002-05-08 05:39:32 -07:00
|
|
|
|
(** {3 Small helper stuff.} *)
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
|
|
|
|
val maxdepth = 4
|
|
|
|
|
|
|
|
|
|
val bullet = Verbatim " @bullet{} "
|
|
|
|
|
val minus = Verbatim " @minus{} "
|
|
|
|
|
val linebreak = Verbatim "@*\n"
|
|
|
|
|
|
2002-11-07 00:36:00 -08:00
|
|
|
|
val mutable indices_to_build = [ `Module ]
|
|
|
|
|
|
2004-07-13 05:25:21 -07:00
|
|
|
|
(** Keep a set of nodes we create. If we try to create one
|
|
|
|
|
a second time, that means it is some kind of alias, so
|
|
|
|
|
don't do it, just link to the previous one *)
|
|
|
|
|
val node_tbl = Hashtbl.create 37
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method node depth name =
|
2004-07-13 05:25:21 -07:00
|
|
|
|
if Hashtbl.mem node_tbl name
|
|
|
|
|
then raise Aliased_node ;
|
|
|
|
|
Hashtbl.add node_tbl name () ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
if depth <= maxdepth
|
2002-04-05 03:25:22 -08:00
|
|
|
|
then Verbatim ("@node " ^ (Texi.fix_nodename name) ^ ",\n")
|
|
|
|
|
else nothing
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method index (ind : indices) ent =
|
|
|
|
|
Verbatim
|
|
|
|
|
(if !Args.with_index
|
2002-11-07 00:36:00 -08:00
|
|
|
|
then (assert(List.mem ind indices_to_build) ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
String.concat ""
|
|
|
|
|
[ "@" ; indices ind ; "index " ;
|
|
|
|
|
Texi.escape (Name.simple ent) ; "\n" ])
|
2002-07-23 07:12:03 -07:00
|
|
|
|
else "")
|
2006-01-04 08:55:50 -08:00
|
|
|
|
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
2002-05-08 05:39:32 -07:00
|
|
|
|
(** Two hacks to fix linebreaks in the descriptions.*)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method private fix_linebreaks =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
let re = Str.regexp "\n[ \t]*" in
|
2002-05-08 05:39:32 -07:00
|
|
|
|
fun t ->
|
2006-01-04 08:55:50 -08:00
|
|
|
|
List.map
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(function
|
|
|
|
|
| Newline -> Raw "\n"
|
|
|
|
|
| Raw s -> Raw (Str.global_replace re "\n" s)
|
2004-07-13 05:25:21 -07:00
|
|
|
|
| List tel -> List (List.map self#fix_linebreaks tel)
|
|
|
|
|
| Enum tel -> Enum (List.map self#fix_linebreaks tel)
|
2002-07-23 07:12:03 -07:00
|
|
|
|
| te -> te) t
|
2002-05-08 05:39:32 -07:00
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method private soft_fix_linebreaks =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
let re = Str.regexp "\n[ \t]*" in
|
2002-05-08 05:39:32 -07:00
|
|
|
|
fun ind t ->
|
2002-07-23 07:12:03 -07:00
|
|
|
|
let rep = String.make (succ ind) ' ' in
|
|
|
|
|
rep.[0] <- '\n' ;
|
|
|
|
|
List.map
|
|
|
|
|
(function
|
|
|
|
|
| Raw s -> Raw (Str.global_replace re rep s)
|
|
|
|
|
| te -> te) t
|
2002-05-08 05:39:32 -07:00
|
|
|
|
|
|
|
|
|
(** {3 [text] values generation}
|
|
|
|
|
Generates [text] values out of description parts.
|
|
|
|
|
Redefines some of methods of {! Odoc_to_text.to_text}. *)
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
|
|
|
|
method text_of_desc = function
|
|
|
|
|
| None -> []
|
|
|
|
|
| Some [ Raw "" ] -> []
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| Some t -> (self#fix_linebreaks t) @ [ Newline ]
|
2002-05-08 05:39:32 -07:00
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method text_of_sees_opt see_l =
|
2002-05-08 05:39:32 -07:00
|
|
|
|
List.concat
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(List.map
|
|
|
|
|
(function
|
|
|
|
|
| (See_url s, t) ->
|
|
|
|
|
[ linebreak ; Bold [ Raw Odoc_messages.see_also ] ;
|
|
|
|
|
Raw " " ; Link (s, t) ; Newline ]
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| (See_file s, t)
|
2002-07-23 07:12:03 -07:00
|
|
|
|
| (See_doc s, t) ->
|
|
|
|
|
[ linebreak ; Bold [ Raw Odoc_messages.see_also ] ;
|
|
|
|
|
Raw " " ; Raw s ] @ t @ [ Newline ])
|
|
|
|
|
see_l)
|
2002-05-08 05:39:32 -07:00
|
|
|
|
|
|
|
|
|
method text_of_params params_list =
|
2002-07-23 07:12:03 -07:00
|
|
|
|
List.concat
|
|
|
|
|
(List.map
|
|
|
|
|
(fun (s, t) ->
|
2006-01-04 08:55:50 -08:00
|
|
|
|
[ linebreak ;
|
2002-07-23 07:12:03 -07:00
|
|
|
|
Bold [ Raw Odoc_messages.parameters ] ;
|
|
|
|
|
Raw " " ; Raw s ; Raw ": " ] @ t @ [ Newline ] )
|
|
|
|
|
params_list)
|
2002-05-08 05:39:32 -07:00
|
|
|
|
|
|
|
|
|
method text_of_raised_exceptions = function
|
|
|
|
|
| [] -> []
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| (s, t) :: [] ->
|
2002-07-23 07:12:03 -07:00
|
|
|
|
[ linebreak ;
|
|
|
|
|
Bold [ Raw Odoc_messages.raises ] ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
Raw " " ; Code s ; Raw " " ]
|
2002-07-23 07:12:03 -07:00
|
|
|
|
@ t @ [ Newline ]
|
2002-05-08 05:39:32 -07:00
|
|
|
|
| l ->
|
2002-07-23 07:12:03 -07:00
|
|
|
|
[ linebreak ;
|
|
|
|
|
Bold [ Raw Odoc_messages.raises ] ;
|
|
|
|
|
Raw " :" ;
|
|
|
|
|
List
|
|
|
|
|
(List.map
|
|
|
|
|
(fun (ex, desc) ->(Code ex) :: (Raw " ") :: desc ) l ) ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
Newline ]
|
2002-05-08 05:39:32 -07:00
|
|
|
|
|
2002-04-05 03:25:22 -08:00
|
|
|
|
method text_of_return_opt = function
|
|
|
|
|
| None -> []
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| Some t ->
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(Bold [Raw Odoc_messages.returns ]) :: Raw " " :: t @ [ Newline ]
|
2002-05-08 05:39:32 -07:00
|
|
|
|
|
|
|
|
|
method text_of_custom c_l =
|
2006-01-04 08:55:50 -08:00
|
|
|
|
List.flatten
|
|
|
|
|
(List.rev
|
|
|
|
|
(List.fold_left
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(fun acc -> fun (tag, text) ->
|
|
|
|
|
try
|
|
|
|
|
let f = List.assoc tag tag_functions in
|
|
|
|
|
( linebreak :: (f text) @ [ Newline ] ) :: acc
|
|
|
|
|
with
|
|
|
|
|
Not_found ->
|
|
|
|
|
Odoc_info.warning (Odoc_messages.tag_not_handled tag) ;
|
|
|
|
|
acc
|
|
|
|
|
) [] c_l))
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
|
|
|
|
method text_of_info ?(block=false) = function
|
|
|
|
|
| None -> []
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| Some info ->
|
|
|
|
|
let t =
|
2002-07-23 07:12:03 -07:00
|
|
|
|
List.concat
|
|
|
|
|
[ ( match info.i_deprecated with
|
|
|
|
|
| None -> []
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| Some t ->
|
|
|
|
|
(Raw (Odoc_messages.deprecated ^ " ")) ::
|
|
|
|
|
(self#fix_linebreaks t)
|
2002-07-23 07:12:03 -07:00
|
|
|
|
@ [ Newline ; Newline ] ) ;
|
|
|
|
|
self#text_of_desc info.i_desc ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
if info.i_authors <> []
|
2002-07-23 07:12:03 -07:00
|
|
|
|
then ( linebreak ::
|
|
|
|
|
self#text_of_author_list info.i_authors )
|
|
|
|
|
else [] ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
if is info.i_version
|
|
|
|
|
then ( linebreak ::
|
2002-07-23 07:12:03 -07:00
|
|
|
|
self#text_of_version_opt info.i_version )
|
|
|
|
|
else [] ;
|
|
|
|
|
self#text_of_sees_opt info.i_sees ;
|
|
|
|
|
if is info.i_since
|
|
|
|
|
then ( linebreak ::
|
|
|
|
|
self#text_of_since_opt info.i_since )
|
|
|
|
|
else [] ;
|
|
|
|
|
self#text_of_params info.i_params ;
|
|
|
|
|
self#text_of_raised_exceptions info.i_raised_exceptions ;
|
|
|
|
|
if is info.i_return_value
|
2006-01-04 08:55:50 -08:00
|
|
|
|
then ( linebreak ::
|
2002-07-23 07:12:03 -07:00
|
|
|
|
self#text_of_return_opt info.i_return_value )
|
|
|
|
|
else [] ;
|
|
|
|
|
self#text_of_custom info.i_custom ;
|
|
|
|
|
] in
|
2006-01-04 08:55:50 -08:00
|
|
|
|
if block
|
|
|
|
|
then [ Block t ]
|
2002-07-23 07:12:03 -07:00
|
|
|
|
else (t @ [ Newline ] )
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
|
|
|
|
method texi_of_info i =
|
|
|
|
|
self#texi_of_text (self#text_of_info i)
|
|
|
|
|
|
2002-05-08 05:39:32 -07:00
|
|
|
|
(** {3 Conversion of [module_elements] into Texinfo strings}
|
2006-01-04 08:55:50 -08:00
|
|
|
|
The following functions convert [module_elements] and their
|
2002-05-08 05:39:32 -07:00
|
|
|
|
description to [text] values then to Texinfo strings using the
|
|
|
|
|
functions above. *)
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method text_el_of_type_expr m_name typ =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
Raw (indent 5
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(self#relative_idents m_name
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(Odoc_info.string_of_type_expr typ)))
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
|
|
|
|
method text_of_short_type_expr m_name typ =
|
|
|
|
|
[ Raw (self#normal_type m_name typ) ]
|
|
|
|
|
|
|
|
|
|
(** Return Texinfo code for a value. *)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method texi_of_value v =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
Odoc_info.reset_type_names () ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let t = [ self#fixedblock
|
|
|
|
|
[ Newline ; minus ;
|
|
|
|
|
Raw ("val " ^ (Name.simple v.val_name) ^ " :\n") ;
|
|
|
|
|
self#text_el_of_type_expr
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(Name.father v.val_name) v.val_type ] ;
|
|
|
|
|
self#index `Value v.val_name ; Newline ] @
|
|
|
|
|
(self#text_of_info v.val_info) in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
self#texi_of_text t
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(** Return Texinfo code for a class attribute. *)
|
|
|
|
|
method texi_of_attribute a =
|
|
|
|
|
Odoc_info.reset_type_names () ;
|
|
|
|
|
let t = [ self#fixedblock
|
2006-01-04 08:55:50 -08:00
|
|
|
|
[ Newline ; minus ;
|
2002-07-23 07:12:03 -07:00
|
|
|
|
Raw "val " ;
|
2008-07-23 01:55:36 -07:00
|
|
|
|
Raw (if a.att_virtual then "virtual " else "") ;
|
2002-07-23 07:12:03 -07:00
|
|
|
|
Raw (if a.att_mutable then "mutable " else "") ;
|
|
|
|
|
Raw (Name.simple a.att_value.val_name) ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
Raw " :\n" ;
|
|
|
|
|
self#text_el_of_type_expr
|
|
|
|
|
(Name.father a.att_value.val_name)
|
2002-07-23 07:12:03 -07:00
|
|
|
|
a.att_value.val_type ] ;
|
|
|
|
|
self#index `Class_att a.att_value.val_name ; Newline ] @
|
|
|
|
|
(self#text_of_info a.att_value.val_info) in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
self#texi_of_text t
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(** Return Texinfo code for a class method. *)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method texi_of_method m =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
Odoc_info.reset_type_names () ;
|
|
|
|
|
let t = [ self#fixedblock
|
2002-07-23 07:12:03 -07:00
|
|
|
|
[ Newline ; minus ; Raw "method " ;
|
|
|
|
|
Raw (if m.met_private then "private " else "") ;
|
|
|
|
|
Raw (if m.met_virtual then "virtual " else "") ;
|
|
|
|
|
Raw (Name.simple m.met_value.val_name) ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
Raw " :\n" ;
|
|
|
|
|
self#text_el_of_type_expr
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(Name.father m.met_value.val_name)
|
|
|
|
|
m.met_value.val_type ] ;
|
|
|
|
|
self#index `Method m.met_value.val_name ; Newline ] @
|
|
|
|
|
(self#text_of_info m.met_value.val_info) in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
self#texi_of_text t
|
|
|
|
|
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method string_of_type_parameters t =
|
2003-09-05 08:40:12 -07:00
|
|
|
|
let f (tp, co, cn) =
|
2006-01-04 08:55:50 -08:00
|
|
|
|
Printf.sprintf "%s%s"
|
|
|
|
|
(Odoc_info.string_of_variance t (co, cn))
|
|
|
|
|
(Odoc_info.string_of_type_expr tp)
|
2003-09-05 08:40:12 -07:00
|
|
|
|
in
|
|
|
|
|
match t.ty_parameters with
|
2002-07-23 07:12:03 -07:00
|
|
|
|
| [] -> ""
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| [ (tp, co, cn) ] ->
|
|
|
|
|
(f (tp, co, cn))^" "
|
|
|
|
|
| l ->
|
|
|
|
|
Printf.sprintf "(%s) "
|
|
|
|
|
(String.concat ", " (List.map f l))
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
|
|
|
|
method string_of_type_args = function
|
|
|
|
|
| [] -> ""
|
|
|
|
|
| args -> " of " ^ (Odoc_info.string_of_type_list " * " args)
|
|
|
|
|
|
|
|
|
|
(** Return Texinfo code for a type. *)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method texi_of_type ty =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
Odoc_info.reset_type_names () ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let t =
|
|
|
|
|
[ self#fixedblock (
|
2002-07-23 07:12:03 -07:00
|
|
|
|
[ Newline ; minus ; Raw "type " ;
|
2003-09-05 08:40:12 -07:00
|
|
|
|
Raw (self#string_of_type_parameters ty) ;
|
2002-07-23 07:12:03 -07:00
|
|
|
|
Raw (Name.simple ty.ty_name) ] @
|
2007-10-09 03:29:37 -07:00
|
|
|
|
let priv = ty.ty_private = Asttypes.Private in
|
2002-07-23 07:12:03 -07:00
|
|
|
|
( match ty.ty_manifest with
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| None -> []
|
|
|
|
|
| Some typ ->
|
2007-10-09 03:29:37 -07:00
|
|
|
|
(Raw " = ") ::
|
|
|
|
|
(Raw (if priv then "private " else "")) ::
|
|
|
|
|
(self#text_of_short_type_expr (Name.father ty.ty_name) typ) ) @
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(
|
|
|
|
|
match ty.ty_kind with
|
2003-07-04 02:31:03 -07:00
|
|
|
|
| Type_abstract -> [ Newline ]
|
2007-10-09 03:29:37 -07:00
|
|
|
|
| Type_variant l ->
|
2003-07-04 02:31:03 -07:00
|
|
|
|
(Raw (" ="^(if priv then " private" else "")^"\n")) ::
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(List.flatten
|
|
|
|
|
(List.map
|
2003-07-04 02:31:03 -07:00
|
|
|
|
(fun constr ->
|
|
|
|
|
(Raw (" | " ^ constr.vc_name)) ::
|
|
|
|
|
(Raw (self#string_of_type_args constr.vc_args)) ::
|
|
|
|
|
(match constr.vc_text with
|
|
|
|
|
| None -> [ Newline ]
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| Some t ->
|
|
|
|
|
((Raw (indent 5 "\n(* ")) :: (self#soft_fix_linebreaks 8 t)) @
|
2003-07-04 02:31:03 -07:00
|
|
|
|
[ Raw " *)" ; Newline ]
|
|
|
|
|
) ) l ) )
|
2007-10-09 03:29:37 -07:00
|
|
|
|
| Type_record l ->
|
2003-07-04 02:31:03 -07:00
|
|
|
|
(Raw (" = "^(if priv then "private " else "")^"{\n")) ::
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(List.flatten
|
|
|
|
|
(List.map
|
|
|
|
|
(fun r ->
|
2003-07-04 02:31:03 -07:00
|
|
|
|
[ Raw (" " ^ r.rf_name ^ " : ") ] @
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(self#text_of_short_type_expr
|
2003-07-04 02:31:03 -07:00
|
|
|
|
(Name.father r.rf_name)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
r.rf_type) @
|
2003-07-04 02:31:03 -07:00
|
|
|
|
[ Raw " ;" ] @
|
|
|
|
|
(match r.rf_text with
|
|
|
|
|
| None -> [ Newline ]
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| Some t ->
|
|
|
|
|
((Raw (indent 5 "\n(* ")) :: (self#soft_fix_linebreaks 8 t)) @
|
|
|
|
|
[ Raw " *)" ; Newline ] ) )
|
2003-07-04 02:31:03 -07:00
|
|
|
|
l ) )
|
2006-01-04 08:55:50 -08:00
|
|
|
|
@ [ Raw " }" ]
|
|
|
|
|
) ) ;
|
2002-07-23 07:12:03 -07:00
|
|
|
|
self#index `Type ty.ty_name ; Newline ] @
|
|
|
|
|
(self#text_of_info ty.ty_info) in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
self#texi_of_text t
|
|
|
|
|
|
|
|
|
|
(** Return Texinfo code for an exception. *)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method texi_of_exception e =
|
2002-04-05 03:25:22 -08:00
|
|
|
|
Odoc_info.reset_type_names () ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let t =
|
2002-07-23 07:12:03 -07:00
|
|
|
|
[ self#fixedblock
|
2006-01-04 08:55:50 -08:00
|
|
|
|
( [ Newline ; minus ; Raw "exception " ;
|
2002-07-23 07:12:03 -07:00
|
|
|
|
Raw (Name.simple e.ex_name) ;
|
|
|
|
|
Raw (self#string_of_type_args e.ex_args) ] @
|
|
|
|
|
(match e.ex_alias with
|
|
|
|
|
| None -> []
|
|
|
|
|
| Some ea -> [ Raw " = " ; Raw
|
|
|
|
|
( match ea.ea_ex with
|
|
|
|
|
| None -> ea.ea_name
|
|
|
|
|
| Some e -> e.ex_name ) ; ]
|
|
|
|
|
) ) ;
|
|
|
|
|
self#index `Exception e.ex_name ; Newline ] @
|
|
|
|
|
(self#text_of_info e.ex_info) in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
self#texi_of_text t
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(** Return the Texinfo code for the given module. *)
|
|
|
|
|
method texi_of_module m =
|
|
|
|
|
let is_alias = function
|
2002-07-23 07:12:03 -07:00
|
|
|
|
| { m_kind = Module_alias _ } -> true
|
|
|
|
|
| _ -> false in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
let is_alias_there = function
|
2002-07-23 07:12:03 -07:00
|
|
|
|
| { m_kind = Module_alias { ma_module = None } } -> false
|
|
|
|
|
| _ -> true in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
let resolve_alias_name = function
|
2002-07-23 07:12:03 -07:00
|
|
|
|
| { m_kind = Module_alias { ma_name = name } } -> name
|
|
|
|
|
| { m_name = name } -> name in
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let t =
|
|
|
|
|
[ [ self#fixedblock
|
|
|
|
|
[ Newline ; minus ; Raw "module " ;
|
2002-07-23 07:12:03 -07:00
|
|
|
|
Raw (Name.simple m.m_name) ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
Raw (if is_alias m
|
|
|
|
|
then " = " ^ (resolve_alias_name m)
|
2002-07-23 07:12:03 -07:00
|
|
|
|
else "" ) ] ] ;
|
|
|
|
|
( if is_alias_there m
|
2006-01-04 08:55:50 -08:00
|
|
|
|
then [ Ref (resolve_alias_name m, Some RK_module) ;
|
2002-07-23 07:12:03 -07:00
|
|
|
|
Newline ; ]
|
|
|
|
|
else [] ) ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
( if is_alias m
|
2002-07-23 07:12:03 -07:00
|
|
|
|
then [ self#index `Module m.m_name ; Newline ]
|
|
|
|
|
else [ Newline ] ) ;
|
|
|
|
|
self#text_of_info m.m_info ]
|
2002-04-05 03:25:22 -08:00
|
|
|
|
in
|
|
|
|
|
self#texi_of_text (List.flatten t)
|
|
|
|
|
|
|
|
|
|
(** Return the Texinfo code for the given module type. *)
|
|
|
|
|
method texi_of_module_type mt =
|
|
|
|
|
let is_alias = function
|
2002-07-23 07:12:03 -07:00
|
|
|
|
| { mt_kind = Some (Module_type_alias _) } -> true
|
|
|
|
|
| _ -> false in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
let is_alias_there = function
|
2002-07-23 07:12:03 -07:00
|
|
|
|
| { mt_kind = Some (Module_type_alias { mta_module = None }) } -> false
|
|
|
|
|
| _ -> true in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
let resolve_alias_name = function
|
2002-07-23 07:12:03 -07:00
|
|
|
|
| { mt_kind = Some (Module_type_alias { mta_name = name }) } -> name
|
|
|
|
|
| { mt_name = name } -> name in
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let t =
|
|
|
|
|
[ [ self#fixedblock
|
2007-02-12 02:27:29 -08:00
|
|
|
|
[ Newline ; minus ; Raw "module type " ;
|
2002-07-23 07:12:03 -07:00
|
|
|
|
Raw (Name.simple mt.mt_name) ;
|
|
|
|
|
Raw (if is_alias mt
|
2006-01-04 08:55:50 -08:00
|
|
|
|
then " = " ^ (resolve_alias_name mt)
|
2002-07-23 07:12:03 -07:00
|
|
|
|
else "" ) ] ] ;
|
|
|
|
|
( if is_alias_there mt
|
2006-01-04 08:55:50 -08:00
|
|
|
|
then [ Ref (resolve_alias_name mt, Some RK_module_type) ;
|
2002-07-23 07:12:03 -07:00
|
|
|
|
Newline ; ]
|
|
|
|
|
else [] ) ;
|
|
|
|
|
( if is_alias mt
|
|
|
|
|
then [ self#index `Module_type mt.mt_name ; Newline ]
|
|
|
|
|
else [ Newline ] ) ;
|
|
|
|
|
self#text_of_info mt.mt_info ]
|
2002-04-05 03:25:22 -08:00
|
|
|
|
in
|
|
|
|
|
self#texi_of_text (List.flatten t)
|
|
|
|
|
|
|
|
|
|
(** Return the Texinfo code for the given included module. *)
|
|
|
|
|
method texi_of_included_module im =
|
|
|
|
|
let t = [ self#fixedblock
|
2003-11-21 04:46:30 -08:00
|
|
|
|
( Newline :: minus :: (Raw "include ") ::
|
2002-07-23 07:12:03 -07:00
|
|
|
|
( match im.im_module with
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| None ->
|
2002-07-23 07:12:03 -07:00
|
|
|
|
[ Raw im.im_name ]
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| Some (Mod { m_name = name }) ->
|
|
|
|
|
[ Raw name ; Raw "\n " ;
|
2002-07-23 07:12:03 -07:00
|
|
|
|
Ref (name, Some RK_module) ]
|
|
|
|
|
| Some (Modtype { mt_name = name }) ->
|
2006-01-04 08:55:50 -08:00
|
|
|
|
[ Raw name ; Raw "\n " ;
|
2002-07-23 07:12:03 -07:00
|
|
|
|
Ref (name, Some RK_module_type) ]
|
2006-01-04 08:55:50 -08:00
|
|
|
|
) @
|
|
|
|
|
[ Newline ] @
|
|
|
|
|
(self#text_of_info im.im_info)
|
|
|
|
|
)
|
|
|
|
|
]
|
2003-11-21 04:46:30 -08:00
|
|
|
|
in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
self#texi_of_text t
|
|
|
|
|
|
|
|
|
|
(** Return the Texinfo code for the given class. *)
|
|
|
|
|
method texi_of_class c =
|
|
|
|
|
Odoc_info.reset_type_names () ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let t = [ self#fixedblock
|
|
|
|
|
[ Newline ; minus ; Raw "class " ;
|
|
|
|
|
Raw (Name.simple c.cl_name) ] ;
|
2002-07-23 07:12:03 -07:00
|
|
|
|
Ref (c.cl_name, Some RK_class) ; Newline ;
|
|
|
|
|
Newline ] @ (self#text_of_info c.cl_info) in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
self#texi_of_text t
|
|
|
|
|
|
|
|
|
|
(** Return the Texinfo code for the given class type. *)
|
|
|
|
|
method texi_of_class_type ct =
|
|
|
|
|
Odoc_info.reset_type_names () ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let t = [ self#fixedblock
|
|
|
|
|
[ Newline ; minus ; Raw "class type " ;
|
|
|
|
|
Raw (Name.simple ct.clt_name) ] ;
|
2002-07-23 07:12:03 -07:00
|
|
|
|
Ref (ct.clt_name, Some RK_class_type) ; Newline ;
|
|
|
|
|
Newline ] @ (self#text_of_info ct.clt_info) in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
self#texi_of_text t
|
|
|
|
|
|
|
|
|
|
(** Return the Texinfo code for the given class element. *)
|
|
|
|
|
method texi_of_class_element class_name class_ele =
|
|
|
|
|
match class_ele with
|
|
|
|
|
| Class_attribute att -> self#texi_of_attribute att
|
|
|
|
|
| Class_method met -> self#texi_of_method met
|
|
|
|
|
| Class_comment t -> self#texi_of_text t
|
|
|
|
|
|
|
|
|
|
(** Return the Texinfo code for the given module element. *)
|
|
|
|
|
method texi_of_module_element module_name module_ele =
|
|
|
|
|
(match module_ele with
|
|
|
|
|
| Element_module m -> self#texi_of_module m
|
|
|
|
|
| Element_module_type mt -> self#texi_of_module_type mt
|
|
|
|
|
| Element_included_module im -> self#texi_of_included_module im
|
|
|
|
|
| Element_class c -> self#texi_of_class c
|
|
|
|
|
| Element_class_type ct -> self#texi_of_class_type ct
|
|
|
|
|
| Element_value v -> self#texi_of_value v
|
|
|
|
|
| Element_exception e -> self#texi_of_exception e
|
|
|
|
|
| Element_type t -> self#texi_of_type t
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| Element_module_comment t ->
|
2002-07-23 07:12:03 -07:00
|
|
|
|
self#texi_of_text (Newline :: t @ [Newline])
|
2002-04-05 03:25:22 -08:00
|
|
|
|
)
|
|
|
|
|
|
2002-05-08 05:39:32 -07:00
|
|
|
|
(** {3 Generating methods }
|
|
|
|
|
These methods write Texinfo code to an [out_channel] *)
|
|
|
|
|
|
2002-04-05 03:25:22 -08:00
|
|
|
|
(** Generate the Texinfo code for the given list of inherited classes.*)
|
|
|
|
|
method generate_inheritance_info chanout inher_l =
|
|
|
|
|
let f inh =
|
2002-07-23 07:12:03 -07:00
|
|
|
|
match inh.ic_class with
|
|
|
|
|
| None -> (* we can't make the reference *)
|
|
|
|
|
(Code inh.ic_name) ::
|
|
|
|
|
(match inh.ic_text with
|
|
|
|
|
| None -> []
|
|
|
|
|
| Some t -> Newline :: t)
|
|
|
|
|
| Some cct -> (* we can create the reference *)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let kind =
|
2002-07-23 07:12:03 -07:00
|
|
|
|
match cct with
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| Cl _ -> Some RK_class
|
2002-07-23 07:12:03 -07:00
|
|
|
|
| Cltype _ -> Some RK_class_type in
|
|
|
|
|
(Code inh.ic_name) ::
|
|
|
|
|
(Ref (inh.ic_name, kind)) ::
|
|
|
|
|
( match inh.ic_text with
|
|
|
|
|
| None -> []
|
|
|
|
|
| Some t -> Newline :: t)
|
2002-04-05 03:25:22 -08:00
|
|
|
|
in
|
|
|
|
|
let text = [
|
2002-07-23 07:12:03 -07:00
|
|
|
|
Bold [ Raw Odoc_messages.inherits ] ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
List (List.map f inher_l) ; Newline ]
|
2002-04-05 03:25:22 -08:00
|
|
|
|
in
|
|
|
|
|
puts chanout (self#texi_of_text text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(** Generate the Texinfo code for the inherited classes
|
2002-04-05 03:25:22 -08:00
|
|
|
|
of the given class. *)
|
|
|
|
|
method generate_class_inheritance_info chanout cl =
|
|
|
|
|
let rec iter_kind = function
|
2002-07-23 07:12:03 -07:00
|
|
|
|
| Class_structure ([], _) -> ()
|
|
|
|
|
| Class_structure (l, _) ->
|
|
|
|
|
self#generate_inheritance_info chanout l
|
|
|
|
|
| Class_constraint (k, _) -> iter_kind k
|
|
|
|
|
| Class_apply _
|
|
|
|
|
| Class_constr _ -> ()
|
2002-04-05 03:25:22 -08:00
|
|
|
|
in
|
|
|
|
|
iter_kind cl.cl_kind
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(** Generate the Texinfo code for the inherited classes
|
2002-04-05 03:25:22 -08:00
|
|
|
|
of the given class type. *)
|
|
|
|
|
method generate_class_type_inheritance_info chanout clt =
|
|
|
|
|
match clt.clt_kind with
|
2002-07-23 07:12:03 -07:00
|
|
|
|
| Class_signature ([], _) ->
|
|
|
|
|
()
|
|
|
|
|
| Class_signature (l, _) ->
|
|
|
|
|
self#generate_inheritance_info chanout l
|
|
|
|
|
| Class_type _ ->
|
|
|
|
|
()
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(** Generate the Texinfo code for the given class,
|
2002-04-05 03:25:22 -08:00
|
|
|
|
in the given out channel. *)
|
|
|
|
|
method generate_for_class chanout c =
|
2004-07-13 05:25:21 -07:00
|
|
|
|
try
|
2002-04-05 03:25:22 -08:00
|
|
|
|
Odoc_info.reset_type_names () ;
|
|
|
|
|
let depth = Name.depth c.cl_name in
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let title = [
|
2002-07-23 07:12:03 -07:00
|
|
|
|
self#node depth c.cl_name ;
|
|
|
|
|
Title (depth, None, [ Raw (Odoc_messages.clas ^ " ") ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
Code c.cl_name ]) ;
|
2002-07-23 07:12:03 -07:00
|
|
|
|
self#index `Class c.cl_name ] in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
puts chanout (self#texi_of_text title) ;
|
|
|
|
|
|
|
|
|
|
if is c.cl_info
|
|
|
|
|
then begin
|
2002-07-23 07:12:03 -07:00
|
|
|
|
let descr = [ Title (succ depth, None,
|
|
|
|
|
[ Raw Odoc_messages.description ]) ] in
|
|
|
|
|
puts chanout (self#texi_of_text descr) ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
puts chanout (self#texi_of_info c.cl_info)
|
2002-04-05 03:25:22 -08:00
|
|
|
|
end ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
|
|
|
|
|
let intf = [ Title (succ depth, None,
|
2002-07-23 07:12:03 -07:00
|
|
|
|
[ Raw Odoc_messages.interface]) ] in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
puts chanout (self#texi_of_text intf);
|
|
|
|
|
self#generate_class_inheritance_info chanout c ;
|
|
|
|
|
List.iter
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(fun ele -> puts chanout
|
|
|
|
|
(self#texi_of_class_element c.cl_name ele))
|
|
|
|
|
(Class.class_elements ~trans:false c)
|
2004-07-13 05:25:21 -07:00
|
|
|
|
with Aliased_node -> ()
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(** Generate the Texinfo code for the given class type,
|
2002-04-05 03:25:22 -08:00
|
|
|
|
in the given out channel. *)
|
|
|
|
|
method generate_for_class_type chanout ct =
|
2004-07-13 05:25:21 -07:00
|
|
|
|
try
|
2002-04-05 03:25:22 -08:00
|
|
|
|
Odoc_info.reset_type_names () ;
|
|
|
|
|
let depth = Name.depth ct.clt_name in
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let title = [
|
2002-07-23 07:12:03 -07:00
|
|
|
|
self#node depth ct.clt_name ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
Title (depth, None, [ Raw (Odoc_messages.class_type ^ " ") ;
|
|
|
|
|
Code ct.clt_name ]) ;
|
2002-07-23 07:12:03 -07:00
|
|
|
|
self#index `Class_type ct.clt_name ] in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
puts chanout (self#texi_of_text title) ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
|
2002-04-05 03:25:22 -08:00
|
|
|
|
if is ct.clt_info
|
|
|
|
|
then begin
|
2002-07-23 07:12:03 -07:00
|
|
|
|
let descr = [ Title (succ depth, None,
|
|
|
|
|
[ Raw Odoc_messages.description ]) ] in
|
|
|
|
|
puts chanout (self#texi_of_text descr) ;
|
|
|
|
|
puts chanout (self#texi_of_info ct.clt_info)
|
2002-04-05 03:25:22 -08:00
|
|
|
|
end ;
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let intf = [ Title (succ depth, None,
|
2002-07-23 07:12:03 -07:00
|
|
|
|
[ Raw Odoc_messages.interface ]) ] in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
puts chanout (self#texi_of_text intf) ;
|
|
|
|
|
self#generate_class_type_inheritance_info chanout ct;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
List.iter
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(fun ele -> puts chanout
|
|
|
|
|
(self#texi_of_class_element ct.clt_name ele))
|
|
|
|
|
(Class.class_type_elements ~trans:false ct)
|
2004-07-13 05:25:21 -07:00
|
|
|
|
with Aliased_node -> ()
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(** Generate the Texinfo code for the given module type,
|
2002-04-05 03:25:22 -08:00
|
|
|
|
in the given out channel. *)
|
|
|
|
|
method generate_for_module_type chanout mt =
|
2004-07-13 05:25:21 -07:00
|
|
|
|
try
|
2002-04-05 03:25:22 -08:00
|
|
|
|
let depth = Name.depth mt.mt_name in
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let title = [
|
2002-07-23 07:12:03 -07:00
|
|
|
|
self#node depth mt.mt_name ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
Title (depth, None, [ Raw (Odoc_messages.module_type ^ " ") ;
|
|
|
|
|
Code mt.mt_name ]) ;
|
2002-07-23 07:12:03 -07:00
|
|
|
|
self#index `Module_type mt.mt_name ; Newline ] in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
puts chanout (self#texi_of_text title) ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
|
2002-04-05 03:25:22 -08:00
|
|
|
|
if is mt.mt_info
|
|
|
|
|
then begin
|
2002-07-23 07:12:03 -07:00
|
|
|
|
let descr = [ Title (succ depth, None,
|
|
|
|
|
[ Raw Odoc_messages.description ]) ] in
|
|
|
|
|
puts chanout (self#texi_of_text descr) ;
|
|
|
|
|
puts chanout (self#texi_of_info mt.mt_info)
|
2002-04-05 03:25:22 -08:00
|
|
|
|
end ;
|
|
|
|
|
|
2002-11-07 00:36:00 -08:00
|
|
|
|
let mt_ele = Module.module_type_elements ~trans:true mt in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
let subparts = module_subparts mt_ele in
|
|
|
|
|
if depth < maxdepth && subparts <> []
|
|
|
|
|
then begin
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let menu = Texi.ifinfo
|
2002-07-23 07:12:03 -07:00
|
|
|
|
( self#heading (succ depth) [ Raw "Subparts" ]) in
|
|
|
|
|
puts chanout menu ;
|
2002-11-07 00:36:00 -08:00
|
|
|
|
Texi.generate_menu chanout (subparts :> menu_data)
|
2002-04-05 03:25:22 -08:00
|
|
|
|
end ;
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let intf = [ Title (succ depth, None,
|
2002-07-23 07:12:03 -07:00
|
|
|
|
[ Raw Odoc_messages.interface ]) ] in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
puts chanout (self#texi_of_text intf) ;
|
|
|
|
|
List.iter
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(fun ele -> puts chanout
|
|
|
|
|
(self#texi_of_module_element mt.mt_name ele))
|
|
|
|
|
mt_ele ;
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
|
|
|
|
(* create sub parts for modules, module types, classes and class types *)
|
|
|
|
|
List.iter
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(function
|
|
|
|
|
| `Module m -> self#generate_for_module chanout m
|
|
|
|
|
| `Module_type mt -> self#generate_for_module_type chanout mt
|
|
|
|
|
| `Class c -> self#generate_for_class chanout c
|
|
|
|
|
| `Class_type ct -> self#generate_for_class_type chanout ct)
|
|
|
|
|
subparts
|
2004-07-13 05:25:21 -07:00
|
|
|
|
with Aliased_node -> ()
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(** Generate the Texinfo code for the given module,
|
2002-04-05 03:25:22 -08:00
|
|
|
|
in the given out channel. *)
|
|
|
|
|
method generate_for_module chanout m =
|
2004-07-13 05:25:21 -07:00
|
|
|
|
try
|
2002-11-07 00:36:00 -08:00
|
|
|
|
Odoc_info.verbose ("Generate for module " ^ m.m_name) ;
|
2002-04-05 03:25:22 -08:00
|
|
|
|
let depth = Name.depth m.m_name in
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let title = [
|
2002-07-23 07:12:03 -07:00
|
|
|
|
self#node depth m.m_name ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
Title (depth, None,
|
2006-09-20 04:14:37 -07:00
|
|
|
|
if m.m_text_only then
|
|
|
|
|
[ Raw m.m_name ]
|
|
|
|
|
else
|
|
|
|
|
[ Raw (Odoc_messages.modul ^ " ") ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
Code m.m_name ]
|
2006-09-20 04:14:37 -07:00
|
|
|
|
) ;
|
2002-07-23 07:12:03 -07:00
|
|
|
|
self#index `Module m.m_name ; Newline ] in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
puts chanout (self#texi_of_text title) ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
|
2002-04-05 03:25:22 -08:00
|
|
|
|
if is m.m_info
|
|
|
|
|
then begin
|
2002-07-23 07:12:03 -07:00
|
|
|
|
let descr = [ Title (succ depth, None,
|
|
|
|
|
[ Raw Odoc_messages.description ]) ] in
|
|
|
|
|
puts chanout (self#texi_of_text descr) ;
|
|
|
|
|
puts chanout (self#texi_of_info m.m_info)
|
2002-04-05 03:25:22 -08:00
|
|
|
|
end ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
|
2002-11-07 00:36:00 -08:00
|
|
|
|
let m_ele = Module.module_elements ~trans:true m in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
let subparts = module_subparts m_ele in
|
|
|
|
|
if depth < maxdepth && subparts <> []
|
|
|
|
|
then begin
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let menu = Texi.ifinfo
|
2002-07-23 07:12:03 -07:00
|
|
|
|
( self#heading (succ depth) [ Raw "Subparts" ]) in
|
|
|
|
|
puts chanout menu ;
|
2002-11-07 00:36:00 -08:00
|
|
|
|
Texi.generate_menu chanout (subparts :> menu_data)
|
2002-04-05 03:25:22 -08:00
|
|
|
|
end ;
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let intf = [ Title (succ depth, None,
|
2002-07-23 07:12:03 -07:00
|
|
|
|
[ Raw Odoc_messages.interface]) ] in
|
2002-04-05 03:25:22 -08:00
|
|
|
|
puts chanout (self#texi_of_text intf) ;
|
|
|
|
|
|
|
|
|
|
List.iter
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(fun ele -> puts chanout
|
|
|
|
|
(self#texi_of_module_element m.m_name ele))
|
|
|
|
|
m_ele ;
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
|
|
|
|
(* create sub nodes for modules, module types, classes and class types *)
|
|
|
|
|
List.iter
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(function
|
|
|
|
|
| `Module m -> self#generate_for_module chanout m
|
|
|
|
|
| `Module_type mt -> self#generate_for_module_type chanout mt
|
|
|
|
|
| `Class c -> self#generate_for_class chanout c
|
|
|
|
|
| `Class_type ct -> self#generate_for_class_type chanout ct )
|
|
|
|
|
subparts
|
2004-07-13 05:25:21 -07:00
|
|
|
|
with Aliased_node -> ()
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
|
|
|
|
|
2003-11-27 01:01:17 -08:00
|
|
|
|
(** Writes the header of the TeXinfo document. *)
|
2003-02-21 05:49:35 -08:00
|
|
|
|
method generate_texi_header chan texi_filename m_list =
|
|
|
|
|
let title = match !Args.title with
|
|
|
|
|
| None -> ""
|
|
|
|
|
| Some s -> self#escape s in
|
|
|
|
|
let filename =
|
2006-01-04 08:55:50 -08:00
|
|
|
|
if texi_filename <> "ocamldoc.texi"
|
|
|
|
|
then
|
|
|
|
|
let fn = Filename.basename texi_filename in
|
|
|
|
|
(if Filename.check_suffix fn ".texi"
|
|
|
|
|
then Filename.chop_suffix fn ".texi"
|
|
|
|
|
else fn) ^ ".info"
|
|
|
|
|
else
|
|
|
|
|
if title <> ""
|
|
|
|
|
then title ^ ".info"
|
|
|
|
|
else "doc.info"
|
2002-04-05 03:25:22 -08:00
|
|
|
|
in
|
|
|
|
|
(* write a standard Texinfo header *)
|
|
|
|
|
List.iter
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(puts_nl chan)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(List.flatten
|
2002-07-23 07:12:03 -07:00
|
|
|
|
[ [ "\\input texinfo @c -*-texinfo-*-" ;
|
|
|
|
|
"@c %**start of header" ;
|
|
|
|
|
"@setfilename " ^ filename ;
|
|
|
|
|
"@settitle " ^ title ;
|
|
|
|
|
"@c %**end of header" ; ] ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
|
2003-02-21 05:49:35 -08:00
|
|
|
|
(if !Args.with_index then
|
2006-01-04 08:55:50 -08:00
|
|
|
|
List.map
|
2003-02-21 05:49:35 -08:00
|
|
|
|
(fun ind ->
|
|
|
|
|
"@defcodeindex " ^ (indices ind))
|
|
|
|
|
indices_to_build
|
2002-07-23 07:12:03 -07:00
|
|
|
|
else []) ;
|
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
[ Texi.dirsection !Args.info_section ] ;
|
2003-02-21 05:49:35 -08:00
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
Texi.direntry
|
|
|
|
|
(if !Args.info_entry <> []
|
|
|
|
|
then !Args.info_entry
|
|
|
|
|
else [ Printf.sprintf "* %s: (%s)."
|
|
|
|
|
title
|
|
|
|
|
(Filename.chop_suffix filename ".info") ]) ;
|
2003-02-21 05:49:35 -08:00
|
|
|
|
|
2002-07-23 07:12:03 -07:00
|
|
|
|
[ "@ifinfo" ;
|
|
|
|
|
"This file was generated by Ocamldoc using the Texinfo generator." ;
|
|
|
|
|
"@end ifinfo" ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
|
2002-07-23 07:12:03 -07:00
|
|
|
|
"@c no titlepage." ;
|
|
|
|
|
|
|
|
|
|
"@node Top, , , (dir)" ;
|
|
|
|
|
"@top "^ title ; ]
|
|
|
|
|
] ) ;
|
2003-11-27 01:01:17 -08:00
|
|
|
|
|
|
|
|
|
(* insert the intro file *)
|
|
|
|
|
begin
|
2006-01-04 08:55:50 -08:00
|
|
|
|
match !Odoc_info.Args.intro_file with
|
|
|
|
|
| None when title <> "" ->
|
|
|
|
|
puts_nl chan "@ifinfo" ;
|
|
|
|
|
puts_nl chan ("Documentation for " ^ title) ;
|
2003-11-27 01:01:17 -08:00
|
|
|
|
puts_nl chan "@end ifinfo"
|
2006-01-04 08:55:50 -08:00
|
|
|
|
| None ->
|
|
|
|
|
puts_nl chan "@c no title given"
|
|
|
|
|
| Some f ->
|
|
|
|
|
nl chan ;
|
|
|
|
|
puts_nl chan
|
2006-09-20 04:14:37 -07:00
|
|
|
|
(self#texi_of_info
|
|
|
|
|
(Some (Odoc_info.info_of_comment_file m_list f)))
|
2003-11-27 01:01:17 -08:00
|
|
|
|
end ;
|
|
|
|
|
|
2002-04-05 03:25:22 -08:00
|
|
|
|
(* write a top menu *)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
Texi.generate_menu chan
|
2002-07-23 07:12:03 -07:00
|
|
|
|
((List.map (fun m -> `Module m) m_list) @
|
2003-02-21 05:49:35 -08:00
|
|
|
|
(if !Args.with_index then
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let indices_names_to_build = List.map indices indices_to_build in
|
|
|
|
|
List.rev
|
|
|
|
|
(List.fold_left
|
|
|
|
|
(fun acc ->
|
|
|
|
|
function (longname, shortname)
|
|
|
|
|
when List.mem shortname indices_names_to_build ->
|
|
|
|
|
(`Index (longname ^ " index")) :: acc
|
|
|
|
|
| _ -> acc)
|
|
|
|
|
[ `Comment "Indices :" ; `Blank ]
|
2002-07-23 07:12:03 -07:00
|
|
|
|
indices_names )
|
|
|
|
|
else [] ))
|
2006-01-04 08:55:50 -08:00
|
|
|
|
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
2003-11-27 01:01:17 -08:00
|
|
|
|
(** Writes the trailer of the TeXinfo document. *)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
method generate_texi_trailer chan =
|
|
|
|
|
nl chan ;
|
2003-02-21 05:49:35 -08:00
|
|
|
|
if !Args.with_index
|
2006-01-04 08:55:50 -08:00
|
|
|
|
then
|
|
|
|
|
let indices_names_to_build = List.map indices indices_to_build in
|
2002-07-23 07:12:03 -07:00
|
|
|
|
List.iter (puts_nl chan)
|
|
|
|
|
(List.flatten
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(List.map
|
2002-07-23 07:12:03 -07:00
|
|
|
|
(fun (longname, shortname) ->
|
2006-01-04 08:55:50 -08:00
|
|
|
|
if List.mem shortname indices_names_to_build
|
|
|
|
|
then [ "@node " ^ longname ^ " index," ;
|
|
|
|
|
"@unnumbered " ^ longname ^ " index" ;
|
|
|
|
|
"@printindex " ^ shortname ; ]
|
|
|
|
|
else [])
|
2002-07-23 07:12:03 -07:00
|
|
|
|
indices_names )) ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
if !Args.with_toc
|
2002-04-05 03:25:22 -08:00
|
|
|
|
then puts_nl chan "@contents" ;
|
|
|
|
|
puts_nl chan "@bye"
|
|
|
|
|
|
|
|
|
|
|
2002-11-07 00:36:00 -08:00
|
|
|
|
method do_index it =
|
|
|
|
|
if not (List.mem it indices_to_build)
|
|
|
|
|
then indices_to_build <- it :: indices_to_build
|
2006-01-04 08:55:50 -08:00
|
|
|
|
|
2002-11-07 00:36:00 -08:00
|
|
|
|
(** Scan the whole module information to know which indices need to be build *)
|
|
|
|
|
method scan_for_index : subparts -> unit = function
|
|
|
|
|
| `Module m ->
|
|
|
|
|
let m_ele = Module.module_elements ~trans:true m in
|
2006-01-04 08:55:50 -08:00
|
|
|
|
List.iter self#scan_for_index_in_mod m_ele
|
|
|
|
|
| `Module_type mt ->
|
2002-11-07 00:36:00 -08:00
|
|
|
|
let m_ele = Module.module_type_elements ~trans:true mt in
|
2006-01-04 08:55:50 -08:00
|
|
|
|
List.iter self#scan_for_index_in_mod m_ele
|
2002-11-07 00:36:00 -08:00
|
|
|
|
| `Class c ->
|
|
|
|
|
let c_ele = Class.class_elements ~trans:true c in
|
2006-01-04 08:55:50 -08:00
|
|
|
|
List.iter self#scan_for_index_in_class c_ele
|
2002-11-07 00:36:00 -08:00
|
|
|
|
| `Class_type ct ->
|
|
|
|
|
let c_ele = Class.class_type_elements ~trans:true ct in
|
2006-01-04 08:55:50 -08:00
|
|
|
|
List.iter self#scan_for_index_in_class c_ele
|
|
|
|
|
|
2002-11-07 00:36:00 -08:00
|
|
|
|
method scan_for_index_in_mod = function
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(* no recursion *)
|
2002-11-07 00:36:00 -08:00
|
|
|
|
| Element_value _ -> self#do_index `Value
|
|
|
|
|
| Element_exception _ -> self#do_index `Exception
|
|
|
|
|
| Element_type _ -> self#do_index `Type
|
|
|
|
|
| Element_included_module _
|
|
|
|
|
| Element_module_comment _ -> ()
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(* recursion *)
|
2002-11-07 00:36:00 -08:00
|
|
|
|
| Element_module m -> self#do_index `Module ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
self#scan_for_index (`Module m)
|
2002-11-07 00:36:00 -08:00
|
|
|
|
| Element_module_type mt -> self#do_index `Module_type ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
self#scan_for_index (`Module_type mt)
|
2002-11-07 00:36:00 -08:00
|
|
|
|
| Element_class c -> self#do_index `Class ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
self#scan_for_index (`Class c)
|
2002-11-07 00:36:00 -08:00
|
|
|
|
| Element_class_type ct -> self#do_index `Class_type ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
self#scan_for_index (`Class_type ct)
|
2002-11-07 00:36:00 -08:00
|
|
|
|
|
|
|
|
|
method scan_for_index_in_class = function
|
|
|
|
|
| Class_attribute _ -> self#do_index `Class_att
|
|
|
|
|
| Class_method _ -> self#do_index `Method
|
|
|
|
|
| Class_comment _ -> ()
|
|
|
|
|
|
2002-04-05 03:25:22 -08:00
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
|
(** Generate the Texinfo file from a module list,
|
2002-10-11 01:25:17 -07:00
|
|
|
|
in the {!Odoc_info.Args.out_file} file. *)
|
2002-04-05 03:25:22 -08:00
|
|
|
|
method generate module_list =
|
2004-07-13 05:25:21 -07:00
|
|
|
|
Hashtbl.clear node_tbl ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let filename =
|
|
|
|
|
if !Args.out_file = Odoc_messages.default_out_file
|
|
|
|
|
then "ocamldoc.texi"
|
|
|
|
|
else !Args.out_file in
|
2003-02-21 05:49:35 -08:00
|
|
|
|
if !Args.with_index
|
2006-01-04 08:55:50 -08:00
|
|
|
|
then List.iter self#scan_for_index
|
|
|
|
|
(List.map (fun m -> `Module m) module_list) ;
|
2002-04-05 03:25:22 -08:00
|
|
|
|
try
|
2006-01-04 08:55:50 -08:00
|
|
|
|
let chanout = open_out
|
2002-11-07 00:36:00 -08:00
|
|
|
|
(Filename.concat !Args.target_dir filename) in
|
2006-01-04 08:55:50 -08:00
|
|
|
|
if !Args.with_header
|
2003-02-21 05:49:35 -08:00
|
|
|
|
then self#generate_texi_header chanout filename module_list ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
List.iter
|
|
|
|
|
(self#generate_for_module chanout)
|
2002-07-23 07:12:03 -07:00
|
|
|
|
module_list ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
if !Args.with_trailer
|
2002-07-23 07:12:03 -07:00
|
|
|
|
then self#generate_texi_trailer chanout ;
|
|
|
|
|
close_out chanout
|
2002-04-05 03:25:22 -08:00
|
|
|
|
with
|
2002-07-23 07:12:03 -07:00
|
|
|
|
| Failure s
|
|
|
|
|
| Sys_error s ->
|
|
|
|
|
prerr_endline s ;
|
2006-01-04 08:55:50 -08:00
|
|
|
|
incr Odoc_info.errors
|
2002-04-05 03:25:22 -08:00
|
|
|
|
end
|