package grace

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

Install

dune-project
 Dependency

Authors

Maintainers

Sources

grace-0.4.1.tbz
sha256=d49754224206de44855590848b3a5a6cc1d5c46cf99a4e5810ca3041d436a28e
sha512=2984b5a6284bf8bbd05419cf850c15c34bc19c19f0c8928b83cc1be1c0bfc84aafef6d992e7435c2f48ba361a6f3aab679abd02f0e6472361c8cec7d497bc405

Description

Added to opam-repository:

README

Grace πŸ’…

Grace is an OCaml πŸͺ library that includes a series of interfaces for building, reporting, and rendering beautiful compiler errors πŸ“œ.

We're still actively working on Grace to support more use cases and improving the quality of the rendering engine. Contributions are very welcome!

Features

  • πŸ“ Inline and multi-line error messages with associated priorities
  • πŸ“‚ Multi-file errors
  • βš™οΈ Configurable rendering (styling and character set)
  • πŸ’° Rich and compact error rendering
  • 🌈 Colored messages (thanks to Fmt's style) for ANSI terminals
  • πŸ’ͺ Written in OCaml
  • πŸ”  Unicode support
  • πŸ’― Error codes

Planned Features

  • LSP integration
  • Accessibility features (improved color options, narratable renderers)
  • HTML renderer

Installation

This library is available on opam. To install

opam install grace

Users of dune can then use this library by adding the appropriate libraries:

(library
 ...
 (libraries grace grace.ansi_renderer ...))

Usage

open! Grace

(* Grace provides a [Source] API for in-memory representations of sources/files. *)
let fizz : Source.t =
  `String
    { name = Some "fizz.ml"
    ; content =
        {|
let fizz n =
  match n mod 5, n mod 3 with
  | 0, 0 -> `Fizz_buzz
  | 0, _ -> `Fizz
  | _, 0 -> `Buzz
  | _, _ -> n
;;
|}
    }
;;

(* Grace provides support for error codes.

   Error codes are arbitrary types with an explicit [code_to_string] function 
   which converts the code into a short (googlable) error code. This allows 
   library users to inspect (and match on) certain types of diagnostics. *)
type code = Incompatible_types

let code_to_string = function
  | Incompatible_types -> "E001"
;;

(* Normally locations (ranges) would be taken from AST nodes, but for sake of
   this example we construct them directly. *)
let diagnostic =
  let range start stop =
    Range.create ~source:fizz (Byte_index.of_int start) (Byte_index.of_int stop)
  in
  Diagnostic.(
    createf
      ~labels:
        Label.
          [ primaryf
              ~range:(range 116 117)
              "expected `[> `Buzz | `Fizz | `Fizz_buzz]`, found `int`"
          ; secondaryf ~range:(range 17 117) "`match` cases have incompatible types"
          ; secondaryf ~range:(range 57 67) "this is found to be of type `[> `Fizz_buzz]`"
          ; secondaryf ~range:(range 80 85) "this is found to be of type `[> `Fizz]`"
          ; secondaryf ~range:(range 98 103) "this is found to be of type `[> `Buzz]`"
          ]
      ~code:Incompatible_types
      Error
      "`match` cases have incompatible types")
;;

let () =
  Format.printf
    "%a@."
    Grace_ansi_renderer.(pp_diagnostic ())
    diagnostic
;;

Authors and Acknowledgement

Authors:

  • Alistair O'Brien (@johnyob)

grace was heavily inspired by all the work on compiler diagnostics in the Rust ecosystem:

  • @brendanzab for the codespan crate which heavily influenced the design of grace's rendering engine.
  • ariadne (@zesterer) for pushing the boundary on diagnostic rendering.
  • rustc and @estebank's work on the state-of-the-art work on compiler diagnostics

License

This code is free, under the MIT license.

Dependencies (7)

  1. ppx_sexp_conv
  2. sexplib
  3. iter
  4. fmt >= "0.8.7"
  5. yojson >= "2.1.0"
  6. dune >= "3.4"
  7. ocaml >= "4.14.0"

Dev Dependencies (5)

  1. odoc with-doc
  2. ppx_jane with-test
  3. core_unix with-test
  4. core with-test
  5. dedent with-test

Optional Dependencies

None

Used by (1)

  1. slipshow >= "0.10.0"

Conflicts

None

Build status

Results of building grace with each compiler on check.ci.ocaml.org, run of against opam-repository 8a77e58. All results for this package.

Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to β€œAuthorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.

Version OCaml 4.11 OCaml 4.14 OCaml 5.2 OCaml 5.4 OCaml 5.5
0.4.1 (this version) n/a good good good good
  • good Package successfully built
  • partial One of the dependencies failed to build
  • bad Package failed to build
  • n/a Package is not available in this environment
  • internal Internal failure