package ocamlformat-lib

  1. Overview
  2. Docs
OCaml Code Formatter

Install

Dune Dependency

Authors

Maintainers

Sources

ocamlformat-0.27.0.tbz
sha256=ddbf484c076d08f99400ee84b790ec231f5c8fcbd5d3324a6400d5388e846d15
sha512=4d2a8965a7b7ad45f8f4e76c01cf38bfa68462b07dfa7bdb2db23bd3e3017b214e6780f036679fa8595dde4167a01d957e3af8837274320449014e306773f917

doc/src/ocamlformat-lib.odoc_parser/warning.ml.html

Source file warning.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
type t = { location : Loc.span; message : string }

let to_string e =
  let { location; message } = e in
  let location_string =
    if location.start.line = location.end_.line then
      Printf.sprintf "line %i, characters %i-%i" location.start.line
        location.start.column location.end_.column
    else
      Printf.sprintf "line %i, character %i to line %i, character %i"
        location.start.line location.start.column location.end_.line
        location.end_.column
  in
  Printf.sprintf "File \"%s\", %s:\n%s" location.file location_string message

let pp fmt v = Format.fprintf fmt "%s" (to_string v)

let kasprintf k fmt =
  Format.(kfprintf (fun _ -> k (flush_str_formatter ())) str_formatter fmt)

let kmake k ?suggestion =
  kasprintf (fun message ->
      match suggestion with
      | None -> k message
      | Some suggestion -> k (message ^ "\nSuggestion: " ^ suggestion))

let make ?suggestion format =
  let k message location = { location; message } in
  kmake k ?suggestion format
OCaml

Innovation. Community. Security.