Layout-sensitive language extensibility with SugarHaskell

Sebastian Erdweg, F. Rieger, Tillmann Rendel, K. Ostermann
{"title":"Layout-sensitive language extensibility with SugarHaskell","authors":"Sebastian Erdweg, F. Rieger, Tillmann Rendel, K. Ostermann","doi":"10.1145/2364506.2364526","DOIUrl":null,"url":null,"abstract":"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.\n 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.\n 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.","PeriodicalId":188691,"journal":{"name":"ACM SIGPLAN Symposium/Workshop on Haskell","volume":"64 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2013-01-17","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"18","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"ACM SIGPLAN Symposium/Workshop on Haskell","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/2364506.2364526","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 18

Abstract

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.
查看原文
分享 分享
微信好友 朋友圈 QQ好友 复制链接
本刊更多论文
SugarHaskell的布局敏感语言可扩展性
程序员需要方便的语法来编写优雅而简洁的程序。因此,Haskell标准为某些场景提供了语法糖(例如,一元代码的do表示法),Haskell编译器的作者为更多场景提供了语法糖(例如,GHC中的箭头表示法),一些Haskell程序员为他们的个人需求实现了预处理器(例如,SHE中的习语括号)。但是手工编写的预处理器无法扩展:它们昂贵、容易出错,而且不可组合。因此,大多数研究人员和程序员都避免在实际的Haskell程序中使用他们需要的语法符号,而只在文档或论文中使用它们。我们提供了Haskell的一个语法可扩展版本SugarHaskell,它使普通程序员能够实现和使用自定义语法糖。在我们之前关于Java语法可扩展性工作的基础上,SugarHaskell将语法扩展作为糖库集成到Haskell的模块系统中。SugarHaskell中的语法扩展可以声明任意上下文无关和布局敏感的语法。SugarHaskell模块被编译成Haskell模块,并由Haskell编译器进一步处理。我们为SugarHaskell提供了一个基于eclipse的IDE,它也是可扩展的,并自动为导入到模块中的所有语法扩展提供语法着色。我们已经用几个案例研究验证了SugarHaskell,包括箭头表示法(在GHC中实现)和EBNF,它是一种简洁的语法,用于声明具有相关具体语法的代数数据类型。EBNF声明还展示了如何扩展扩展机制本身:它们引入了语法糖,以便在其他SugarHaskell模块中使用声明的具体语法。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 去求助
来源期刊
自引率
0.00%
发文量
0
期刊最新文献
Mio: a high-performance multicore io manager for GHC Understanding idiomatic traversals backwards and forwards An EDSL approach to high performance Haskell programming Causality of optimized Haskell: what is burning our cycles? Splittable pseudorandom number generators using cryptographic hashing
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
现在去查看 取消
×
提示
确定
0
微信
客服QQ
Book学术公众号 扫码关注我们
反馈
×
意见反馈
请填写您的意见或建议
请填写您的手机或邮箱
已复制链接
已复制链接
快去分享给好友吧!
我知道了
×
扫码分享
扫码分享
Book学术官方微信
Book学术文献互助
Book学术文献互助群
群 号:481959085
Book学术
文献互助 智能选刊 最新文献 互助须知 联系我们:info@booksci.cn
Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。
Copyright © 2023 Book学术 All rights reserved.
ghs 京公网安备 11010802042870号 京ICP备2023020795号-1