Now that we have an understanding of what domain-specific languages are in a general sense, let's dive into the building blocks of DSLs in Kotlin. At its core, a Kotlin-based DSL is comprised of functions and function literals with a receiver that can be leveraged to configure and build components via a human-readable, statically typed syntax. Beyond basic functions, we will examine several other features of Kotlin that can enable us to build custom DSLs:
- Top-level and extension functions
- Function types with receivers
- Custom scope annotations
Let's look at each of these in turn.