Library
Module
Module type
Parameter
Class
Class type
A KDL value.
`String
can be either a regular quoted string ("string"
) or a "raw" string (r#"raw string"#
).
Although the KDL spec does not differentiate integers and floats, a number is parsed as `Float
if it is written in the e
scientific notation or contains a .
, same as in OCaml.
If an integer is too large for the OCaml int
, the integer is parsed as `RawInt
instead of `Int
.
type annot_value = string option * value
An annotated value: opt_annot * value
. For example, (Some "u16", `Int 3201)
is an annot_value
.
type prop = string * annot_value
A KDL property is a key-value pair.
type node = {
name : string;
annot : string option;
args : annot_value list;
props : prop list;
children : node list;
}
A KDL node.
props
is an association list; the order of props
is unspecified.
type t = node list
A KDL document is a list of nodes.
Note: the positions count unicode code points, not bytes.
type error = string * error_loc
val show_error : error -> string
exception Parse_error of error
val from_string_exn : ?fname:string -> string -> t
Parse KDL from a channel.
val from_channel_exn : ?fname:string -> Stdlib.in_channel -> t
val of_string_exn : ?fname:string -> string -> t
Alias for from_string_exn
.
val node :
?annot:string ->
string ->
?args:annot_value list ->
?props:prop list ->
node list ->
node
node ?annot name ?args ?props children
creates a node
.
val arg : ?annot:string -> value -> annot_value
arg ?annot value
creates an argument.
val equal_annot_value : annot_value -> annot_value -> bool
val sexp_of_value : [< value ] -> Sexplib0.Sexp.t
val sexp_of_annot_value : annot_value -> Sexplib0.Sexp.t
val sexp_of_prop : prop -> Sexplib0.Sexp.t
val sexp_of_node : node -> Sexplib0.Sexp.t
val sexp_of_t : t -> Sexplib0.Sexp.t
indent
is a number of spaces used per indentation level. By default, indent
is set to 2
.
val pp_value : Stdlib.Format.formatter -> [< value ] -> unit
Pretty-print a value.
val pp_annot_value : Stdlib.Format.formatter -> annot_value -> unit
Pretty-print an annotated value.
val pp_prop : Stdlib.Format.formatter -> prop -> unit
Pretty-print a property.
val pp_node : Stdlib.Format.formatter -> node -> unit
Pretty-print a node using !indent
as the indentation width for children nodes.
val pp_node_compact : Stdlib.Format.formatter -> node -> unit
Same as pp_node
, but outputs the result in one line.
val pp : Stdlib.Format.formatter -> t -> unit
Pretty-print a list of nodes or a KDL document using !indent
as the indentation width for children nodes.
val pp_compact : Stdlib.Format.formatter -> t -> unit
Same as pp
, but outputs the result in one line.
val show : t -> string
Alias for to_string
.
KDL defines reserved type annotations, some of them are supported out of the box. An annotated value can be interpreted using the interpret
function. If the type annotation is unknown, `Other
is returned.
You can extend typed_value
with custom type annotations e.g. the following way:
type typed_value = [ Kdl.typed_value
| `Date of (* ... *) ]
let interpret : _ -> typed_value = function
| Some "date", value -> `Date ((* ... parse ISO 8601 date ... *))
| x -> Kdl.interpret x
val interpret : annot_value -> [> typed_value ]
val i8 : annot_value -> int option
Interpret a value with the "i8" type annotation as int
.
val i16 : annot_value -> int option
Interpret a value with the "i16" type annotation as int
.
val i32 : annot_value -> int32 option
Interpret a value with the "i32" type annotation as int32
.
val i64 : annot_value -> int64 option
Interpret a value with the "i64" type annotation as int64
.
val u8 : annot_value -> int option
Interpret a value with the "u8" type annotation as int
.
val u16 : annot_value -> int option
Interpret a value with the "u16" type annotation as int
.
val u32 : annot_value -> int32 option
Interpret a value with the "u32" type annotation as int32
.
val u64 : annot_value -> int64 option
Interpret a value with the "u64" type annotation as int64
.
val isize : annot_value -> nativeint option
Interpret a value with the "isize" type annotation as nativeint
.
val usize : annot_value -> nativeint option
Interpret a value with the "usize" type annotation as nativeint
.
val f32 : annot_value -> float option
Interpret a value with the "f32" type annotation as float
. This is currently identical to f64
.
val f64 : annot_value -> float option
Interpret a value with the "f64" type annotation as float
.
val base64 : annot_value -> bytes option
Interpret a value with the "base64" type annotation, decoding the base64 string into bytes
.
module L : sig ... end
Note: These lenses are mostly meant for getting, set
is generally inefficient.