Contracts for domain-specific languages in Ruby

Contracts for domain-specific languages in Ruby
复制标题

Ruby 中特定领域语言的契约

DOI:
--
复制
发表时间:
2014
期刊:
Dynamic Languages Symposium
影响因子:
--
通讯作者:
Jeffrey S. Foster
Jeffrey S. Foster
中科院分区:
--
文献类型:
--
作者:
T. Stephen Strickland;Brianna M. Ren;Jeffrey S. Foster

文献摘要

被引文献

相似文献

本文关注的是面向对象的嵌入式dsl,它在Ruby社区中很流行,但在研究文献中却很少受到关注。Ruby dsl将语言关键字实现为对self的隐式方法调用;语言结构是通过调整在不同范围内绑定到self的对象来实现的。虽然Ruby dsl功能强大且优雅,但它们缺乏规范。在本文中,我们介绍了Ruby dsl的契约,它允许我们在实现和客户端之间存在不一致时适当地归咎于责任。我们在DSL中形式化了Ruby DSL契约检查,这是一种核心演算,使用带有实例求值的预方法来强制执行契约。然后我们描述RDL,一种Ruby DSL契约的实现。最后,我们提供了两个自动推断RDL契约的工具:TypeInfer根据观察到的方法调用推断简单的类类型契约,而DSLInfer根据初始示例生成和测试候选DSL用法推断DSL关键字范围和嵌套。TypeInfer生成的类型契约工作得很好,尽管它们的精度受到少量测试的限制,而DSLInfer可以找到几乎所有的DSL结构。我们的目标是帮助用户从示例程序中理解DSL。
This paper concerns object-oriented embedded DSLs, which are popular in the Ruby community but have received little attention in the research literature. Ruby DSLs implement language keywords as implicit method calls to self; language structure is enforced by adjusting which object is bound to self in different scopes. While Ruby DSLs are powerful and elegant, they suffer from a lack of specification. In this paper, we introduce contracts for Ruby DSLs, which allow us to attribute blame appropriately when there are inconsistencies between an implementation and client. We formalize Ruby DSL contract checking in DSL, a core calculus that uses premethods with instance evaluation to enforce contracts. We then describe RDL, an implementation of Ruby DSL contracts. Finally, we present two tools that automatically infer RDL contracts: TypeInfer infers simple, type-like contracts based on observed method calls, and DSLInfer infers DSL keyword scopes and nesting by generating and testing candidate DSL usages based on initial examples. The type contracts generated by TypeInfer work well enough, though they are limited in precision by the small number of tests, while DSLInfer finds almost all DSL structure. Our goal is to help users understand a DSL from example programs.