package grace

  1. Overview
  2. Docs
A fancy diagnostics library that allows your compilers to exit with grace

Install

Dune Dependency

Authors

Maintainers

Sources

grace-0.2.0.tbz
sha256=821df54882c9253eac69f47bcf3a71ffdc61c77fdae42587c32aada5b56cfeae
sha512=007afa83251da3ddecd874e120ea89dce0253c387a64a5fece69069d3486ec5eb6c82d6bf0febaf23dd322bd9eaadc2f7882e33f05a2e1fa18a41294e7dc3ba1

doc/src/grace.ansi_renderer/import.ml.html

Source file import.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
include Core
include Grace
module Source_reader = Grace_source_reader
module Iter = IterLabels

module Format = struct
  include Format

  [%%if ocaml_version < (5, 2, 0)]

  let pp_max_margin = Int.max_value

  [%%else]

  let pp_max_margin = pp_infinity - 1

  [%%endif]
end

module Fmt = struct
  include Fmt

  let sp ppf () = Fmt.pf ppf " "
  let styled_multi style_multi t = List.fold_right style_multi ~init:t ~f:styled
  let with_style styles ppf t = styled_multi styles t ppf ()

  let repeat ~width t ppf x =
    for _ = 1 to width do
      t ppf x
    done
  ;;

  let sps n ppf x = repeat ~width:n sp ppf x
  let newline ppf () = Fmt.pf ppf "@."
end

module List = struct
  include List

  let concat_map_with_next t ~f =
    let rec loop = function
      | [] -> []
      | [ x ] -> f x ~next:None
      | x1 :: x2 :: t -> f x1 ~next:(Some x2) @ loop (x2 :: t)
    in
    loop t
  ;;

  let concat_map_with_next_and_prev t ~f =
    let rec loop t ~prev =
      match t with
      | [] -> []
      | [ x ] -> f x ~prev ~next:None
      | x1 :: x2 :: t ->
        let t' = f x1 ~prev ~next:(Some x2) in
        t' @ loop (x2 :: t) ~prev:(last t')
    in
    loop t ~prev:None
  ;;
end
OCaml

Innovation. Community. Security.