Projective Template-Based Code Generation

Template-based code generation (TBCG) is a generative technology that transforms data into structured text, e.g. code, through the use of templates. The data, referred to as the model, represents an abstract design while the templates provide the mold of the target code used by the generator in the process of code production. A classical template is a mixture of text blocks and imperative control code segments. The text blocks’ concern is to describe textual patterns while the control code’s is to retrieve, manipulate, and substitute the data into place holders within the text. The mixture of these concerns reduces the readability, expressiveness, reusability, and analyzability of the textual patterns and the control code alike. We introduce the projector templates, a TBCG technology that adheres to separation of concerns of the template, model, and the template control code. Inspired by the relational theory, projective template blocks are treated as annotated relations that can derive their input from the source model through the use of relational operators. The projector templates are thus code-free, coherent, their transformation process reusable, and capable of elegantly coping with complex code-generation scenarios.