Skip to content

Commit

Permalink
voodoo-gen: Use Bos_setup.R (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetiot authored Jul 21, 2023
1 parent 692daa4 commit c3ff187
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/voodoo-gen/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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))
12 changes: 3 additions & 9 deletions src/voodoo-gen/main.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
open Cmdliner
module Result = Stdlib.Result
module Result = Bos_setup.R

[@@@ocaml.warning "-3"]

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/voodoo-gen/markdown.ml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/voodoo-gen/package_info.ml
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions src/voodoo-gen/rendering.ml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/voodoo-gen/search_index.ml
Original file line number Diff line number Diff line change
@@ -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 *)

Expand Down

0 comments on commit c3ff187

Please sign in to comment.