Generating a fluent API with syntax checking from an LR grammar
Authors:
Open Access
- 10 October 2019
- journal article
- research article
- Published by Association for Computing Machinery (ACM) in Proceedings of the ACM on Programming Languages
- Vol. 3 (OOPSLA) , 1-24
Abstract
This paper proposes a fluent API generator for Scala, Haskell, and C++. It receives a grammar definition and generates a code skeleton of the library in the host programming language. The generated library is accessed through a chain of method calls; this style of API is called a fluent API. The library uses the host-language type checker to detect an invalid chain of method calls. Each method call is regarded as a lexical token in the embedded domain specific language implemented by that library. A sequence of the lexical tokens is checked and, if the sequence is not acceptable by the grammar, a type error is reported during compilation time. A contribution of this paper is to present an algorithm for generating the code-skeleton for a fluent API that reports a type error when a chain of method calls to the library does not match the given LR grammar. Our algorithm works in Scala, Haskell, and C++. To encode LR parsing, it uses the method/function overloading available in those languages. It does not need an advanced type system, or exponential compilation time or memory consumption. This paper also presents our implementation of the proposed generator.Keywords
This publication has 13 references indexed in Scilit:
- Typechecking protocols with Mungo and StMungo: A session type toolchain for JavaScience of Computer Programming, 2018
- Silverchain: a fluent API generator2017
- Java generics are turing complete2017
- Context-free session types2016
- Wyvern2013
- Simple and safe SQL queries with C++ templatesScience of Computer Programming, 2010
- EriLex: An Embedded Domain Specific Language Generator2010
- Generating words in a context-free language uniformly at randomInformation Processing Letters, 1994
- A parsing automata approach to LR theoryTheoretical Computer Science, 1981
- On reducing the number of states in a PDATheory of Computing Systems, 1981