Module Yaml

A minimal YAML reader and writer.

The supported subset is the one people hand-write in configuration files: block mappings and sequences, inline flow collections ([1, 2] and {a: b}), plain and quoted scalars, and comments. Block scalars (| and >), anchors, aliases, tags and multi-document streams are rejected with an explicit error, and flow collections have to fit on a single line.

type t =
  1. | Null
    (*

    the null value, written null or ~

    *)
  2. | Bool of bool
  3. | Float of float
    (*

    any number, integers included

    *)
  4. | String of string
  5. | List of t list
    (*

    a sequence, e.g. - 1

    *)
  6. | Assoc of (string * t) list
    (*

    a mapping, e.g. a: 1; entries are kept in the order they occur and duplicate keys are preserved

    *)

A YAML value.

val of_string : string -> (t, string) Stdlib.result

Parse a YAML document. On failure, the message is prefixed with the line at which the error was detected.

val of_file : string -> (t, string) Stdlib.result

Parse the YAML document contained in a file. Raises Sys_error if the file cannot be read.

val to_string : t -> string

Print a YAML document, using block style and two-space indentation. The result always ends with a newline and can be read back with of_string: of_string (to_string v) = Ok v for every v.

val to_file : string -> t -> unit

Write a YAML document to a file, as printed by to_string. Raises Sys_error if the file cannot be written.