Text Templates

This is a model-to-text transformation.

Summary

Literal text templates are used to generate text from models, where variables or operations within the template can access the source model to fill in specific values or to choose variations of the template.

Application conditions

This pattern is suitable for a wide range of model-to-text transformations, where only text is needed as output, not a model representing the output document or program. If rules only output text, and contain substantial fragments of literal string text to form this output, this is a sign that the pattern is required.

Solution

Use templates of target language constructs to produce the output text, accessing source elements to configure the output.

Benefits

Arbitrary text can be generated, for program code or document content, without the need to construct a metamodel for the target language. For programming languages, such metamodels can be large and complex.

Disadvantages

Verification of such transformations is difficult because the result is a linear sequence of text, without structure.

Applications and examples

The pattern can be used for model-to-text transformations or higher-order transformations.

In (Tisi et al., 2010) the idea of text templates is introduced to make higher-order transformations more concise: the text template describes in concrete syntax a transformation to be produced by the higher-order transformation. The EGL language is a specialised model-to-text language which uses templates (www.eclipse.org/epsilon/doc/egl).

(Tisi et al., 2010) Tisi, J. Cabot, F. Jouault, Improving higher-order transformations support in ATL, ICMT 2010, LNCS vol. 6142, pp. 215--229, 2010.