Implementation

Let's create an internal DSL to control a smart house. This example fits well into the Internet of things 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:

open -> gate

An example of an event that requires arguments is shown:

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 regular expressions, string ...

Get Mastering Python Design Patterns 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.