package dkml-dune-dsl

  1. Overview
  2. Docs
Embedded DSL for Dune files to do syntax checking, auto-completion and generate dune.inc include files

Install

Dune Dependency

Authors

Maintainers

Sources

dkml-dune-dsl-0.1.3.tbz
sha256=11db13cbb29a6cd453f4f9d8138076624c2a55d78729ad6319cbab0239686ba5
sha512=d8410e8ba6327cfacd400423328f661b30bb6faa8d89340c6873563c0a03d62cdcf07cf2d52f1008818026804b0dfc2e108cd95e4c5a3127d06f260a3f9eaa3b

Description

dkml-dune-dsl lets you define Dune files in OCaml code with your favorite auto-completing IDE, compile it to an executable, and use it as a generator of your dune.inc files.

Published: 06 Jan 2024

README

dkml-dune-dsl

A mini-language (DSL) for Dune files embedded in OCaml that produces readable, valid Dune include files. The mini-language closely matches the structure of a regular Dune file, and because it is embedded in OCaml you get OCaml type-safety and the power of your favorite OCaml IDE as you write your Dune files.

The Dune DSL uses a tagless final design so your Dune DSL can be interpreted in a variety of ways that are independent of Dune itself. The standard dkml-dune-dsl-show interpreter allows all of the Dune string values (executable names, rule targets, etc.) to be parameterized from external JSON files. That lets you produce many similar executables, libraries or assets using the same Dune logic without repeating yourself DRY.

The documentation is at https://diskuv.github.io/dkml-dune-dsl/dkml-dune-dsl/index.html

Once installed (see the documentation) you will be able to write DSL expressions like:

open DkmlDuneDsl

module Build (I : Dune.SYM) = struct
  open I

  let res =
    [
      rule
        [
          target "{{{ name }}}.txt";
          action
            (with_stdout_to "%{target}"
              (echo [ "{{{ age }}}" ]));
        ];
    ]
end

that are run over the parameters in a JSON file:

{
  "param-sets": [
    {"name": "batman", "age": 39},
    {"name": "robin", "age": 24}
  ]
}

You can do also do aggregation or, if you are really adventurous, define your own interpreter. Even if you don't use parameterization you get things you take for granted with OCaml: type-safety, auto-complete and let constants.

Examples and Testing

The examples are available in the examples/ folder. Since Dune is the authority on whether Dune DSL is producing correct output, each example includes a test that checks the output of Dune.

For now the process is when a new bug is found then an existing example is expanded or a new example created.

Dependencies (2)

  1. ocaml >= "4.12.1"
  2. dune >= "2.9"

Dev Dependencies (1)

  1. odoc with-doc

Used by (1)

  1. dkml-dune-dsl-show >= "0.1.3"

Conflicts

None