From 613de424545844c18bcc051a2432670022e92fcb Mon Sep 17 00:00:00 2001 From: brendanzab Date: Mon, 11 Nov 2024 17:18:11 +1100 Subject: [PATCH] Install top-level printers with attribute As of ocaml-community/utop#269 utop automatically installs printers marked with the `[@@ocaml.toplevel_printer]` attribute. --- src/unsigned.mli | 2 +- top/dune | 7 ------- top/install_integer_printers.ml | 32 -------------------------------- top/install_integer_printers.mli | 1 - top/integer_printers.ml | 31 ------------------------------- top/integer_printers.mli | 21 --------------------- 6 files changed, 1 insertion(+), 93 deletions(-) delete mode 100644 top/dune delete mode 100644 top/install_integer_printers.ml delete mode 100644 top/install_integer_printers.mli delete mode 100644 top/integer_printers.ml delete mode 100644 top/integer_printers.mli diff --git a/src/unsigned.mli b/src/unsigned.mli index 12347ed3..c67771f1 100644 --- a/src/unsigned.mli +++ b/src/unsigned.mli @@ -136,7 +136,7 @@ module type S = sig (** Convert the given string to an unsigned integer. Returns [None] if the given string is not a valid representation of an unsigned integer. *) - val pp : Format.formatter -> t -> unit + val pp : Format.formatter -> t -> unit [@@ocaml.toplevel_printer] (** Output the result of {!to_string} on a formatter. *) val pp_hex : Format.formatter -> t -> unit diff --git a/top/dune b/top/dune deleted file mode 100644 index a187464b..00000000 --- a/top/dune +++ /dev/null @@ -1,7 +0,0 @@ -(library - (name integers_top) - (public_name integers.top) - (modes byte) - (wrapped false) - (synopsis "toplevel pretty printers") - (libraries integers compiler-libs)) diff --git a/top/install_integer_printers.ml b/top/install_integer_printers.ml deleted file mode 100644 index 2b8b3ef8..00000000 --- a/top/install_integer_printers.ml +++ /dev/null @@ -1,32 +0,0 @@ -(* Adapted from Anil Madhavapeddy's ocaml-uri package. *) - -let _ = Integer_printers.format_sint - -let printers = [ "Integer_printers.format_sint"; - "Integer_printers.format_long"; - "Integer_printers.format_llong"; - "Integer_printers.format_uchar"; - "Integer_printers.format_uint8"; - "Integer_printers.format_uint16"; - "Integer_printers.format_uint32"; - "Integer_printers.format_uint64"; - "Integer_printers.format_ushort"; - "Integer_printers.format_uint"; - "Integer_printers.format_ulong"; - "Integer_printers.format_ullong";] - -let eval_string - ?(print_outcome = false) ?(err_formatter = Format.err_formatter) str = - let lexbuf = Lexing.from_string str in - let phrase = !Toploop.parse_toplevel_phrase lexbuf in - Toploop.execute_phrase print_outcome err_formatter phrase - -let rec install_printers = function - | [] -> true - | printer :: printers -> - let cmd = Printf.sprintf "#install_printer %s;;" printer in - eval_string cmd && install_printers printers - -let () = - if not (install_printers printers) then - Format.eprintf "Problem installing integer-printers@." diff --git a/top/install_integer_printers.mli b/top/install_integer_printers.mli deleted file mode 100644 index 77719064..00000000 --- a/top/install_integer_printers.mli +++ /dev/null @@ -1 +0,0 @@ -(* This file is intentionally left almost blank. *) diff --git a/top/integer_printers.ml b/top/integer_printers.ml deleted file mode 100644 index dbdcc551..00000000 --- a/top/integer_printers.ml +++ /dev/null @@ -1,31 +0,0 @@ -(* - * Copyright (c) 2013 Jeremy Yallop. - * - * This file is distributed under the terms of the MIT License. - * See the file LICENSE for details. - *) - -let format_sint fmt v = - Format.fprintf fmt "" (Signed.SInt.to_string v) -let format_long fmt v = - Format.fprintf fmt "" (Signed.Long.to_string v) -let format_llong fmt v = - Format.fprintf fmt "" (Signed.LLong.to_string v) -let format_uchar fmt v = - Format.fprintf fmt "" (Unsigned.UChar.to_string v) -let format_uint8 fmt v = - Format.fprintf fmt "" (Unsigned.UInt8.to_string v) -let format_uint16 fmt v = - Format.fprintf fmt "" (Unsigned.UInt16.to_string v) -let format_uint32 fmt v = - Format.fprintf fmt "" (Unsigned.UInt32.to_string v) -let format_uint64 fmt v = - Format.fprintf fmt "" (Unsigned.UInt64.to_string v) -let format_ushort fmt v = - Format.fprintf fmt "" (Unsigned.UShort.to_string v) -let format_uint fmt v = - Format.fprintf fmt "" (Unsigned.UInt.to_string v) -let format_ulong fmt v = - Format.fprintf fmt "" (Unsigned.ULong.to_string v) -let format_ullong fmt v = - Format.fprintf fmt "" (Unsigned.ULLong.to_string v) diff --git a/top/integer_printers.mli b/top/integer_printers.mli deleted file mode 100644 index fff543de..00000000 --- a/top/integer_printers.mli +++ /dev/null @@ -1,21 +0,0 @@ -(* - * Copyright (c) 2013 Jeremy Yallop. - * - * This file is distributed under the terms of the MIT License. - * See the file LICENSE for details. - *) - -open Format - -val format_sint : formatter -> Signed.SInt.t -> unit -val format_long : formatter -> Signed.Long.t -> unit -val format_llong : formatter -> Signed.LLong.t -> unit -val format_uchar : formatter -> Unsigned.UChar.t -> unit -val format_uint8 : formatter -> Unsigned.UInt8.t -> unit -val format_uint16 : formatter -> Unsigned.UInt16.t -> unit -val format_uint32 : formatter -> Unsigned.UInt32.t -> unit -val format_uint64 : formatter -> Unsigned.UInt64.t -> unit -val format_ushort : formatter -> Unsigned.UShort.t -> unit -val format_uint : formatter -> Unsigned.UInt.t -> unit -val format_ulong : formatter -> Unsigned.ULong.t -> unit -val format_ullong : formatter -> Unsigned.ULLong.t -> unit