Layout-sensitive language extensibility with SugarHaskell

Layout-sensitive language extensibility with SugarHaskell
复制标题

SugarHaskell 的布局敏感语言可扩展性

DOI:
10.1145/2364506.2364526
复制
发表时间:
2013
期刊:
Parallel Process. Lett.
影响因子:
--
通讯作者:
K. Ostermann
K. Ostermann
中科院分区:
--
文献类型:
--
作者:
Sebastian Erdweg;F. Rieger;Tillmann Rendel;K. Ostermann

文献摘要

被引文献

相似文献

程序员需要方便的语法来编写优雅简洁的程序。因此,Haskell标准为某些场景提供了语法糖(例如,do notation for monadic code),Haskell编译器的作者为更多的场景提供了语法糖(例如,GHC中的箭头符号),并且一些Haskell程序员针对其个人需要实现预处理器(例如,SHE中的习惯用法括号)。但是手动编写的预处理器无法扩展:它们昂贵,容易出错,并且不可组合。因此,大多数研究人员和程序员避免在实际的Haskell程序中使用他们需要的语法符号,而只在文档或论文中使用它们。我们提出了一个语法上可扩展的Haskell版本,SugarHaskell,使普通程序员能够实现和使用自定义语法糖。 在我们之前关于Java语法扩展性的工作的基础上,SugarHaskell将语法扩展作为糖库集成到Haskell的模块系统中。SugarHaskell中的JavaScript扩展可以声明任意上下文无关和布局敏感的语法。SugarHaskell模块被编译成Haskell模块,并由Haskell编译器进一步处理。我们为SugarHaskell提供了一个基于语法的IDE,它也是可扩展的,并自动为导入到模块中的所有语法扩展提供语法着色。 我们已经通过几个案例研究验证了SugarHaskell,包括箭头表示法(在GHC中实现)和EBNF作为一种简洁的语法,用于声明代数数据类型和相关的具体语法。EBNF声明还展示了如何扩展扩展机制本身:它们引入了语法糖,以便在其他SugarHaskell模块中使用声明的具体语法。
Programmers need convenient syntax to write elegant and concise programs. Consequently, the Haskell standard provides syntactic sugar for some scenarios (e.g., do notation for monadic code), authors of Haskell compilers provide syntactic sugar for more scenarios (e.g., arrow notation in GHC), and some Haskell programmers implement preprocessors for their individual needs (e.g., idiom brackets in SHE). But manually written preprocessors cannot scale: They are expensive, error-prone, and not composable. Most researchers and programmers therefore refrain from using the syntactic notations they need in actual Haskell programs, but only use them in documentation or papers. We present a syntactically extensible version of Haskell, SugarHaskell, that empowers ordinary programmers to implement and use custom syntactic sugar. Building on our previous work on syntactic extensibility for Java, SugarHaskell integrates syntactic extensions as sugar libraries into Haskell's module system. Syntax extensions in SugarHaskell can declare arbitrary context-free and layout-sensitive syntax. SugarHaskell modules are compiled into Haskell modules and further processed by a Haskell compiler. We provide an Eclipse-based IDE for SugarHaskell that is extensible, too, and automatically provides syntax coloring for all syntax extensions imported into a module. We have validated SugarHaskell with several case studies, including arrow notation (as implemented in GHC) and EBNF as a concise syntax for the declaration of algebraic data types with associated concrete syntax. EBNF declarations also show how to extend the extension mechanism itself: They introduce syntactic sugar for using the declared concrete syntax in other SugarHaskell modules.