Skip to content

Commit

Permalink
Merge pull request #489 from anmonteiro/anmonteiro/ocaml-5.3
Browse files Browse the repository at this point in the history
OCaml 5.3 support
  • Loading branch information
Octachron authored Oct 22, 2024
2 parents 384b309 + c7bab9e commit b490bac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/lib/uTop_compat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ let rec is_persistent_path = function
| Path.Pextra_ty (p, _) -> is_persistent_path p
#endif

#if OCAML_VERSION >= (5, 2, 0)
let inline_code =
#if OCAML_VERSION >= (5, 3, 0)
(Format_doc.compat Misc.Style.inline_code)
#else
Misc.Style.inline_code
#endif
#endif

let invalid_package_error_to_string err =
#if OCAML_VERSION >= (5, 2, 0)
(* NOTE: from https://github.com/ocaml/ocaml/blob/9b059b1e7a66e9d2f04d892a4de34c418cd96f69/parsing/parse.ml#L149 *)
Expand All @@ -78,11 +87,11 @@ let invalid_package_error_to_string err =
Format.fprintf ppf "private types are not supported"
| Not_with_type ->
Format.fprintf ppf "only %a constraints are supported"
Misc.Style.inline_code "with type t ="
inline_code "with type t ="
| Neither_identifier_nor_with_type ->
Format.fprintf ppf
"only module type identifier and %a constraints are supported"
Misc.Style.inline_code "with type"
inline_code "with type"
in
let buf = Buffer.create 128 in
let fmt = Format.formatter_of_buffer buf in
Expand Down Expand Up @@ -119,7 +128,7 @@ let find_in_path_normalized =
Misc.find_in_path_normalized
#else
Misc.find_in_path_uncap
#endif
#endif

let visible_paths_for_cmt_infos (cmt_infos: Cmt_format.cmt_infos) =
#if OCAML_VERSION >= (5, 2, 0)
Expand Down
15 changes: 15 additions & 0 deletions src/lib/uTop_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,13 @@ end
| Extra macros |
+-----------------------------------------------------------------+ *)

module Printtyp =
#if OCAML_VERSION >= (5, 3, 0)
Out_type
#else
Printtyp
#endif

let typeof sid =
let id = Parse.longident (Lexing.from_string sid) in
let env = !Toploop.toplevel_env in
Expand Down Expand Up @@ -1218,7 +1225,11 @@ let typeof sid =
| Some osig ->
let buf = Buffer.create 128 in
let pp = Format.formatter_of_buffer buf in
#if OCAML_VERSION >= (5, 3, 0)
Format.fprintf pp "%a" (Format_doc.compat !Toploop.print_out_signature) [osig];
#else
!Toploop.print_out_signature pp [osig];
#endif
Format.pp_print_newline pp ();
let str = Buffer.contents buf in
Lwt_main.run (Lazy.force LTerm.stdout >>= fun term -> render_out_phrase term str)
Expand Down Expand Up @@ -1584,6 +1595,10 @@ let () =
Location.register_error_of_exn
(function
| Envaux.Error err ->
#if OCAML_VERSION >= (5,3,0)
Some (Location.error_of_printer_file Envaux.report_error_doc err)
#else
Some (Location.error_of_printer_file Envaux.report_error err)
#endif
| _ -> None
)

0 comments on commit b490bac

Please sign in to comment.