package ocp-ocamlres

  1. Overview
  2. Docs

The type of subformats, as passed to format functors.

This is basically an abstract type equipped with the functions that work on it as required by the formats. This type is the intermediate representation of resources at generation time. It can be the same as the run-time type of the resources, but is not necessarily so. For instance, a subformat could parse a CSV file using a CSV library at generation time but produce OCaml arrays or records as output. See Int for a simple sample instance.

All functions take two extra parameters specifying the path and data of the processed resource. They are added for building decorator / dispatch subformats and should be ignored for most formats.

type t

The generation-time intermediate representation of data.

val from_raw : OCamlRes.Path.t -> string -> t

A parser as used by the scanner to obtain the in-memory resources from files.

val to_raw : OCamlRes.Path.t -> t -> string

A dumper to reconstitute the files from the in-memory resources.

val pprint : OCamlRes.Path.t -> t -> PPrint.document

Takes the path to the resource in the resource tree, and its value to pretty print. Returns the OCaml representation of the value.

val pprint_header : OCamlRes.Path.t -> t -> PPrint.document option

Provides an optional piece of OCaml code to put before the resource store definition, for instance a type definition.

Provides an optional piece of OCaml code to put after the resource store definition, for instance a type definition.

val name : OCamlRes.Path.t -> t -> string

A name used to identify the subformat.

val type_name : OCamlRes.Path.t -> t -> string

The run-time OCaml type name (that describes the type of values generated by pprint). Used to annotate the generated source where needed. The common usecase is when this function returns the same type as the static t type.

val mod_name : OCamlRes.Path.t -> t -> string

The name of the subformat module at run-time. If the static type t is the same as the runtime type returned by type_abbrv, this is simply the path to the module used for generation.