skip to main content

Generating a fluent API with syntax checking from an LR grammar

Published:10 October 2019Publication History
Skip Abstract Section

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.

References

  1. Roland Bock. 2016. rbock/sqlpp11: A type safe SQL template library for C++. https://github.com/rbock/sqlpp11 .Google ScholarGoogle Scholar
  2. John Cocke. 1969. Programming Languages and Their Compilers: Preliminary Notes.Google ScholarGoogle Scholar
  3. Bruno Courcelle. 1977. On Jump-Deterministic Pushdown Automata. Mathematical systems theory (1977).Google ScholarGoogle Scholar
  4. Werner Dietl, Stephanie Dietzel, Michael D. Ernst, Kivanç Muşlu, and Todd W. Schiller. 2011. Building and Using Pluggable Type-checkers. In Proceedings of the 33rd International Conference on Software Engineering (ICSE ’11). ACM, 681–690. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Apache Software Foundation. 2014. Apache Phoenix. https://phoenix.apache.org/ .Google ScholarGoogle Scholar
  6. Martin Fowler. 2005. FluentInterface. https://www.martinfowler.com/bliki/FluentInterface.html .Google ScholarGoogle Scholar
  7. Emden R. Gansner and Stephen C. North. 2000. An open graph visualization system and its applications to software engineering. SOFTWARE - PRACTICE AND EXPERIENCE 30, 11 (2000), 1203–1233.Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Jeremy Gibbons and Nicolas Wu. 2014. Folding domain-specific languages: Deep and shallow embeddings (functional Pearl). In Proceedings of the ACM SIGPLAN International Conference on Functional Programming.Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Joseph (Yossi) Gil and Keren Lenz. 2010. Simple and safe SQL queries with C++ templates. Science of Computer Programming 75, 7 (2010), 573 – 595. Generative Programming and Component Engineering (GPCE 2007).Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Yossi Gil and Tomer Levy. 2016. Formal Language Recognition with the Java Type Checker. In Proceedings of 30th European Conference on Object-Oriented Programming .Google ScholarGoogle Scholar
  11. Yossi Gil and Ori Roth. 2019. Fling - A Fluent API Generator. In 33rd European Conference on Object-Oriented Programming (ECOOP 2019) . Google ScholarGoogle ScholarCross RefCross Ref
  12. Jonathan Goldstine, John K. Price, and Detlef Wotschke. 1981. On reducing the number of states in a PDA. Mathematical systems theory 15, 1 (01 Dec 1981), 315–321. Google ScholarGoogle ScholarCross RefCross Ref
  13. Radu Grigore. 2017. Java Generics Are Turing Complete. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages .Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Stephan Heilbrunner. 1981. A parsing automata approach to LR theory. Theoretical Computer Science 15, 2 (1981), 117 – 157. Google ScholarGoogle ScholarCross RefCross Ref
  15. Kohei Honda. 1993. Types for dyadic interaction. In CONCUR’93, Eike Best (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg, 509–523.Google ScholarGoogle Scholar
  16. Paul Hudak. 1996. Building Domain-Specific Embedded Languages. Comput. Surveys (1996).Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Kazuhiro Ichikawa and Shigeru Chiba. 2017. User-Defined Operators Including Name Binding for New Language Constructs. The Art, Science, and Engineering of Programming 1, 2, Article 15 (2017), 15:1–15:25 pages.Google ScholarGoogle Scholar
  18. Google Inc. 2011. Improve your code with lint checks. https://developer.android.com/studio/write/lint .Google ScholarGoogle Scholar
  19. Tadao Kasami. 1965. An Efficient Recognition and Syntax-Analysis Algorithm for Context-Free Languages. Technical Report.Google ScholarGoogle Scholar
  20. Dimitrios Kouzapas, Ornela Dardha, Roly Perera, and Simon J. Gay. 2018. Typechecking protocols with Mungo and StMungo: A session type toolchain for Java. Science of Computer Programming 155 (2018), 52–75. Google ScholarGoogle ScholarCross RefCross Ref
  21. Stefan Krüger, Johannes Späth, Karim Ali, Eric Bodden, and Mira Mezini. 2018. CrySL: An Extensible Approach to Validating the Correct Usage of Cryptographic APIs. In European Conference on Object-Oriented Programming (ECOOP). 10:1–10:27.Google ScholarGoogle Scholar
  22. Tomer Levy. 2017. A Fluent API for Automatic Generation of Fluent APIs in Java.Google ScholarGoogle Scholar
  23. Harry G. Mairson. 1994. Generating Words in a Context-free Language Uniformly at Random. Inf. Process. Lett. (1994). Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Tomoki Nakamaru, Kazuhiro Ichikawa, Tetsuro Yamazaki, and Shigeru Chiba. 2017. Silverchain: a fluent API generator. In Proceedings of the 16th ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences .Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Hanne Riis Nielson and Flemming Nielson. 1992. Semantics with Applications: A Formal Introduction.Google ScholarGoogle Scholar
  26. Ligia Nistor, Darya Kurilova, Stephanie Balzer, Benjamin Chung, Alex Potanin, and Jonathan Aldrich. 2013. Wyvern: A Simple, Typed, and Pure Object-oriented Language. In Proceedings of the 5th Workshop on MechAnisms for SPEcialization, Generalization and inHerItance (MASPEGHI ’13) . ACM, 9–16.Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Joshua Sunshine, Karl Naden, Sven Stork, Jonathan Aldrich, and Éric Tanter. 2011. First-class State Change in Plaid. In Proceedings of the 2011 ACM International Conference on Object Oriented Programming Systems Languages and Applications (OOPSLA ’11) . ACM, 713–732. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Peter Thiemann and Vasco T. Vasconcelos. 2016. Context-free Session Types. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming (ICFP 2016) . ACM, 462–475. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Todd Veldhuizen. 2003. C++ Templates are Turing Complete. Technical Report. Indiana University Computer Science.Google ScholarGoogle Scholar
  30. Hao Xu. 2010. EriLex: An Embedded Domain Specific Language Generator.Google ScholarGoogle Scholar
  31. Daniel Younger. 1967. Recognition and parsing of context-free languages in time n 3 . Information and Control (1967).Google ScholarGoogle Scholar

Index Terms

  1. Generating a fluent API with syntax checking from an LR grammar

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!