From c3ff187b3a0328cddf4623a750773117ea69cd13 Mon Sep 17 00:00:00 2001 From: Guillaume Petiot Date: Fri, 21 Jul 2023 16:25:34 +0100 Subject: [PATCH] voodoo-gen: Use Bos_setup.R (#112) --- src/voodoo-gen/dune | 2 +- src/voodoo-gen/main.ml | 12 +++--------- src/voodoo-gen/markdown.ml | 5 ++--- src/voodoo-gen/package_info.ml | 6 +++--- src/voodoo-gen/rendering.ml | 10 ++++------ src/voodoo-gen/search_index.ml | 5 +++-- 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/voodoo-gen/dune b/src/voodoo-gen/dune index 39bfbb9d..348f8976 100644 --- a/src/voodoo-gen/dune +++ b/src/voodoo-gen/dune @@ -2,4 +2,4 @@ (name main) (public_name voodoo-gen) (package voodoo-gen) - (libraries odoc.odoc omd bos yojson cmdliner voodoo_lib)) + (libraries odoc.odoc omd bos bos.setup yojson cmdliner voodoo_lib)) diff --git a/src/voodoo-gen/main.ml b/src/voodoo-gen/main.ml index eb067ac5..97fc83ba 100644 --- a/src/voodoo-gen/main.ml +++ b/src/voodoo-gen/main.ml @@ -1,5 +1,5 @@ open Cmdliner -module Result = Stdlib.Result +module Result = Bos_setup.R [@@@ocaml.warning "-3"] @@ -30,12 +30,6 @@ type files = { otherdocs : Fpath.t list; odocls : Fpath.t list } let empty = { otherdocs = []; odocls = [] } -let get_ok = function - | Result.Ok x -> x - | Error (`Msg m) -> - Format.eprintf "get_ok: Failure! msg=%s\n%!" m; - failwith "get_ok: Not OK" - let generate_pkgver output_dir name_filter version_filter = let linkedpath = Fpath.(v "linked") in match @@ -111,7 +105,7 @@ let generate_pkgver output_dir name_filter version_filter = in let paths = List.rev_map (Rendering.render ~output) files - |> List.rev_map get_ok |> List.flatten + |> List.rev_map Result.get_ok |> List.flatten in let foutput = Fpath.v (Odoc_odoc.Fs.Directory.to_string output_dir) @@ -124,7 +118,7 @@ let generate_pkgver output_dir name_filter version_filter = in Package_info.gen ~input:parent ~output:output_prefix paths; - Rendering.render_other ~parent ~otherdocs ~output |> get_ok; + Rendering.render_other ~parent ~otherdocs ~output |> Result.get_ok; let otherdocs = let init = Voodoo_serialize.Status.Otherdocs.empty in diff --git a/src/voodoo-gen/markdown.ml b/src/voodoo-gen/markdown.ml index faa40478..e6b040fe 100644 --- a/src/voodoo-gen/markdown.ml +++ b/src/voodoo-gen/markdown.ml @@ -1,8 +1,7 @@ (* Markdown renderer *) open Omd -open Result - -let ( >>= ) m f = match m with Ok x -> f x | Error y -> Error y +module Result = Bos_setup.R +open Result.Infix type intermediate = | Bl of Odoc_document.Types.Block.t diff --git a/src/voodoo-gen/package_info.ml b/src/voodoo-gen/package_info.ml index d993819a..9daceb94 100644 --- a/src/voodoo-gen/package_info.ml +++ b/src/voodoo-gen/package_info.ml @@ -1,4 +1,5 @@ -module Result = Stdlib.Result +module Result = Bos_setup.R +open Result.Infix module StringMap = Map.Make (String) let info_of_paths ~(info : string Voodoo_serialize.Package_info.t) paths = @@ -48,10 +49,9 @@ let info_of_paths ~(info : string Voodoo_serialize.Package_info.t) paths = info.libraries let gen ~input ~output paths = - Result.iter_error ignore + Result.ignore_error ~use:ignore @@ let input = Fpath.(parent input / "package.json" |> to_string) in - let ( >>= ) = Result.bind in let info = Voodoo_serialize.Package_info.of_yojson Voodoo_serialize.String_.of_yojson (Yojson.Safe.from_file input) diff --git a/src/voodoo-gen/rendering.ml b/src/voodoo-gen/rendering.ml index 740da0af..15f74687 100644 --- a/src/voodoo-gen/rendering.ml +++ b/src/voodoo-gen/rendering.ml @@ -1,7 +1,6 @@ open Odoc_odoc -module Result = Stdlib.Result - -let ( >>= ) = Result.bind +module Result = Bos_setup.R +open Result.Infix let document_of_odocl ~syntax input = let open Odoc_document in @@ -59,10 +58,9 @@ let docs_ids parent docs = let render ~output file = let open Odoc_document in - let ( let* ) = Result.bind in let f = Fs.File.of_string (Fpath.to_string file) in - let* document = document_of_odocl ~syntax:Renderer.OCaml f in - let* () = render_document ~output document in + document_of_odocl ~syntax:Renderer.OCaml f >>= fun document -> + render_document ~output document >>= fun () -> let urls = let rec get_subpages document = document diff --git a/src/voodoo-gen/search_index.ml b/src/voodoo-gen/search_index.ml index 7edc193f..6321f0f1 100644 --- a/src/voodoo-gen/search_index.ml +++ b/src/voodoo-gen/search_index.ml @@ -1,10 +1,11 @@ +module Result = Bos_setup.R +open Result.Infix + type entry = { id : Odoc_model.Paths.Identifier.Any.t; doc : Odoc_model.Comment.docs option; } -let ( >>= ) x f = match x with Ok v -> f v | Error _ as e -> e - module Generate = struct (** Get plain text doc-comment from a doc comment *)