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/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.
  2. 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).
Sourcetype reader = {
  1. id : int;
    (*

    The unique identifier of the reader. Equality, comparison, hashing are all performed on this identifier.

    *)
  2. name : string option;
    (*

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

    *)
  3. length : int;
    (*

    The length (in bytes) of the source.

    *)
  4. unsafe_get : int -> char;
    (*

    unsafe_get i reads the ith byte without performing bounds checks.

    *)
}

A reader denotes an arbitrary byte source (potentially backed by a file, buffer, socket, etc).

Sourceval equal_reader : reader -> reader -> bool
Sourceval compare_reader : reader -> reader -> int
Sourceval sexp_of_reader : reader -> Sexplib0.Sexp.t
Sourceval reader_of_sexp : Sexplib0.Sexp.t -> reader
Sourceval reader_name : reader -> string

reader_name reader returns the name of the reader. If reader.name is None, then identifier reader.id (converted to a string) is returned.

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 equal_string_source : string_source -> string_source -> bool
Sourceval compare_string_source : string_source -> string_source -> int
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
    (*

    A reader-backed source.

    *)
]

The type of sources.

Sourceval equal : t -> t -> bool
Sourceval compare : t -> t -> int
include Ppx_hash_lib.Hashable.S with type t := t
Sourceval hash_fold_t : Base.Hash.state -> t -> Base.Hash.state
Sourceval sexp_of_t : t -> Sexplib0.Sexp.t
Sourceval t_of_sexp : Sexplib0.Sexp.t -> t
Sourceval __t_of_sexp__ : Sexplib0.Sexp.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.

  • raises Invalid_argument

    if the file size is larger than an OCaml 63-bit integer.

OCaml

Innovation. Community. Security.