Fledex.Utils.Dsl (fledex v0.7.0)

View Source

The module is only inteded to be used by the Fledex module.

It's a set of helper functions to create the DSL. A lot of functions are workign on the AST (abstract syntax tree) level.

Summary

Functions

This function applies an effect to some configurations

This function takes an ast function block and adds an argument to the function. This is different from ast_add_argument_to_func_if_missing/1 that it does not expect there to be an arugment and therefore will raise an ArgumentError if it does find one.

This function takes an AST block of a function, checks whether the required parameter (trigger) is present, and if not will add one. This function is to decide on whether ast_create_anonymous_func/1 or ast_create_anonymous_func/2 should be called

This function takes an AST of a function body and wraps it into an anonymous function. It does expect that the arguments are handled as part of the function body, e.g. the function body should look something like this

This function is similar to ast_create_anonymous_func/1, except that no argument was specified in the block (because the user does not want to use it), even though the function should have one. The function will make sure to add the argument to the block before wrapping it into an anonymous function.

This function extracts teh configs from an AST

This function creates the configuration for an led strip

This function creates the configuration for a component

This function creates a configuration for an animator

This function creates the configuration for a coordinator

This function creates the confguration for a job

This initializes our animation system, except if we don't want this

Functions

apply_effect(module, options, block)

This function applies an effect to some configurations

ast_add_argument_to_func(block)

@spec ast_add_argument_to_func(any()) :: {:fn, [], [{:->, list(), list()}, ...]}

This function takes an ast function block and adds an argument to the function. This is different from ast_add_argument_to_func_if_missing/1 that it does not expect there to be an arugment and therefore will raise an ArgumentError if it does find one.

ast_add_argument_to_func_if_missing(block)

@spec ast_add_argument_to_func_if_missing(any()) ::
  {:fn, [], [{:->, list(), list()}, ...]}

This function takes an AST block of a function, checks whether the required parameter (trigger) is present, and if not will add one. This function is to decide on whether ast_create_anonymous_func/1 or ast_create_anonymous_func/2 should be called

Note

This function makes the assumption that a single argument is required.

ast_create_anonymous_func(block)

@spec ast_create_anonymous_func([{:->, list(), [[atom()] | any()]}]) ::
  {:fn, [], [{:->, list(), [[atom()] | any()]}]}

This function takes an AST of a function body and wraps it into an anonymous function. It does expect that the arguments are handled as part of the function body, e.g. the function body should look something like this:

  arg1 -> :ok
  arg1, arg2 -> :ok

ast_create_anonymous_func(args, block)

@spec ast_create_anonymous_func([atom()], any()) ::
  {:fn, [], [{:->, [], [[atom()] | any()]}]}

This function is similar to ast_create_anonymous_func/1, except that no argument was specified in the block (because the user does not want to use it), even though the function should have one. The function will make sure to add the argument to the block before wrapping it into an anonymous function.

ast_extract_configs(block)

@spec ast_extract_configs(Macro.t()) :: Macro.t()

This function extracts teh configs from an AST

configure_strip(strip_name, drivers, strip_options, config)

This function creates the configuration for an led strip

create_config(name, module, opts)

@spec create_config(atom(), atom(), keyword() | nil) ::
  Fledex.Animation.Manager.config_t()

This function creates the configuration for a component

create_config(name, type, def_func, options)

@spec create_config(
  atom(),
  :animation | :static,
  (map() -> Fledex.Leds.t()),
  keyword() | nil
) ::
  Fledex.Animation.Manager.config_t()

This function creates a configuration for an animator

create_coordinator(name, options, function)

@spec create_coordinator(atom(), keyword(), (-> any())) :: %{
  required(atom()) => Fledex.Animation.Coordinator.config_t()
}

This function creates the configuration for a coordinator

create_job(name, schedule, options, function)

@spec create_job(atom(), Fledex.Scheduler.Job.schedule(), keyword(), (-> any())) :: %{
  required(atom()) => Fledex.Animation.JobScheduler.config_t()
}

This function creates the confguration for a job

init(opts)

@spec init(keyword()) :: :ok | {:ok, pid()}

This initializes our animation system, except if we don't want this