package grace

  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

doc/grace/Grace/Source/index.html

Module Grace.SourceSource

Source is a file-like abstraction.

Grace provides the abstraction of a file called a 'source'.

There are several benefits with providing a in-memory abstraction of a sources:

  1. Virtual files: It is often useful to invent temporary files (e.g. test input, command line input, REPL input). By providing a in-memory abstraction, Grace provides the ability to create virtual files.
  1. Caching: Caching sources is useful in many situations (e.g. LSP semantic analysis, reporting multiple errors in a single file in a diagnostic reporter, etc).
Sourcemodule Reader : sig ... end
Sourcetype string_source = {
  1. name : string option;
    (*

    The name of a string source. The diagnostic render can use the name of a string source in place of a file path.

    *)
  2. content : string;
    (*

    The content of a string source

    *)
}

An in-memory string source.

Sourceval sexp_of_string_source : string_source -> Sexplib0.Sexp.t
Sourceval string_source_of_sexp : Sexplib0.Sexp.t -> string_source
Sourcetype t = [
  1. | `File of string
    (*

    A file source specified by its filename.

    *)
  2. | `String of string_source
    (*

    A in-memory string source.

    *)
  3. | `Reader of Reader.t
    (*

    A reader-backed source.

    *)
]

The type of sources.

Sourceval sexp_of_t : t -> Sexplib0.Sexp.t
Sourceval t_of_sexp : Sexplib0.Sexp.t -> t
Sourceval __t_of_sexp__ : Sexplib0.Sexp.t -> t
include Grace_std.Comparable.S with type t := t
Sourceval (>=) : t -> t -> bool
Sourceval (<=) : t -> t -> bool
Sourceval (>) : t -> t -> bool
Sourceval (<) : t -> t -> bool
Sourceval (=) : t -> t -> bool
Sourceval (<>) : t -> t -> bool
Sourceval compare : t -> t -> int
Sourceval equal : t -> t -> bool
Sourceval min : t -> t -> t
Sourceval max : t -> t -> t
Sourceval name : t -> string option

name src returns the name of the source if it exists.

Sourceval length : t -> int

length src returns the length or size in bytes of src. Interpreted as a byte_index, this is known as the end-of-source position.

For `File sources:

  • raises Sys_error

    if the file cannot be opened (e.g., file does not exist, permission denied, etc.), or if obtaining the file length fails (e.g., from lseek failures, file system errors, etc.).

  • raises Invalid_argument

    if the file size exceeds the maximum value that can be represented by an OCaml 63-bit integer (Int.max_value).

For other source types (`String, `Reader), this function does not raise exceptions.