Type-directed, whitespace-delimited parsing for embedded DSLs

Domain-specific languages improve ease-of-use, expressiveness and verifiability, but defining and using different DSLs within a single application remains difficult. We introduce an approach for embedded DSLs where 1) whitespace delimits DSL-governed blocks, and 2) the parsing and type checking phases occur in tandem so that the expected type of the block determines which domain-specific parser governs that block. We argue that this approach occupies a sweet spot, providing high expressiveness and ease-of-use while maintaining safe composability. We introduce the design, provide examples and describe an ongoing implementation of this strategy in the Wyvern programming language. We also discuss how a more conventional keyword-directed strategy for parsing of DSLs can arise as a special case of this type-directed strategy.

[1]  Eelco Visser,et al.  SugarJ: library-based language extensibility , 2011, OOPSLA Companion.

[2]  Bernhard Rumpe,et al.  MontiCore: Modular Development of Textual Domain Specific Languages , 2008, TOOLS.

[3]  Simon L. Peyton Jones,et al.  Template meta-programming for Haskell , 2002, Haskell '02.

[4]  Tony Clark,et al.  Beyond Annotations: A Proposal for Extensible Java (XJ) , 2008, 2008 Eighth IEEE International Working Conference on Source Code Analysis and Manipulation.

[5]  Mark van den Brand,et al.  PREGMATIC - a generator for incremental programming environments , 1992 .

[6]  Thomas D. LaToza,et al.  Active code completion , 2011, 2012 34th International Conference on Software Engineering (ICSE).

[7]  Shigeru Chiba,et al.  OpenJava: A Class-Based Macro System for Java , 1999, Reflection and Software Engineering.

[8]  Peyton Jones,et al.  Haskell 98 language and libraries : the revised report , 2003 .

[9]  Eelco Visser,et al.  The Spoofax language workbench , 2010, SPLASH/OOPSLA Companion.

[10]  David Robson,et al.  Smalltalk-80: The Language and Its Implementation , 1983 .

[11]  Eelco Visser,et al.  Generalized type-based disambiguation of meta programs with concrete object syntax , 2005, GPCE'05.

[12]  W. Taha,et al.  Plenary talk III Domain-specific languages , 2008, 2008 International Conference on Computer Engineering & Systems.

[13]  Scott F. Smith,et al.  Backstage Java: making a difference in metaprogramming , 2011, OOPSLA '11.

[14]  Eelco Visser,et al.  The spoofax language workbench: rules for declarative specification of languages and IDEs , 2010, OOPSLA.

[15]  Michael D. Adams Principled parsing for indentation-sensitive languages: revisiting landin's offside rule , 2013, POPL.

[16]  Aruna Raja,et al.  Domain Specific Languages , 2010 .