cast v0.1.0 Cast.DSL

Provides DSL for importing Cast types

Link to this section Summary

Functions

Declares a constant

Declares an enumeration module

Link to this section Functions

Link to this macro

const(name, opts \\ [])

(macro)

Declares a constant

Arguments:

  • name: name of the constant in the AST
  • opts: keyword list

    • name: valid function name: if constant name is not a valid function name, this option gives the name of the function to generate (default: constant name as in AST)
    • cast: a function to cast (charlist) value into desired one (default: & &1)

Generates a function to access value.

Link to this macro

enum(name, opts)

(macro)

Declares an enumeration module

Arguments

  • name: name of the generated module
  • opts: keyword list, one of:

    • contains: one of the value of the enumeration to extract (for anonymous enumerations)
    • name: name of the enumeration

Generates a module with following functions:

  • mapping/0: returns a %{atom => integer} map
  • key/1: returns the atom key for a given integer. Raise if invalid value.
  • value/1: returns the integer value for a given atom key. Raise if invalid key.