Meta Programming
For most use cases, the default API @option
is sufficient, however, there are some specific cases requires one to use Configurations
's advanced API on meta programming.
Custom Option Macro
In some cases, you may not want all the features we defined by default in Configurations
.
In this case, you can construct your own macro using the code generation passes defined in Configurations
. The code generation passes API starts with codegen_
. You combine them as a codegen pipeline.
Configurations
uses an intermediate representation defined by Expronicon to represent user defined option types, which is the JLKwStruct
struct.
Builtin Code Generators
Configurations.add_field_defaults!
— Methodadd_field_defaults!(m::Module, def::JLKwStruct)
Add default value for Maybe
and Reflect
type.
Configurations.codegen_convert
— Methodcodegen_convert(x::JLKwStruct)
Generate Base.convert
from AbstractDict{String}
to the given option type.
Configurations.codegen_create
— Methodcodegen_create(def::JLKwStruct)
Generate Configurations.create
overload.
Configurations.codegen_field_default
— Methodcodegen_field_default(def::JLKwStruct)
Generate field_default
overload to support the default value reflection.
Configurations.codegen_from_dict_specialize
— Methodcodegen_from_dict_specialize(def::JLKwStruct)
Generate the specialized from_dict
for the given definition.
Configurations.codegen_is_option
— Methodcodegen_is_option(x::JLKwStruct)
Generate the is_option
method.
Configurations.codegen_isequal
— Methodcodegen_isequal(x::JLKwStruct)
Generate Base.:(==)
to overload comparison operator to compare_options
for given option type.
Configurations.codegen_option_type
— Methodcodegen_option_type(mod::Module, def::JLKwStruct)
Generate the Configurations
option type definition from a given JLKwStruct
created by Expronicon
.
Configurations.codegen_type_alias
— Methodcodegen_type_alias(def::JLKwStruct)
Generate type alias method type_alias
.
Configurations.has_duplicated_reflect_type
— Methodhas_duplicated_reflect_type(m::Module, def::JLKwStruct)
Check if the definition has duplicated reflect type.
Configurations.is_maybe_type_expr
— Methodis_maybe_type_expr(m::Module, @nospecialize(ex))
Check if the expression ex
evaluates to a Maybe{T}
.
Configurations.is_reflect_type_expr
— Methodis_reflect_type_expr(m::Module, @nospecialize(ex))
Check if the expression ex
evaluates to a Reflect
.
Configurations.validate_option_def
— Methodvalidate_option_def(def::JLKwStruct)
Validate the option definition.