From 203c212bcc2c29915c84a4c96b16f29e626e9b3e Mon Sep 17 00:00:00 2001 From: Benjamin Canou Date: Fri, 26 Oct 2018 12:05:11 +0200 Subject: [PATCH] Micheline: fix printer for code that exceeds 80 columns --- src/lib_micheline/micheline_printer.ml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib_micheline/micheline_printer.ml b/src/lib_micheline/micheline_printer.ml index fab828571..eb2b0176b 100644 --- a/src/lib_micheline/micheline_printer.ml +++ b/src/lib_micheline/micheline_printer.ml @@ -165,8 +165,19 @@ and print_expr ppf = function Format.fprintf ppf "(%a)" print_expr_unwrapped expr | expr -> print_expr_unwrapped ppf expr +let with_unbounded_formatter ppf f x = + let buf = Buffer.create 10000 in + let sppf = Format.formatter_of_buffer buf in + Format.pp_set_margin sppf 199999 ; + Format.pp_set_max_indent sppf 99999 ; + Format.pp_set_max_boxes sppf 99999 ; + f sppf x ; + Format.fprintf sppf "%!" ; + let lines = String.split_on_char '\n' (Buffer.contents buf) in + Format.pp_print_list ~pp_sep:Format.pp_force_newline Format.pp_print_string ppf lines + let print_expr_unwrapped ppf expr = - print_expr_unwrapped ppf (preformat expr) + with_unbounded_formatter ppf print_expr_unwrapped (preformat expr) let print_expr ppf expr = - print_expr ppf (preformat expr) + with_unbounded_formatter ppf print_expr (preformat expr)