Skip to content

Commit 50946dc

Browse files
Julowadamchol
andauthored
Build on OCaml 5.3 (#2603)
Co-authored-by: Adam Cholewiński <theadamcholewinski@gmail.com>
1 parent 864d6a5 commit 50946dc

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ profile. This started with version 0.26.0.
6262
- Fix formatting of short `fun` expressions with the janestreet profile (#2593, @Julow)
6363
- Fix missing parentheses around a let in class expressions (#2599, @Julow)
6464
- Fix dropped attribute in `(module M : S [@attr])` (#2602, @Julow)
65+
- Build on OCaml 5.3 (#2603, @adamchol, @Julow)
6566

6667
### Changes
6768
- The location of attributes for structure items is now tracked and preserved. (#2247, @EmileTrotignon)

vendor/ocaml-common/location.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ let highlight_quote ppf
502502
Format.fprintf ppf "@}@,"
503503
| _ ->
504504
(* Multi-line error *)
505-
Misc.pp_two_columns ~sep:"|" ~max_lines ppf
505+
Format_doc.compat (Format_doc.pp_two_columns ~sep:"|" ~max_lines) ppf
506506
@@ List.map (fun (line, line_nb, line_start_cnum) ->
507507
let line = String.mapi (fun i car ->
508508
if ISet.mem iset ~pos:(line_start_cnum + i) then car else '.'

vendor/parser-shims/ocamlformat_parser_shims.ml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,32 @@ module Builtin_attributes = struct
220220

221221
let mark_payload_attrs_used _ = ()
222222
end
223+
224+
module Format_doc = struct
225+
open Format
226+
227+
type 'a t = formatter -> 'a -> unit
228+
229+
let compat t ppf x = t ppf x
230+
231+
let pp_two_columns ?(sep = "|") ?max_lines ppf (lines: (string * string) list) =
232+
let left_column_size =
233+
List.fold_left (fun acc (s, _) -> Int.max acc (String.length s)) 0 lines in
234+
let lines_nb = List.length lines in
235+
let ellipsed_first, ellipsed_last =
236+
match max_lines with
237+
| Some max_lines when lines_nb > max_lines ->
238+
let printed_lines = max_lines - 1 in (* the ellipsis uses one line *)
239+
let lines_before = printed_lines / 2 + printed_lines mod 2 in
240+
let lines_after = printed_lines / 2 in
241+
(lines_before, lines_nb - lines_after - 1)
242+
| _ -> (-1, -1)
243+
in
244+
fprintf ppf "@[<v>";
245+
List.iteri (fun k (line_l, line_r) ->
246+
if k = ellipsed_first then fprintf ppf "...@,";
247+
if ellipsed_first <= k && k <= ellipsed_last then ()
248+
else fprintf ppf "%*s %s %s@," left_column_size line_l sep line_r
249+
) lines;
250+
fprintf ppf "@]"
251+
end

vendor/parser-shims/ocamlformat_parser_shims.mli

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,9 @@ module Builtin_attributes : sig
9090

9191
val mark_payload_attrs_used : 'a -> unit
9292
end
93+
94+
module Format_doc : sig
95+
type 'a t
96+
val compat : 'a t -> Format.formatter -> 'a -> unit
97+
val pp_two_columns : ?sep : string -> ?max_lines:int -> (string * string) list t
98+
end

0 commit comments

Comments
 (0)