Diesel.Package behaviour (diesel v0.1.0)
Packages extend DSLs by providing new tags.
Optionally, packages can also specify how these tags should be compiled, in order to form a new definition that can then be consumed by code generators.
Usage:
defmodule Latex.Dsl.Music do
use Diesel.Package,
tags: [
:music,
:instrument,
:meter
]
@impl true
def compiler do
quote do
def compile({:music, attrs, children}, ctx) do
atttrs = Keyword.put_new(attrs, :indent, "10mm")
children = compile(children, ctx)
{:music, attrs, children}
end
end
end
end
The code returned by each package via the compiler/1
function will be injected into the Dsl.
The Diesel.Dsl
macro provides with a default implementation for the compile/2
callback, so that you can conveniently traverse the definition tree.
Summary
Callbacks
@callback compiler() :: Macro.t()
Link to this callback
tags()
@callback tags() :: [atom()]