Skip to content

Commit

Permalink
Tree: rename entry to node
Browse files Browse the repository at this point in the history
  • Loading branch information
panglesd committed Oct 18, 2024
1 parent aa6ad0f commit 967eab9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 40 deletions.
10 changes: 5 additions & 5 deletions src/document/sidebar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ end = struct
| _ -> None
in
let root_entry =
match tree.Tree.entry with
match tree.Tree.node with
| Some v -> convert v
| None -> block (Block.Inline [ inline (Text "root") ])
in
{
Tree.entry = root_entry;
Tree.node = root_entry;
children = Tree.filter_map_f fun_ tree.children;
}
in
let rec block_of_block_tree { Tree.entry = name; children = content } =
let rec block_of_block_tree { Tree.node = name; children = content } =
let content =
match content with
| [] -> []
Expand All @@ -96,7 +96,7 @@ end = struct
let block_tree = block_tree_of_t current_url tree in
block_of_block_tree block_tree

let of_skeleton ({ entry; children } : Odoc_index.Entry.t Tree.t) =
let of_skeleton ({ node = entry; children } : Odoc_index.Entry.t Tree.t) =
let map_entry entry =
let stop_before =
match entry.Odoc_index.Entry.kind with
Expand Down Expand Up @@ -124,7 +124,7 @@ end = struct
in
let entry = map_entry entry in
let children = Tree.filter_map_f fun_ children in
{ Tree.entry; children }
{ Tree.node = entry; children }
end

type pages = { name : string; pages : Toc.t }
Expand Down
12 changes: 6 additions & 6 deletions src/index/skeleton.ml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ let rec unit (u : Compilation_unit.t) =
| Pack _ -> []
| Module m -> signature (u.id :> Identifier.LabelParent.t) m
in
{ Tree.entry; children }
{ Tree.node = entry; children }

and signature id (s : Signature.t) =
List.concat_map ~f:(signature_item (id :> Identifier.LabelParent.t)) s.items
Expand Down Expand Up @@ -153,7 +153,7 @@ and module_ id m =
| Alias (_, Some s_e) -> simple_expansion id s_e
| ModuleType mte -> module_type_expr id mte
in
[ { Tree.entry; children } ]
[ { Tree.node = entry; children } ]

and module_type id mt =
if_non_hidden mt.id @@ fun () ->
Expand All @@ -163,7 +163,7 @@ and module_type id mt =
| None -> []
| Some mt_expr -> module_type_expr id mt_expr
in
[ { Tree.entry; children } ]
[ { Tree.node = entry; children } ]

and type_decl td =
if_non_hidden td.id @@ fun () ->
Expand All @@ -176,7 +176,7 @@ and type_decl td =
| Some (Record fl) -> List.concat_map ~f:(field td.id td.equation.params) fl
| Some Extensible -> []
in
[ { Tree.entry; children } ]
[ { Tree.node = entry; children } ]

and constructor type_id params c =
let entry = Entry.of_constructor type_id params c in
Expand Down Expand Up @@ -206,15 +206,15 @@ and class_ id cl =
| None -> []
| Some cl_signature -> class_signature id cl_signature
in
[ { Tree.entry; children } ]
[ { Tree.node = entry; children } ]

and class_type id ct =
if_non_hidden ct.id @@ fun () ->
let entry = Entry.of_class_type ct in
let children =
match ct.expansion with None -> [] | Some cs -> class_signature id cs
in
[ { Tree.entry; children } ]
[ { Tree.node = entry; children } ]

and include_ id inc = signature id inc.expansion.content

Expand Down
12 changes: 2 additions & 10 deletions src/model/sidebar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,15 @@ module PageToc = struct
unordered
in
let contents = ordered @ unordered |> List.map snd in
{ Tree.entry = index; children = contents }
{ Tree.node = index; children = contents }

let rec remove_common_root (v : t) =
match v with
| { Tree.children = [ v ]; entry = None } -> remove_common_root v
| { Tree.children = [ v ]; node = None } -> remove_common_root v
| _ -> v

let of_list l =
let dir = empty_t None in
List.iter (add dir) l;
t_of_in_progress dir |> remove_common_root
end

(* type toc = PageToc.t *)

(* type library = { name : string; units : Paths.Identifier.RootModule.t list } *)

(* type page_hierarchy = { hierarchy_name : string; pages : toc } *)

(* type t = { pages : page_hierarchy list; libraries : library list } *)
6 changes: 0 additions & 6 deletions src/model/sidebar.mli
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,3 @@ module PageToc : sig
(** Uses the convention that the [index] children passes its payload to the
container directory to output a payload *)
end

(* type library = { name : string; units : Id.RootModule.t list } *)

(* type page_hierarchy = { hierarchy_name : string; pages : PageToc.t } *)

(* type t = { pages : page_hierarchy list; libraries : library list } *)
26 changes: 13 additions & 13 deletions src/utils/tree.ml
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
type 'a t = { entry : 'a; children : 'a forest }
type 'a t = { node : 'a; children : 'a forest }
and 'a forest = 'a t list

let leaf entry = { entry; children = [] }
let leaf node = { node; children = [] }

let rec fold_t fun_ acc { entry; children } =
let acc = fun_ acc entry in
let rec fold_t fun_ acc { node; children } =
let acc = fun_ acc node in
fold_f fun_ acc children

and fold_f fun_ acc f = List.fold_left (fold_t fun_) acc f

let rec iter_t fun_ { entry; children } =
let () = fun_ entry in
let rec iter_t fun_ { node; children } =
let () = fun_ node in
iter_f fun_ children

and iter_f fun_ f = List.iter (iter_t fun_) f

let rec map_t fun_ { entry; children } =
let entry = fun_ entry in
let rec map_t fun_ { node; children } =
let node = fun_ node in
let children = map_f fun_ children in
{ entry; children }
{ node; children }

and map_f fun_ f = List.map (map_t fun_) f

let rec filter_map_t fun_ { entry; children } =
match fun_ entry with
let rec filter_map_t fun_ { node; children } =
match fun_ node with
| None -> None
| Some entry ->
| Some node ->
let children = filter_map_f fun_ children in
Some { entry; children }
Some { node; children }

and filter_map_f fun_ f = List.filter_map (filter_map_t fun_) f

0 comments on commit 967eab9

Please sign in to comment.