package ocp-ocamlres

  1. Overview
  2. Docs

Registration of (sub)formats for use from the command line

This file implements the interface between OCaml defintions of Format and SubFormat module instances and the command line interface of ocp-ocamlres.

Basically, it consists in pre-instanciating the formats:

  • with string valued resource trees as input where the strings are the raw contents as extracted from the files
  • with a proxy subformat, performing a dynamic dispatch of the subformat depending on file extensions

To associate the extensions with the subformats, it maintains an assiciative table to link the command line name of the subformat to the OCaml implementation (as a packed module).

Same is done with the main format names, and both tables can be extended to the tool can be extended from outside this module (by recompiling it with / dynlinking a module performing a (sub)format registration at toplevel)

Formats registry

module type Format = sig ... end

The type of format plug-ins. Differs from OCamlResFormats.Format since it is dedicated to be used by the command line tool. For this, the parameters are provided not as a data type but as a list of command line args that can mutate global references, which can then be read from the output function. This is because parameters come from the user, not the programmer. Also, the tool is dedicated to use with the filesystem, so the type of data is fixed to strings representing the raw encoding of data.

val register_format : string -> (module Format) -> unit

Register a new named format module or override one.

val find_format : string -> (module Format)

Find a format module from its name. May throw Not_found.

val formats : unit -> (module Format) Map.Make(String).t

Retrive the currently available formats

SubFormats registry

module type SubFormat = sig ... end

The type of subformat plug-ins

val register_subformat : string -> (module SubFormat) -> unit

Register a new named subformat module or override one.

val find_subformat : string -> (module SubFormat)

Find a subformat module from its name. May throw Not_found.

val subformats : unit -> (module SubFormat) Map.Make(String).t

Retrive the currently available subformats

Predefined Subformats

module Raw : SubFormat with type t = string

Registered under the name "raw".

module Int : SubFormat with type t = int

Registered under the name "int".

module Lines : SubFormat with type t = string list

Registered under the name "lines".

Predefined Formats

module PredefOptions : sig ... end

Predefined options that you can use in your own formats

Output subformat dispatching the output depending on file extensions and the command line options. To be polymorphic, the t type is a string containing the raw resource representation, and the from_raw method of the selected subformat is used at every operation. The SubFormat used is resolved using table PredefOptions.subformats.

val disclaimer : string

Disclaimer that you can use in your own formats

module OCaml : Format

Registered under the name "ocaml".

module Res : Format

Registered under the name "ocamlres".

module Variants : Format

Registered under the name "variants".

module Files : Format

Registered under the name "files".

OCaml

Innovation. Community. Security.