Chapter 8. Designing external DSLs using Scala parser combinators

 

This chapter covers

  • What are parser combinators
  • The Scala parser combinator library
  • Using packrat parsers
  • Designing external DSLs using Scala parser combinators

With basic background information about external DSL implementations already served up in chapter 7, we’re going to jump directly into parser combinators. Parser combinators are one of the most beautiful applications of functional programming. They offer an internal DSL to use for designing external DSLs so you don’t have to implement your own language infrastructure as you do with other techniques of external DSL design. When we designed an external DSL for processing client orders in chapter 7, remember that we used ANTLR as the parser generator. We designed our grammar for the DSL and ANTLR generated the parser for us. To design our own DSL, we had to use an external tool that provided us with the necessary language implementation infrastructure. Using parser combinators, you don’t have to step out of the host language for a second. This makes the implementation succinct, expressive, and completely free of any external dependency.

8.1. Parser combinators

8.2. The Scala parser combinator library

8.3. DSL design with parser combinators: step-by-step

8.4. A DSL that needs a packrat parser

8.5. Summary

8.6. References