package kdl

  1. Overview
  2. Docs
An implementation of the KDL document laguage

Install

Dune Dependency

Authors

Maintainers

Sources

v0.1.0.tar.gz
sha256=84b37a3a61d2fe5fc7f8076af664e94257993db8662ce4218555ff0a9891424c
sha512=3a165f895f600c9a277f85f6530ec5edb6e4ff550de26d65979bff6caeb0b74f59e38a908a2b82112ffe7220deec4118fb38f32f816f5cad4fad5b8a0a1f6e25

Description

README

ocaml-kdl  

An OCaml implementation of the KDL 1.0 document language.

Features

  • [x] Parsing

  • [x] Pretty-printing

  • [x] Lenses

  • [ ] The KDL Query Language

  • [ ] The KDL Schema Language

  • [ ] Preserve formatting when editing

Usage

Example:

# let kdl = Kdl.from_string {|
    contents {
      section "First section" {
        paragraph "This is the first paragraph"
        paragraph "This is the second paragraph"
      }
    }
  |}
val kdl : (Kdl.t, Kdl.error) result = Ok
 [{Kdl.name = "contents"; annot = None; args = []; props = [];
   children =
    [{Kdl.name = "section"; annot = None;
      args = [(None, `String "First section")]; props = [];
      children =
       [{Kdl.name = "paragraph"; annot = None;
         args = [(None, `String "This is the first paragraph")]; props = [];
         children = []};
        {Kdl.name = "paragraph"; annot = None;
         args = [(None, `String "This is the second paragraph")]; props = [];
         children = []}]}]}]

Convert to a sexp-expression:

# Kdl.sexp_of_t kdl |> Sexplib0.Sexp.to_string_hum |> print_endline
(contents
 (children
  (section (string "First section")
   (children (paragraph (string "This is the first paragraph"))
    (paragraph (string "This is the second paragraph"))))))

Pretty-print the KDL document back:

# Kdl.to_string kdl |> print_endline
contents {
  section "First section" {
    paragraph "This is the first paragraph"
    paragraph "This is the second paragraph"
  }
}

Similar to to.ml, ocaml-kdl provides lenses. The lenses can be composed using |-- or //:

# let open Kdl.L in
  kdl.@(top // child "section" // child_nth 1 // arg 0 // string_value)
- : string option = Some "This is the second paragraph"

Additionaly, type-annotated values can be interpreted:

# let parsed = Kdl.from_string_exn "- (u8)220"
# Kdl.interpret @@ get_exn parsed (node "-" // arg 0)
- : Kdl.typed_value = `U8 220

For the full list of available functions, see the mli file.

Dependencies (6)

  1. sexplib0
  2. sedlex >= "2.3"
  3. menhirLib
  4. menhir
  5. dune >= "3.0"
  6. ocaml >= "4.08"

Dev Dependencies (2)

  1. odoc with-doc
  2. ppx_expect with-test

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.