Skip to content

Commit

Permalink
Explicitly construct ast_builder floating comments
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Ferris <[email protected]>
  • Loading branch information
patricoferris committed Aug 31, 2024
1 parent 011ddf3 commit 860753d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/gen/gen_ast_builder.ml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,26 @@ let dump fn ~ext printer x =
Format.fprintf ppf "%a@." printer x;
close_out oc

let floating_comment s =
let doc =
PStr
[
{
pstr_desc =
Pstr_eval
( {
pexp_desc = Pexp_constant (Pconst_string (s, loc, None));
pexp_loc = loc;
pexp_loc_stack = [];
pexp_attributes = [];
},
[] );
pstr_loc = loc;
};
]
in
Sig.attribute (Attr.mk { txt = "ocaml.text"; loc } doc)

let generate filename =
(* let fn = Misc.find_in_path_uncap !Config.load_path (unit ^ ".cmi") in*)
let types = get_types ~filename in
Expand Down Expand Up @@ -320,7 +340,7 @@ let generate filename =
Bytes.set bs 0 (Char.uppercase_ascii @@ Bytes.get bs 0);
String.concat ~sep:" " (Bytes.to_string bs :: rest)
in
(M.sigi "(** {2 %s} *)" label :: items) @ acc)
(floating_comment (Format.asprintf "{2 %s}" label) :: items) @ acc)
(mod_sig_items located) []
in
let items =
Expand Down
2 changes: 1 addition & 1 deletion src/gen/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ module M = struct
(fun s ->
match Parse.interface (Lexing.from_string s) with
| [ x ] -> x
| _ -> assert false)
| _ -> failwith ("Failed to parse: " ^ s))
fmt
end

Expand Down

0 comments on commit 860753d

Please sign in to comment.