package kdl
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=84b37a3a61d2fe5fc7f8076af664e94257993db8662ce4218555ff0a9891424c
sha512=3a165f895f600c9a277f85f6530ec5edb6e4ff550de26d65979bff6caeb0b74f59e38a908a2b82112ffe7220deec4118fb38f32f816f5cad4fad5b8a0a1f6e25
doc/kdl/Kdl/index.html
Module KdlSource
The definition of a KDL document
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.
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.
Parsing
Note: the positions count unicode code points, not bytes.
Parse KDL from a channel.
Helpers
val node :
?annot:string ->
string ->
?args:annot_value list ->
?props:prop list ->
node list ->
nodenode ?annot name ?args ?props children creates a node.
arg ?annot value creates an argument.
Equivalence
Sexp conversions
Pretty-printing
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.
Type annotations
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 xInterpret 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.