Another great article appeared in the April issue of Python Magazine. This time it was written by Paul McGuire, author of pyparsing. The article is called Create your own Domain Specific Language in Python with imputil and pyparsing. It’s a fairly long article, but it walked through the steps of generating a language to describe state machines. The author used pyparsing to extend the Python language to add a state machine construct that is intermingled with real Python source code. He stored these extended source files as .pystate files instead of .py files, and then hooked the module import process with imputil to allow him to import .pystate files and have pyparsing automatically transform .pystate files into real python code.
More and more I’m realizing the power of these sorts of solutions. It was great to see an article bringing these tools together to do something very interesting, and non-trivial. If you haven’t subscribed to Python Magazine, you may want to consider it. There have been some really top-notch articles.