Static Syntax Validation for Code Generation with String Templates

  • Dorian WeberEmail author
  • Joachim Fischer
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 10567)


Many applications of model-based techniques ultimately require a model-to-text transformation to make practical use of the information encoded in meta-model instances. This step requires a code generator that has to be validated in order to ensure that the translation doesn’t alter the semantics of the model. Validation is often test-based, i.e. the code generator is executed on a wide range of inputs in order to verify the correctness of its output. Unfortunately, tests generally only prove the presence of errors, not their absence. This paper identifies the common core of string template implementations that are often used in the description of code generators, deriving a formal model that is suitable for mathematical reasoning. We provide a formal proof of the equivalence in expressiveness between string templates and context free grammars, thereby allowing the application of formal results from language theory. From there, we derive a scheme that would allow the verification of syntactical correctness for generated code before the translation of any model-instance is attempted, at the expense of freedom in the variability of the description.


Code generation Language theory String template Meta language Domain-specific language 


  1. 1.
    Arnoldus, B.J.: An illumination of the template enigma: software code generation with templates. Ph.D. thesis, Technische Universiteit Eindhoven (2010)Google Scholar
  2. 2.
    Bettini, L.: Implementing Domain-Specific Languages with Xtext and Xtend. Packt Publishing, Birmingham (2013)Google Scholar
  3. 3.
    Hopcroft, J.E., Ullman, J.D.: Introduction to Automata Theory, Languages, and Computation, Chap. 8, p. 203. In: [5] (1979)Google Scholar
  4. 4.
    Hopcroft, J.E., Ullman, J.D.: Introduction to Automata Theory, Languages, and Computation, Chap. 8, pp. 185–192. In: [5] (1979)Google Scholar
  5. 5.
    Hopcroft, J.E., Ullman, J.D.: Introduction to Automata Theory, Languages, and Computation. Addison-Wesley (1979)Google Scholar
  6. 6.
    Parr, T.J.: Enforcing strict model-view separation in template engines. In: Proceedings of the 13th International Conference on World Wide Web, pp. 224–233. ACM (2004)Google Scholar
  7. 7.
    Parr, T.J.: A functional language for generating structured text (2006).
  8. 8.
    Rudd, T., Orr, M., Bicking, I., Esterbrook, C.: Cheetah: the python-powered template engine. In: 10th International Python Conference-2002 (2007)Google Scholar
  9. 9.
    Wachsmuth, G.: A formal way from text to code templates. In: Chechik, M., Wirsing, M. (eds.) FASE 2009. LNCS, vol. 5503, pp. 109–123. Springer, Heidelberg (2009). doi: 10.1007/978-3-642-00593-0_8 CrossRefGoogle Scholar

Copyright information

© Springer International Publishing AG 2017

Authors and Affiliations

  1. 1.Institut für InformatikHumboldt-Universität zu BerlinBerlinGermany

Personalised recommendations