Page
Library
Module
Module type
Parameter
Class
Class type
Source
Kdl
SourceA 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
.
An annotated value: opt_annot * value
. For example, (Some "u16", `Int 3201)
is an 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.
Note: the positions count unicode code points, not bytes.
Parse KDL from a channel.
val node :
?annot:string ->
string ->
?args:annot_value list ->
?props:prop list ->
node list ->
node
node ?annot name ?args ?props children
creates a node
.
arg ?annot value
creates an argument.
indent
is a number of spaces used per indentation level. By default, indent
is set to 2
.
Pretty-print a value.
Pretty-print an annotated value.
Pretty-print a property.
Pretty-print a node using !indent
as the indentation width for children nodes.
Same as pp_node
, but outputs the result in one line.
Pretty-print a list of nodes or a KDL document using !indent
as the indentation width for children nodes.
Same as pp
, but outputs the result in one line.
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
Interpret a value with the "i8" type annotation as int
.
Interpret a value with the "i16" type annotation as int
.
Interpret a value with the "i32" type annotation as int32
.
Interpret a value with the "i64" type annotation as int64
.
Interpret a value with the "u8" type annotation as int
.
Interpret a value with the "u16" type annotation as int
.
Interpret a value with the "u32" type annotation as int32
.
Interpret a value with the "u64" type annotation as int64
.
Interpret a value with the "isize" type annotation as nativeint
.
Interpret a value with the "usize" type annotation as nativeint
.
Interpret a value with the "f32" type annotation as float
. This is currently identical to f64
.
Interpret a value with the "f64" type annotation as float
.
Interpret a value with the "base64" type annotation, decoding the base64 string into bytes
.