package grace

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

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).
type 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).

val equal_reader : reader -> reader -> bool
val compare_reader : reader -> reader -> int
val hash_fold_reader : Base.Hash.state -> reader -> Base.Hash.state
val hash_reader : reader -> Base.Hash.hash_value
val sexp_of_reader : reader -> Sexplib0.Sexp.t
val reader_of_sexp : Sexplib0.Sexp.t -> reader
val 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.

type 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.

val equal_string_source : string_source -> string_source -> bool
val compare_string_source : string_source -> string_source -> int
val hash_fold_string_source : Base.Hash.state -> string_source -> Base.Hash.state
val hash_string_source : string_source -> Base.Hash.hash_value
val sexp_of_string_source : string_source -> Sexplib0.Sexp.t
val string_source_of_sexp : Sexplib0.Sexp.t -> string_source
type 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.

val equal : t -> t -> bool
val compare : t -> t -> int
include Ppx_hash_lib.Hashable.S with type t := t
val hash_fold_t : Base.Hash.state -> t -> Base.Hash.state
val hash : t -> Base.Hash.hash_value
val sexp_of_t : t -> Sexplib0.Sexp.t
val t_of_sexp : Sexplib0.Sexp.t -> t
val __t_of_sexp__ : Sexplib0.Sexp.t -> t
val name : t -> string option

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

val 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.