Implementation

Let's create an internal DSL to control a smart house. This example fits well into the Internet of Things (IoT) era, which is getting more and more attention nowadays. The user is able to control their home using a very simple event notation. An event has the form of command -> receiver -> arguments. The arguments part is optional.

Not all events require arguments. An example of an event that does not require any arguments is shown here:

open -> gate

An example of an event that requires arguments is shown here:

increase -> boiler temperature -> 3 degrees

The -> symbol is used to mark the end of one part of an event and state the beginning of the next one. There are many ways to implement an internal DSL. We can use plain old ...

Get Mastering Python Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.