Skip to content

Commit 40aa758

Browse files
committed
Remove RootPage constructor
Instead use `Page(None,name). This change allows pages without parents to be leaf pages, which again helps with tests.
1 parent 68f10f1 commit 40aa758

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1195
-1027
lines changed

src/document/doctree.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ end = struct
6969
{ url = mkurl anchor; text; children }
7070

7171
let compute page ~on_sub t =
72-
let mkurl anchor = { Url.Anchor.page; anchor; kind = `Page } in
72+
let mkurl anchor = { Url.Anchor.page; anchor; kind = `LeafPage } in
7373
Rewire.walk ~classify:(classify ~on_sub) ~node:(node mkurl) t
7474
end
7575

src/document/generator.ml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1637,8 +1637,7 @@ module Make (Syntax : SYNTAX) = struct
16371637

16381638
let page (t : Odoc_model.Lang.Page.t) : Page.t =
16391639
let name =
1640-
match t.name with
1641-
| `RootPage name | `Page (_, name) | `LeafPage (_, name) -> name
1640+
match t.name with `Page (_, name) | `LeafPage (_, name) -> name
16421641
in
16431642
let title = Odoc_model.Names.PageName.to_string name in
16441643
let url = Url.Path.from_identifier t.name in

src/document/url.ml

+19-18
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@ module Path = struct
7676

7777
type kind =
7878
[ `Module
79-
| `ContainerPage
8079
| `Page
80+
| `LeafPage
8181
| `ModuleType
8282
| `Argument
8383
| `Class
8484
| `ClassType
8585
| `File ]
8686

8787
let string_of_kind : kind -> string = function
88-
| `ContainerPage -> "container-page"
89-
| `Module -> "module"
9088
| `Page -> "page"
89+
| `Module -> "module"
90+
| `LeafPage -> "leaf-page"
9191
| `ModuleType -> "module-type"
9292
| `Argument -> "argument"
9393
| `Class -> "class"
@@ -110,20 +110,24 @@ module Path = struct
110110
let kind = `Module in
111111
let page = ModuleName.to_string unit_name in
112112
mk ?parent kind page
113-
| `RootPage page_name ->
114-
let kind = `ContainerPage in
115-
let page = PageName.to_string page_name in
116-
mk kind page
117113
| `Page (parent, page_name) ->
118-
let parent = from_identifier (parent :> source) in
119-
let kind = `ContainerPage in
114+
let parent =
115+
match parent with
116+
| Some p -> Some (from_identifier (p :> source))
117+
| None -> None
118+
in
119+
let kind = `Page in
120120
let page = PageName.to_string page_name in
121-
mk ~parent kind page
121+
mk ?parent kind page
122122
| `LeafPage (parent, page_name) ->
123-
let parent = from_identifier (parent :> source) in
124-
let kind = `Page in
123+
let parent =
124+
match parent with
125+
| Some p -> Some (from_identifier (p :> source))
126+
| None -> None
127+
in
128+
let kind = `LeafPage in
125129
let page = PageName.to_string page_name in
126-
mk ~parent kind page
130+
mk ?parent kind page
127131
| `Module (parent, mod_name) ->
128132
let parent = from_identifier (parent :> source) in
129133
let kind = `Module in
@@ -242,15 +246,12 @@ module Anchor = struct
242246
| `Root _ as p ->
243247
let page = Path.from_identifier (p :> Path.source) in
244248
Ok { page; kind = `Module; anchor = "" }
245-
| `RootPage _ as p ->
246-
let page = Path.from_identifier (p :> Path.source) in
247-
Ok { page; kind = `ContainerPage; anchor = "" }
248249
| `Page _ as p ->
249250
let page = Path.from_identifier (p :> Path.source) in
250-
Ok { page; kind = `ContainerPage; anchor = "" }
251+
Ok { page; kind = `Page; anchor = "" }
251252
| `LeafPage _ as p ->
252253
let page = Path.from_identifier (p :> Path.source) in
253-
Ok { page; kind = `Page; anchor = "" }
254+
Ok { page; kind = `LeafPage; anchor = "" }
254255
(* For all these identifiers, page names and anchors are the same *)
255256
| (`Parameter _ | `Result _ | `ModuleType _ | `Class _ | `ClassType _) as p
256257
->

src/document/url.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ end
1414
module Path : sig
1515
type kind =
1616
[ `Module
17-
| `ContainerPage
1817
| `Page
18+
| `LeafPage
1919
| `ModuleType
2020
| `Argument
2121
| `Class

src/html/link.ml

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ module Path = struct
88

99
let segment_to_string (kind, name) =
1010
match kind with
11-
| `Module | `ContainerPage -> name
11+
| `Module | `Page -> name
1212
| _ -> Format.asprintf "%a-%s" Url.Path.pp_kind kind name
1313

14-
let is_leaf_page url = url.Url.Path.kind = `Page
14+
let is_leaf_page url = url.Url.Path.kind = `LeafPage
1515

1616
let get_dir_and_file url =
1717
let l = Url.Path.to_list url in
1818
let is_dir =
19-
if !flat then function `ContainerPage -> true | _ -> false
20-
else function `Page -> false | `File -> false | _ -> true
19+
if !flat then function `Page -> true | _ -> false
20+
else function `LeafPage -> false | `File -> false | _ -> true
2121
in
2222
let dir, file = Url.Path.split ~is_dir l in
2323
let dir = List.map segment_to_string dir in
2424
let file =
2525
match file with
2626
| [] -> "index.html"
27-
| [ (`Page, name) ] -> name ^ ".html"
27+
| [ (`LeafPage, name) ] -> name ^ ".html"
2828
| [ (`File, name) ] -> name
2929
| xs ->
3030
assert !flat;

src/latex/generator.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module Link = struct
2727

2828
let rec is_class_or_module_path (url : Odoc_document.Url.Path.t) =
2929
match url.kind with
30-
| `Module | `Page | `Class | `ContainerPage -> (
30+
| `Module | `LeafPage | `Class | `Page -> (
3131
match url.parent with
3232
| None -> true
3333
| Some url -> is_class_or_module_path url)
@@ -42,7 +42,7 @@ module Link = struct
4242
let get_dir_and_file url =
4343
let open Odoc_document in
4444
let l = Url.Path.to_list url in
45-
let is_dir = function `ContainerPage -> true | _ -> false in
45+
let is_dir = function `Page -> true | _ -> false in
4646
let dir, file = Url.Path.split ~is_dir l in
4747
let segment_to_string (_kind, name) = name in
4848
let dir = List.map segment_to_string dir in

src/manpage/link.ml

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,22 @@ let for_printing url = List.map snd @@ Url.Path.to_list url
44

55
let segment_to_string (kind, name) =
66
match kind with
7-
| `Module | `ContainerPage | `Page | `Class -> name
7+
| `Module | `Page | `LeafPage | `Class -> name
88
| _ -> Format.asprintf "%a-%s" Odoc_document.Url.Path.pp_kind kind name
99

1010
let as_filename (url : Url.Path.t) =
1111
let components = Url.Path.to_list url in
1212
let dir, path =
13-
Url.Path.split
14-
~is_dir:(function `ContainerPage -> true | _ -> false)
15-
components
13+
Url.Path.split ~is_dir:(function `Page -> true | _ -> false) components
1614
in
1715
let dir = List.map segment_to_string dir in
1816
let path = String.concat "." (List.map segment_to_string path) in
19-
Fpath.(v (String.concat dir_sep (dir @ [ path ])) + ".3o")
17+
let str_path = String.concat Fpath.dir_sep (dir @ [ path ]) in
18+
Fpath.(v str_path + ".3o")
2019

2120
let rec is_class_or_module_path (url : Url.Path.t) =
2221
match url.kind with
23-
| `Module | `Page | `ContainerPage | `Class -> (
22+
| `Module | `LeafPage | `Page | `Class -> (
2423
match url.parent with
2524
| None -> true
2625
| Some url -> is_class_or_module_path url)

src/model/paths.ml

-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ module Identifier = struct
2121

2222
let rec name_aux : t -> string = function
2323
| `Root (_, name) -> ModuleName.to_string name
24-
| `RootPage name -> PageName.to_string name
2524
| `Page (_, name) -> PageName.to_string name
2625
| `LeafPage (_, name) -> PageName.to_string name
2726
| `Module (_, name) -> ModuleName.to_string name
@@ -51,7 +50,6 @@ module Identifier = struct
5150
| `Result i -> label_parent_aux (i :> any)
5251
| `CoreType _ | `CoreException _ -> assert false
5352
| `Root _ as p -> (p :> label_parent)
54-
| `RootPage _ as p -> (p :> label_parent)
5553
| `Page _ as p -> (p :> label_parent)
5654
| `LeafPage _ as p -> (p :> label_parent)
5755
| `Module (p, _)

src/model/paths_types.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ open Names
22
(** {1 Paths} *)
33

44
module Identifier = struct
5-
type container_page =
6-
[ `RootPage of PageName.t | `Page of container_page * PageName.t ]
5+
type container_page = [ `Page of container_page option * PageName.t ]
76
(** @canonical Odoc_model.Paths.Identifier.ContainerPage.t *)
87

9-
type page = [ container_page | `LeafPage of container_page * PageName.t ]
8+
type page =
9+
[ container_page | `LeafPage of container_page option * PageName.t ]
1010
(** @canonical Odoc_model.Paths.Identifier.Page.t *)
1111

1212
type odoc_id = [ page | `Root of container_page option * ModuleName.t ]

src/model/root.ml

+7-5
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ let hash : t -> int = Hashtbl.hash
6464
let to_string t =
6565
let rec pp fmt (id : Paths.Identifier.OdocId.t) =
6666
match id with
67-
| `RootPage p -> Format.fprintf fmt "%a" Names.PageName.fmt p
68-
| `LeafPage (parent, name) | `Page (parent, name) ->
69-
Format.fprintf fmt "%a::%a" pp
70-
(parent :> Paths.Identifier.OdocId.t)
71-
Names.PageName.fmt name
67+
| `LeafPage (parent, name) | `Page (parent, name) -> (
68+
match parent with
69+
| Some p ->
70+
Format.fprintf fmt "%a::%a" pp
71+
(p :> Paths.Identifier.OdocId.t)
72+
Names.PageName.fmt name
73+
| None -> Format.fprintf fmt "%a" Names.PageName.fmt name)
7274
| `Root (Some parent, name) ->
7375
Format.fprintf fmt "%a::%a" pp
7476
(parent :> Paths.Identifier.OdocId.t)

src/model/semantics.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ let section_heading :
387387

388388
let validate_first_page_heading status ast_element =
389389
match status.parent_of_sections with
390-
| `RootPage name | `Page (_, name) | `LeafPage (_, name) -> (
390+
| `Page (_, name) | `LeafPage (_, name) -> (
391391
match ast_element with
392392
| { Location.value = `Heading (_, _, _); _ } -> ()
393393
| _invalid_ast_element ->
@@ -437,7 +437,7 @@ let top_level_block_elements status ast_elements =
437437
let top_heading_level =
438438
(* Non-page documents have a generated title. *)
439439
match status.parent_of_sections with
440-
| `RootPage _ | `Page _ | `LeafPage _ -> None
440+
| `Page _ | `LeafPage _ -> None
441441
| _parent_with_generated_title -> Some 0
442442
in
443443
traverse ~top_heading_level [] ast_elements

src/model_desc/paths_desc.ml

+4-5
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,16 @@ module General_paths = struct
6161
let rec identifier : Paths.Identifier.t t =
6262
Variant
6363
(function
64-
| `RootPage name -> C ("`RootPage", name, Names.pagename)
6564
| `Page (parent, name) ->
6665
C
6766
( "`Page",
68-
((parent :> id_t), name),
69-
Pair (identifier, Names.pagename) )
67+
((parent :> id_t option), name),
68+
Pair (Option identifier, Names.pagename) )
7069
| `LeafPage (parent, name) ->
7170
C
7271
( "`LeafPage",
73-
((parent :> id_t), name),
74-
Pair (identifier, Names.pagename) )
72+
((parent :> id_t option), name),
73+
Pair (Option identifier, Names.pagename) )
7574
| `Root (parent, name) ->
7675
C
7776
( "`Root",

src/odoc/bin/main.ml

+10-7
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ module Odoc_html = Make_renderer (struct
446446
~f:(fun acc seg ->
447447
Some
448448
Odoc_document.Url.Path.
449-
{ kind = `ContainerPage; parent = acc; name = seg })
449+
{ kind = `Page; parent = acc; name = seg })
450450
l ~init:None
451451
in
452452
`Ok
@@ -604,15 +604,18 @@ module Depends = struct
604604
module Link = struct
605605
let rec fmt_page pp page =
606606
match page with
607-
| `RootPage name ->
608-
Format.fprintf pp "%a" Odoc_model.Names.PageName.fmt name
609-
| `Page (parent, name) ->
610-
Format.fprintf pp "%a/%a" fmt_page parent
607+
| `Page (parent_opt, name) ->
608+
Format.fprintf pp "%a%a" fmt_parent_opt parent_opt
611609
Odoc_model.Names.PageName.fmt name
612-
| `LeafPage (parent, name) ->
613-
Format.fprintf pp "%a/%a" fmt_page parent
610+
| `LeafPage (parent_opt, name) ->
611+
Format.fprintf pp "%a%a" fmt_parent_opt parent_opt
614612
Odoc_model.Names.PageName.fmt name
615613

614+
and fmt_parent_opt pp parent_opt =
615+
match parent_opt with
616+
| None -> ()
617+
| Some p -> Format.fprintf pp "%a/" fmt_page p
618+
616619
let list_dependencies input_file =
617620
let open Or_error in
618621
Depends.for_rendering_step (Fs.Directory.of_string input_file)

src/odoc/compile.ml

+8-7
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let parent resolver parent_cli_spec =
5050
| _ -> Error (`Msg "Expecting page as parent")
5151
in
5252
let extract_parent = function
53-
| (`RootPage _ | `Page _) as container -> Ok container
53+
| `Page _ as container -> Ok container
5454
| _ -> Error (`Msg "Specified parent is not a parent of this file")
5555
in
5656
match parent_cli_spec with
@@ -59,7 +59,7 @@ let parent resolver parent_cli_spec =
5959
find_parent r >>= fun page ->
6060
extract_parent page.name >>= fun parent ->
6161
Ok (Explicit (parent, page.children))
62-
| CliPackage package -> Ok (Package (`RootPage (PageName.make_std package)))
62+
| CliPackage package -> Ok (Package (`Page (None, PageName.make_std package)))
6363
| CliNoparent -> Ok Noparent
6464

6565
let resolve_imports resolver imports =
@@ -158,12 +158,13 @@ let mld ~parent_spec ~output ~children ~warnings_options input =
158158
else Error (`Msg "Specified parent is not a parent of this file")
159159
in
160160
match (parent_spec, children) with
161-
| Explicit (p, cs), [] -> check cs @@ `LeafPage (p, page_name)
162-
| Explicit (p, cs), _ -> check cs @@ `Page (p, page_name)
163-
| Package parent, [] -> Ok (`LeafPage (parent, page_name))
161+
| Explicit (p, cs), [] -> check cs @@ `LeafPage (Some p, page_name)
162+
| Explicit (p, cs), _ -> check cs @@ `Page (Some p, page_name)
163+
| Package parent, [] -> Ok (`LeafPage (Some parent, page_name))
164164
| Package parent, _ ->
165-
Ok (`Page (parent, page_name)) (* This is a bit odd *)
166-
| Noparent, _ -> Ok (`RootPage page_name)
165+
Ok (`Page (Some parent, page_name)) (* This is a bit odd *)
166+
| Noparent, [] -> Ok (`LeafPage (None, page_name))
167+
| Noparent, _ -> Ok (`Page (None, page_name))
167168
in
168169
name >>= fun name ->
169170
let root =

src/odoc/html_fragment.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ open Or_error
33
let from_mld ~xref_base_uri ~resolver ~output ~warnings_options input =
44
(* Internal names, they don't have effect on the output. *)
55
let page_name = "__fragment_page__" in
6-
let id = `RootPage (Odoc_model.Names.PageName.make_std page_name) in
6+
let id = `Page (None, Odoc_model.Names.PageName.make_std page_name) in
77
let input_s = Fs.File.to_string input in
88
let digest = Digest.file input_s in
99
let root =

src/xref2/component.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ module Fmt = struct
11981198
Format.fprintf ppf "%a.%s" model_identifier
11991199
(p :> Odoc_model.Paths.Identifier.t)
12001200
(ExtensionName.to_string name)
1201-
| `Page (_, name) | `LeafPage (_, name) | `RootPage name ->
1201+
| `Page (_, name) | `LeafPage (_, name) ->
12021202
Format.fprintf ppf "%s" (PageName.to_string name)
12031203

12041204
and model_fragment ppf (f : Odoc_model.Paths.Fragment.t) =

0 commit comments

Comments
 (0)