My aggregated monorepo of OCaml code, automaintained
at main 49 lines 1.4 kB view raw
1type t = { raw : string; parsed : Odoc_parser.t } 2 3type meta = { 4 libs : string list; [@default []] 5 html_scripts : string list; [@default []] 6 other_config : Yojson.Safe.t; [@default `Null] 7} 8[@@deriving yojson] 9 10let parse_mld mld_file = 11 let text = In_channel.(with_open_bin mld_file input_all) in 12 let location = 13 { Lexing.pos_fname = mld_file; pos_lnum = 1; pos_bol = 0; pos_cnum = 0 } 14 in 15 { raw = text; parsed = Odoc_parser.parse_comment ~location ~text } 16 17let meta_of_parsed parsed = 18 let meta_block = 19 List.filter_map 20 (fun block -> 21 let open Odoc_parser in 22 match block with 23 | { Loc.value = `Code_block c; _ } -> ( 24 match c.Ast.meta with 25 | None -> None 26 | Some m -> 27 if m.Ast.language.value = "meta" then Some c.content.value 28 else None) 29 | _ -> None) 30 (Odoc_parser.ast parsed) 31 in 32 let meta = 33 match meta_block with 34 | [] -> None 35 | x :: _ :: _ -> 36 Format.eprintf 37 "Warning, more than one meta block found. Ignoring all but the first."; 38 Some x 39 | [ meta ] -> Some meta 40 in 41 match meta with 42 | None -> None 43 | Some meta -> 44 let y = Yojson.Safe.from_string meta in 45 Some (meta_of_yojson y) 46 47let meta_of_mld mld_file = 48 let { parsed; _ } = parse_mld mld_file in 49 meta_of_parsed parsed