Scala has been designed to enable the implementation of
Domain Specific Languages. This is surely one of its major strength (see
DSLs – A powerfull Scala feature for more information).
This article is an attempt to develop a very simple
internal DSL dealing with the
X10 home automation protocol (as done
here on the top of Oslo).
Here is the syntax (not sure that it reflects exactly the X10 protocol, but it's enough for our example ...):
- on [house_code] [unit_code]
where [house_code] is a letter between A and P (16 values) and [unit_code] an integer between 1 and 16 or All (for any devices).
- Idem for the off command
- It's the same for bright and dim commands except that an additional level parameter is required:
bright A 12 level 80