DSL.Macros (dsl v0.1.2)

Copy Markdown View Source

Helpers for defining public macro wrappers around DSL scope modules.

Summary

Functions

Import public macro-definition helpers.

Defines a macro from a quoted template with an explicit caller-block yield.

Defines a block macro with start and finish calls.

Defines a macro that expands to a single call.

Build and escape caller source metadata for generated macro wrappers.

Expand variables in a quoted template with caller-provided AST bindings.

Replace yield() markers in a template with a caller block.

Functions

__using__(opts)

(macro)

Import public macro-definition helpers.

defaround(head, opts \\ [], list)

(macro)

Defines a macro from a quoted template with an explicit caller-block yield.

defaround project(name) do
  start_project(name)
  yield()
  finish_project()
end

Pass optional: true to also define a no-body form where yield() expands to nil.

defblock(head, opts \\ [], list)

(macro)

Defines a block macro with start and finish calls.

defblock project(name, opts \ []) do
  start MyScope.start_project(name, opts)
  finish MyScope.finish_project()
end

Pass source: true to make a source variable available to start and finish expressions. The generated macro uses DSL.Source.escape_caller/1.

defdirective(head, opts \\ [], list)

(macro)

Defines a macro that expands to a single call.

defdirective providers(providers) do
  MyScope.put_providers(providers)
end

escape_source(module, caller)

@spec escape_source(true | module(), Macro.Env.t()) :: Macro.t()

Build and escape caller source metadata for generated macro wrappers.

expand_template(template, bindings)

@spec expand_template(
  Macro.t(),
  keyword(Macro.t())
) :: Macro.t()

Expand variables in a quoted template with caller-provided AST bindings.

expand_yield(template, block)

@spec expand_yield(Macro.t(), Macro.t() | nil) :: Macro.t()

Replace yield() markers in a template with a caller block.