package forester

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file Xml_tree.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
open Forester_prelude
open Base

type xml_qname = {
  prefix : string;
  (** The prefix to a qualified XML name; this prefix is expected to be rendered in the scope of a corresponding [xmlns] binding. *)

  uname : string;
  (** The unqualified part of the XML name. *)

  xmlns : string option
  (** The XML namespace bound by the current scope to [prefix]. This is not used when serialising to XML, but can be helpful for other analyses. *)
}
[@@deriving repr]

type xml_attr = {key : xml_qname; value : string}
[@@deriving repr]

type 'content attribution =
  | Author of 'content
  | Contributor of 'content
[@@deriving repr]

type date_ = {
  addr : addr option;
  year : int;
  month : int option;
  day : int option
}
[@@deriving repr]

type date =
  | Date of date_
[@@deriving repr]

type 'content meta_ = {
  key : string;
  body : 'content
}
[@@deriving repr]

type 'content meta =
  | Meta of 'content meta_
[@@deriving repr]

type 'content xml_tag = {
  name : xml_qname;
  attrs : xml_attr list;
  content : 'content
}
[@@deriving repr]

type ref = {
  addr : addr;
  taxon : string option;
  number : string option
}
[@@deriving repr]

type 'content local_link = {
  addr : addr;
  content : 'content;
  title : string option
}
[@@deriving repr]

type 'content external_link = {
  href : string;
  content : 'content;
  title : string option;
}
[@@deriving repr]

type tex = {
  display : [`Inline | `Block];
  body : string
}
[@@deriving repr]

type img = {
  src : string;
}
[@@deriving repr]

type embedded_tex = {
  hash : string;
  preamble : string;
  source : string
}
[@@deriving repr]

type ('content, 'tree) content_node =
  | Text of string
  | CDATA of string
  | Xml_tag of 'content xml_tag
  | Prim of Prim.t * 'content
  | Subtree of 'tree
  | Ref of ref
  | Local_link of 'content local_link
  | External_link of 'content external_link
  | TeX of tex
  | Img of img
  | Embedded_tex of embedded_tex
  | Info of string
[@@deriving repr]

type 'content frontmatter = {
  title : 'content option;
  title_text : string option;
  anchor : string option;
  number : string option;
  taxon : string option;
  designated_parent : string option;
  metas : 'content meta list;
  addr : addr option;
  source_path : string option;
  dates : date list;
  last_changed : date option;
  attributions : 'content attribution list
}
[@@deriving repr]

type tree_options = {
  toc : bool;
  numbered : bool;
  show_heading : bool;
  show_metadata : bool;
  expanded : bool;
  root : bool
}
[@@deriving repr]

type 'content tree = {
  options : tree_options;
  frontmatter : 'content frontmatter;
  mainmatter : 'content;
  backmatter : 'content tree list
}

let tree_t content_t =
  let open Repr in
  mu @@ fun tree_t ->
  record "tree"
    (fun
      options
      frontmatter
      mainmatter
      backmatter
      -> {
          options;
          frontmatter;
          mainmatter;
          backmatter;
        })
  |+ field "options" tree_options_t (fun t -> t.options)
  |+ field "frontmatter" (frontmatter_t content_t)(fun t -> t.frontmatter)
  |+ field "mainmatter" content_t(fun t -> t.mainmatter)
  |+ field "backmatter" (list (tree_t))(fun t -> t.backmatter)
  |> sealr

(* Tie the knot *)
type tree_ = Tree of content tree
[@@deriving repr]
and content = Content of (content, tree_) content_node list
[@@deriving repr]

let splice (Content xs) = xs
let splice_tree (Tree tree) = tree
OCaml

Innovation. Community. Security.