OCaml Library Collection
/

INI element metadata.

Metadata holds text location and layout information (whitespace and comments) for INI elements. When decoding with ~layout:true, this information is captured and can be used to preserve formatting when re-encoding.

Example: A value decoded from:

  port = 8080  # server port

would have ws_before = " ", ws_after = " ", and comment = Some "# server port".

type t

The type for element metadata.

val none : t

none is metadata with no information (no location, no whitespace).

val make : ?ws_before:string -> ?ws_after:string -> ?comment:string -> Textloc.t -> t

make ?ws_before ?ws_after ?comment textloc creates metadata.

  • ws_before is whitespace preceding the element.
  • ws_after is whitespace following the element.
  • comment is an associated comment (including the # or ;).
  • textloc is the source location.
val is_none : t -> bool

is_none m is true iff m has no text location.

val textloc : t -> Textloc.t

textloc m is the text location of m.

val ws_before : t -> string

ws_before m is whitespace that appeared before the element.

val ws_after : t -> string

ws_after m is whitespace that appeared after the element.

val comment : t -> string option

comment m is the comment associated with the element, if any. Includes the comment prefix (# or ;).

Functional updates

val with_textloc : t -> Textloc.t -> t

with_textloc m loc is m with text location loc.

val with_ws_before : t -> string -> t

with_ws_before m ws is m with ws_before set to ws.

val with_ws_after : t -> string -> t

with_ws_after m ws is m with ws_after set to ws.

val with_comment : t -> string option -> t

with_comment m c is m with comment set to c.

val clear_ws : t -> t

clear_ws m is m with whitespace cleared.

val clear_textloc : t -> t

clear_textloc m is m with textloc set to Textloc.none.

val copy_ws : t -> dst:t -> t

copy_ws src ~dst copies whitespace from src to dst.