skip to main content
research-article

Less is more: unparser-completeness of metalanguages for template engines

Authors Info & Claims
Published:22 October 2011Publication History
Skip Abstract Section

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.

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. B. J. Arnoldus. An Illumination of the Template Enigma: Software Code Generation with Templates. PhD thesis, Technische Universiteit Eindhoven, 2010.Google ScholarGoogle Scholar
  3. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  4. H. Bergsten. Javaserver Pages. O'Reilly & Associates, Inc., Sebastopol, CA, USA, 2nd edition, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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 ScholarGoogle ScholarCross RefCross Ref
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. S. Burbeck. Applications Programming in Smalltalk-80: How to use Model-View-Controller (MVC), 1992.Google ScholarGoogle Scholar
  8. L. G. W. A. Cleophas. Private communication, September 2009.Google ScholarGoogle Scholar
  9. 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 ScholarGoogle Scholar
  10. F. L. Deremer. Practical Translators for LR(k) languages. PhD thesis, Massachusetts Institute of Technology, Cambridge, MA, USA, 1969.Google ScholarGoogle Scholar
  11. J. Engelfriet. Tree Automata and Tree Grammars. Manual written lecture notes, 1974.Google ScholarGoogle Scholar
  12. 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 ScholarGoogle ScholarCross RefCross Ref
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle Scholar
  15. 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 ScholarGoogle Scholar
  16. J. Herrington. Code Generation in Action. Manning Publications Co., Greenwich, CT, USA, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. S. C. Johnson. Yacc: Yet Another Compiler-Compiler. Technical Report 32, Bell Laboratories, Murray Hill, NJ, USA, 1975.Google ScholarGoogle Scholar
  18. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  19. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. D. C. Oppen. Pretty printing. Technical Report STAN-CS-79-770, Computer Science Department, Stanford University, October 1979. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  22. N. Ramsey. Unparsing expressions with prefix and postfix operators. Software: Practice & Experience, 28(12):1327--1356, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  24. T. Sheard. Accomplishments and Research Challenges in Meta-programming. In SAIG, volume 2196 of LNCS, pages 2--44, London, UK, 2001. Springer. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  26. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  27. J. Virágh. Deterministic ascending tree automata I. Acta Cybernetica, 5:33--42, 1981.Google ScholarGoogle Scholar
  28. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  29. D. S. Wile. Abstract syntax from concrete syntax. In ICSE, pages 472--480, New York, NY, USA, 1997. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Less is more: unparser-completeness of metalanguages for template engines

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      • Published in

        cover image ACM SIGPLAN Notices
        ACM SIGPLAN Notices  Volume 47, Issue 3
        GCPE '11
        March 2012
        179 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/2189751
        Issue’s Table of Contents
        • cover image ACM Conferences
          GPCE '11: Proceedings of the 10th ACM international conference on Generative programming and component engineering
          October 2011
          194 pages
          ISBN:9781450306898
          DOI:10.1145/2047862

        Copyright © 2011 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 22 October 2011

        Check for updates

        Qualifiers

        • research-article

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!