Advertisement

Safely Composable Type-Specific Languages

  • Cyrus Omar
  • Darya Kurilova
  • Ligia Nistor
  • Benjamin Chung
  • Alex Potanin
  • Jonathan Aldrich
Part of the Lecture Notes in Computer Science book series (LNCS, volume 8586)

Abstract

Programming languages often include specialized syntax for common datatypes (e.g. lists) and some also build in support for specific specialized datatypes (e.g. regular expressions), but user-defined types must use general-purpose syntax. Frustration with this causes developers to use strings, rather than structured data, with alarming frequency, leading to correctness, performance, security, and usability issues. Allowing library providers to modularly extend a language with new syntax could help address these issues. Unfortunately, prior mechanisms either limit expressiveness or are not safely composable: individually unambiguous extensions can still cause ambiguities when used together. We introduce type-specific languages (TSLs): logic associated with a type that determines how the bodies of generic literals, able to contain arbitrary syntax, are parsed and elaborated, hygienically. The TSL for a type is invoked only when a literal appears where a term of that type is expected, guaranteeing non-interference. We give evidence supporting the applicability of this approach and formally specify it with a bidirectionally typed elaboration semantics for the Wyvern programming language.

Keywords

extensible languages parsing bidirectional typechecking hygiene 

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Adams, M.D.: Principled parsing for indentation-sensitive languages: Revisiting Landin’s offside rule. In: Principles of Programming Languages (2013)Google Scholar
  2. 2.
    Bravenboer, M., Vermaas, R., Vinju, J.J., Visser, E.: Generalized type-based disambiguation of meta programs with concrete object syntax. In: Glück, R., Lowry, M. (eds.) GPCE 2005. LNCS, vol. 3676, pp. 157–172. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  3. 3.
    Clark, T., Sammut, P., Willans, J.S.: Beyond annotations: A proposal for extensible Java (XJ). In: Source Code Analysis and Manipulation (2008)Google Scholar
  4. 4.
    de Rauglaudre, D.: Camlp4 - Reference Manual (2003), http://caml.inria.fr/pub/docs/manual-camlp4/
  5. 5.
    Diekmann, L., Tratt, L.: Parsing composed grammars with language boxes. In: Workshop on Scalable Language Specification (2013)Google Scholar
  6. 6.
    Erdweg, S., Rendel, T., Kästner, C., Ostermann, K.: SugarJ: library-based language extensibility. In: Object-Oriented Programming Systems, Languages, and Applications (2011)Google Scholar
  7. 7.
    Erdweg, S., Rieger, F.: A framework for extensible languages. In: Generative Programming: Concepts & Experiences (2013)Google Scholar
  8. 8.
    Green, T., Petre, M.: Usability analysis of visual programming environments: A ‘cognitive dimensions’ framework. Journal of Visual Languages and Computing 7(2), 131–174 (1996)CrossRefGoogle Scholar
  9. 9.
    Harper, R.: Practical Foundations for Programming Languages. Cambridge University Press (2012)Google Scholar
  10. 10.
    Harper, R., Stone, C.: A Type-Theoretic Interpretation of Standard ML. In: Proof, Language and Interaction: Essays in Honour of Robin Milner. MIT Press (2000)Google Scholar
  11. 11.
    Ichikawa, K., Chiba, S.: Composable user-defined operators that can express user-defined literals. In: Modularity (2014)Google Scholar
  12. 12.
    JetBrains. JetBrains MPS – Meta Programming System, http://www.jetbrains.com/mps/
  13. 13.
    Karakoidas, V.: On domain-specific languages usage (why DSLs really matter). Crossroads 20(3), 16–17 (2014)CrossRefGoogle Scholar
  14. 14.
    Kats, L.C.L., Visser, E.: The Spoofax language workbench: Rules for declarative specification of languages and IDEs. In: Object-Oriented Programming Systems, Languages, and Applications (2010)Google Scholar
  15. 15.
    Krishnan, L., Van Wyk, E.: Termination analysis for higher-order attribute grammars. In: Czarnecki, K., Hedin, G. (eds.) SLE 2012. LNCS, vol. 7745, pp. 44–63. Springer, Heidelberg (2013)CrossRefGoogle Scholar
  16. 16.
    Lee, B., Grimm, R., Hirzel, M., McKinley, K.S.: Marco: Safe, expressive macros for any language. In: Noble, J. (ed.) ECOOP 2012. LNCS, vol. 7313, pp. 589–613. Springer, Heidelberg (2012)CrossRefGoogle Scholar
  17. 17.
    Leroy, X.: Formal verification of a realistic compiler. Communications of the ACM (2009)Google Scholar
  18. 18.
    Loh, A., van der Storm, T., Cook, W.R.: Managed data: Modular strategies for data abstraction. In: Onward! (2012)Google Scholar
  19. 19.
    Microsoft Corporation. Expression Trees (C# and Visual Basic), http://msdn.microsoft.com/en-us/library/bb397951.aspx
  20. 20.
    Miller, H., Haller, P., Burmako, E., Odersky, M.: Instant pickles: Generating object-oriented pickler combinators for fast and extensible serialization. In: Object Oriented Programming Systems, Languages & Applications (2013)Google Scholar
  21. 21.
    Möller, E.: SRFI-49: Indentation-sensitive syntax (2005), http://srfi.schemers.org/srfi-49/srfi-49.html
  22. 22.
    Nistor, L., Kurilova, D., Balzer, S., Chung, B., Potanin, A., Aldrich, J.: Wyvern: A simple, typed, and pure object-oriented language. In: MechAnisms for SPEcialization, Generalization and Inheritance (2013)Google Scholar
  23. 23.
    Omar, C., Chung, B., Kurilova, D., Potanin, A., Aldrich, J.: Type-directed, whitespace-delimited parsing for embedded DSLs. In: Globalization of Domain Specific Languages (2013)Google Scholar
  24. 24.
    Omar, C., Kurilova, D., Nistor, L., Chung, B., Potanin, A., Aldrich, J.: Safely Composable Type-Specific Languages. Technical Report CMU-ISR-14-106, Carnegie Mellon University (2014)Google Scholar
  25. 25.
    Omar, C., Yoon, Y., LaToza, T.D., Myers, B.A.: Active code completion. In: International Conference on Software Engineering (2012)Google Scholar
  26. 26.
    OWASP. OWASP Top 10 2013 (2013), https://www.owasp.org/index.php/Top_10_2013-Top_10
  27. 27.
    Palmer, Z., Smith, S.F.: Backstage Java: Making a Difference in Metaprogramming. In: Object-Oriented Programming Systems, Languages, and Applications (2011)Google Scholar
  28. 28.
    Pierce, B.C., Turner, D.N.: Local type inference. ACM Trans. Program. Lang. Syst. 22(1), 1–44 (2000)CrossRefGoogle Scholar
  29. 29.
    Schwerdfeger, A.C., Van Wyk, E.R.: Verifiable composition of deterministic grammars. In: Programming Language Design and Implementation (2009)Google Scholar
  30. 30.
    Sheard, T., Jones, S.: Template meta-programming for Haskell. ACM SIGPLAN Notices 37(12), 60–75 (2002)CrossRefGoogle Scholar
  31. 31.
    Stoy, J.E.: Denotational Semantics: The Scott-Strachey Approach to Programming Language Theory. MIT Press, Cambridge (1977)Google Scholar
  32. 32.
    Tatsubori, M., Chiba, S., Killijian, M.-O., Itano, K.: OpenJava: A Class-based Macro System for Java. In: Cazzola, W., Houmb, S.H., Tisato, F. (eds.) Reflection and Software Engineering. LNCS, vol. 1826, pp. 117–133. Springer, Heidelberg (2000)CrossRefGoogle Scholar
  33. 33.
    Tempero, E., Anslow, C., Dietrich, J., Han, T., Li, J., Lumpe, M., Melton, H., Noble, J.: Qualitas corpus: A curated collection of Java code for empirical studies. In: Asia Pacific Software Engineering Conference (2010)Google Scholar
  34. 34.
    Tratt, L.: Domain specific language implementation via compile-time meta-programming. ACM Trans. Program. Lang. Syst. 30(6) (October 2008)Google Scholar
  35. 35.
    van den Brand, M.G.J.: Pregmatic: A Generator for Incremental Programming Environments. PhD thesis, Katholieke Universiteit Nijmegen (1992)Google Scholar
  36. 36.
    Van Wyk, E.R., Schwerdfeger, A.C.: Context-aware scanning for parsing extensible languages. In: Generative Programming and Component Engineering (2007)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2014

Authors and Affiliations

  • Cyrus Omar
    • 1
  • Darya Kurilova
    • 1
  • Ligia Nistor
    • 1
  • Benjamin Chung
    • 1
  • Alex Potanin
    • 2
  • Jonathan Aldrich
    • 1
  1. 1.Carnegie Mellon UniversityPittsburghUSA
  2. 2.Victoria University of WellingtonWellingtonNew Zealand

Personalised recommendations