Abstract
A code generator is a program translating an input model into code. In this paper we focus on template-based code generators in the context of the model view controller architecture (MVC).
The language in which the code generator is written is known as a metalanguage in the code generation parlance. The metalanguage should be, on the one side, expressive enough to be of practical value, and, on the other side, restricted enough to enforce the separation between the view and the model, according to the MVC.
In this paper we advocate the notion of unparser-complete metalanguages as providing the right level of expressivity. An unparser-complete metalanguage is capable of expressing an unparser, a code generator that translates any legal abstract syntax tree into an equivalent sentence of the corresponding context-free language. A metalanguage not able to express an unparser will fail to produce all sentences belonging to the corresponding context-free language. A metalanguage able to express more than an unparser will also be able to implement code violating the model/view separation.
We further show that a metalanguage with the power of a linear deterministic tree-to-string transducer is unparser-complete. Moreover, this metalanguage has been successfully applied in a non-trivial case study where an existing code generator is refactored using templates.
- A. Alimarine, S. Smetsers, A. van Weelden, M. C. J. D. van Eekelen, and M. J. Plasmeijer. There and back again: arrows for invertible programming. In ACM SIGPLAN workshop on Haskell, pages 86--97, New York, NY, USA, 2005. ACM. Google Scholar
Digital Library
- B. J. Arnoldus. An Illumination of the Template Enigma: Software Code Generation with Templates. PhD thesis, Technische Universiteit Eindhoven, 2010.Google Scholar
- B. J. Arnoldus, J. W. Bijpost, and M. G. J. van den Brand. Repleo: a Syntax-Safe Template Engine. In GPCE '07, pages 25--32, New York, NY, USA, 2007. ACM Press. Google Scholar
Digital Library
- H. Bergsten. Javaserver Pages. O'Reilly & Associates, Inc., Sebastopol, CA, USA, 2nd edition, 2002. Google Scholar
Digital Library
- M. G. J. van den Brand, P. E. Moreau, and J. J. Vinju. A generator of efficient strongly typed abstract syntax trees in Java. IEE Proceedings Software, 152(2):70--78, 2005.Google Scholar
Cross Ref
- M. G. J. van den Brand and E. Visser. Generation of formatters for context-free languages. ACM Transactions on Software Engineering and Methodology, 5(1):1--41, 1996. Google Scholar
Digital Library
- S. Burbeck. Applications Programming in Smalltalk-80: How to use Model-View-Controller (MVC), 1992.Google Scholar
- L. G. W. A. Cleophas. Private communication, September 2009.Google Scholar
- H. Comon, M. Dauchet, R. Gilleron, C. Löding, F. Jacquemard, D. Lugiez, S. Tison, and M. Tommasi. Tree Automata Techniques and Applications. Available on: http://www.grappa.univ-lille3.fr/tatahttp://www.grappa.univ-lille3.fr/tata (accessed on November 30, 2010), 2008. release November, 18th 2008.Google Scholar
- F. L. Deremer. Practical Translators for LR(k) languages. PhD thesis, Massachusetts Institute of Technology, Cambridge, MA, USA, 1969.Google Scholar
- J. Engelfriet. Tree Automata and Tree Grammars. Manual written lecture notes, 1974.Google Scholar
- J. Engelfriet, G. Rozenberg, and G. Slutzki. Tree transducers, L systems, and two-way machines. Journal of Computer and System Sciences, 20(2):150--202, 1980.Google Scholar
Cross Ref
- E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design patterns: elements of reusable object-oriented software. Addison-Wesley Longman Publishing Co., Boston, MA, USA, 1995. Google Scholar
Digital Library
- R. Glück and M. Kawabe. A program inverter for a functional language with equality and constructors. In A. Ohori, editor, Programming Languages and Systems, volume 2895 of LNCS, pages 246--264. Springer, 2003.Google Scholar
- J. Hartmanis. Context-free languages and Turing machine computations. In Symposia in Applied Mathematics, volume 19 of Mathematical Aspects of Computer Science, pages 42--51. Amer Mathematical Society, 1967.Google Scholar
- J. Herrington. Code Generation in Action. Manning Publications Co., Greenwich, CT, USA, 2003. Google Scholar
Digital Library
- S. C. Johnson. Yacc: Yet Another Compiler-Compiler. Technical Report 32, Bell Laboratories, Murray Hill, NJ, USA, 1975.Google Scholar
- P. Klint, T. van der Storm, and J. J. Vinju. RASCAL: A Domain Specific Language for Source Code Analysis and Manipulation. In SCAM '09, pages 168--177, Los Alamitos, CA, USA, 2009. IEEE Computer Society Press. Google Scholar
Digital Library
- G. E. Krasner and S. T. Pope. A description of the model-view-controller user interface paradigm in the Smalltalk-80 system. Journal of Object Oriented Programming, 1(3):26--49, 1988. Google Scholar
Digital Library
- D. C. Oppen. Pretty printing. Technical Report STAN-CS-79-770, Computer Science Department, Stanford University, October 1979. Google Scholar
Digital Library
- T. J. Parr. Enforcing Strict Model-View Separation in Template Engines. In WWW '04: International Conference on World Wide Web, pages 224--233, New York, NY, USA, 2004. ACM Press. Google Scholar
Digital Library
- N. Ramsey. Unparsing expressions with prefix and postfix operators. Software: Practice & Experience, 28(12):1327--1356, 1998. Google Scholar
Digital Library
- T. Rendel and K. Ostermann. Invertible syntax descriptions: unifying parsing and pretty printing. In ACM SIGPLAN Haskell symposium, pages 1--12, New York, NY, USA, 2010. ACM. Google Scholar
Digital Library
- T. Sheard. Accomplishments and Research Challenges in Meta-programming. In SAIG, volume 2196 of LNCS, pages 2--44, London, UK, 2001. Springer. Google Scholar
Digital Library
- T. Sturm, J. von Voss, and M. Boger. Generating Code from UML with Velocity Templates. In J.-M. Jézéquel, H. Hußmann, and S. Cook, editors, UML, volume 2460 of LNCS, pages 150--161. Springer, 2002. Google Scholar
Digital Library
- M. G. J. van den Brand, J. S. Scheerder, J. J. Vinju, and E. Visser. Disambiguation filters for scannerless generalized LR parsers. In R. Horspool, editor, Compiler Construction, volume 2304 of LNCS, pages 21--44. Springer, 2002. Google Scholar
Digital Library
- J. Virágh. Deterministic ascending tree automata I. Acta Cybernetica, 5:33--42, 1981.Google Scholar
- E. Visser. Stratego: A language for Program Transformation based on Rewriting Strategies. System Description of Stratego 0.5. In RTA '01, volume 2051 of LNCS, pages 357--361, Berlin, Heidelberg, 2001. Springer. Google Scholar
Digital Library
- D. S. Wile. Abstract syntax from concrete syntax. In ICSE, pages 472--480, New York, NY, USA, 1997. ACM Press. Google Scholar
Digital Library
Index Terms
Less is more: unparser-completeness of metalanguages for template engines
Recommendations
Repleo: a syntax-safe template engine
GPCE '07: Proceedings of the 6th international conference on Generative programming and component engineeringTemplates are a very common solution to generate code. They are used for different tasks like rendering webpages, creating Java Beans and so on. Most template systems have no notion of the object language and just generate text. The drawback of this ...
Less is more: unparser-completeness of metalanguages for template engines
GPCE '11: Proceedings of the 10th ACM international conference on Generative programming and component engineeringA code generator is a program translating an input model into code. In this paper we focus on template-based code generators in the context of the model view controller architecture (MVC).
The language in which the code generator is written is known as ...
Towards More Security in Data Exchange: Defining Unparsers with Context-Sensitive Encoders for Context-Free Grammars
SPW '15: Proceedings of the 2015 IEEE Security and Privacy WorkshopsTo exchange complex data structures in distributed systems, documents written in context-free languages are exchanged among communicating parties. Unparsing these documents correctly is as important as parsing them correctly because errors during ...







Comments