Expresso.Builder.Generator (expresso v0.1.0)

Copy Markdown View Source

Makes the functions of a builder from the definition of a Spark DSL

A module that calls use Expresso.Builder.Generator, extension: MyExtension gets one function for each entity of the extension, at each level of the tree. The function has the name of the entity. It takes the required arguments of the entity, then its optional arguments, then a keyword list. You can leave out the optional arguments and the keyword list. The keyword list holds the options of the entity and its children, under the keys of the children, such as elements:.

A function builds its struct with Spark.Dsl.Entity.build/5, which the macros of the DSL also call. Therefore the function validates the options with the schema of the entity, and it runs the transform of the entity. It also refuses a value that is not a child of the DSL. A function raises ArgumentError for an error.

The module also gets dsl_state/2. It takes the entities and the options of the section, and it makes the state that a module of the DSL has. Then it runs the transformers and the verifiers of the extension on the state, in the order of Spark. The extension must have one section.

A function accepts a struct under a key of the children when that key holds that kind of struct somewhere in the tree. The DSL is also less strict than its definitions: in a nested block, the macros of the outer entities stay in scope. The verifiers then refuse a child in a wrong place, such as a pause in a text box.

docs/overlays.md gives the reasons for this design.