module Line:sig
..end
This module defines a Line.t
type, useful to represent line-oriented data
with structured content. A Line.t
can be thought of as a (extensible)
record. It has multiple fields storing the structured data, alongside the raw
content of the line, from which they are extracted.
Additionally, a line must contain at least the following fields (see
Mandatory fields for more details): raw
, show
, source
,
seq
, after
and before
.
type
label = ..
Field identifiers, or labels, are constructors of the Line.label
type, usually
of arity zero. Several labels are predefined in this module, and more can be
created by extending the Line.label
variant type.
For example, one can define labels Foo
and Bar
using type label += Foo
.
| Bar
val add_label_string : label -> string -> unit
Line.string_of_label
.val string_of_label : label -> string
Failure "string_of_label"
if such string has not been registered.module Fields:Hmap.S
with type 'a Key.info = label
Line.label
.
exception Field_not_found of label
Fields.get
if the queried key is not bound in the
map.typet =
Fields.t
A line is a heterogeneous map, with keys indexed by Line.label
, which must
contain the fields described in section Mandatory fields.
To create a custom line field foo
, one must first define a new label
(type label += Foo
), then create a corresponding map key (let foo =
).
Fields.Key.create Foo
val line : ?after:string -> ?before:string -> string -> t
after
is the trailing delimiter data associated with the line (default =
"\n"
); before
is the leading delimiter data associated with the line
(default = ""
).
val pp : Format.formatter -> t -> unit
In this section and the ones that follow, we define several line fields. We
do not directly expose the Line.label
s and Fields.Key.t
created, but
instead wrapper functions (accessors, updaters).
Fields being mandatory means that the accessors and updaters are guaranteed
to never raise Line.Field_not_found
.
val raw : t -> string
This should typically not change after a line is created; to change the
principal string value of a line, see Line.select
and Line.show
. (accessor,
required)
val set_raw : string -> t -> t
Line.raw
val show : t -> string
Unlike Line.raw
above, the value of Line.show
should reflect the data of concern
in a line. Use Line.set_show
or Line.select
to change the value returned by
Line.show
. When a line is passed to an external process, Line.show
is used to
get a string to send.
val set_show : string -> t -> t
Line.show
.val select : (t -> string) -> t -> t
Line.select sel ln
is equivalent to Line.set_show (sel ln) ln
.typesource =
[ `Command of string
| `Directory of string
| `File of string
| `None
| `Other of string
| `Process of Proc.execspec ]
val source : t -> source
val set_source : source -> t -> t
Line.source
val seq : t -> int
val set_seq : int -> t -> t
Line.seq
val after : t -> string
"\n"
)val set_after : string -> t -> t
Line.after
val before : t -> string
""
)val set_before : string -> t -> t
Line.before
Several structures that may be read from a line. If the raw contents of a
line matches a structure corresponding to module Foo
, Foo.create
will
parse it and add the corresponding fields to the line.
For every module below, accessors and updaters raise exception
Line.Field_not_found
when the corresponding field is not present in a line.
module Key_value:sig
..end
module Delim:sig
..end
module Passwd:sig
..end
module Group:sig
..end
module Stat:sig
..end
module Ps:sig
..end
module Fstab:sig
..end
module Mailcap:sig
..end