Macros (for Python)!
Posted by thepythonista on 2 June 2008
As I hinted at in my previous post, Andrew Dalke has written a very interesting piece of software: python4ply. Basically, he’s used ply to implement a parser and lexer for Python 2.5, in Python. The tutorial gives some neat examples of how you can modify this parser to enhance the grammar of Python. (My favorite is where he implemented syntax-level support for decimal.Decimal numbers.)
I’d definitely like to play with this a bit. He calls it a “half-formed macro system for Python,” and I see the similarity to Lisp macros. “Half-formed,” perhaps, because ply4python “macros” are basically second-class citizens: there’s no support for them in the language itself.
In spite of its limitations, this is definitely an interesting piece of software. Thanks, Andrew.