I am working on a domain specific language implemented on top of Python. The grammar is so close to Python that so far we have only done some simple trivial transformations and then fed them to ast . For example, the indentation is replaced by the #endfor / #endwhile / #endif operators, so we normalize the indentation while it is still a string.
I am wondering if there is a better way? As far as I can tell, ast hard-coded to parse Python grammar, and I can't find any documentation other than http://docs.python.org/library/ast.html#module-ast (and the source itself, I I guess).
Does anyone have personal experience with PyParsing, ANTLR or PLY?
There are vague plans to rewrite the interpreter into something that turns our language into valid Python and passes it into the Python interpreter, so I would like something compatible with compile , but this is not an interruption to the deal.
Update: It occurred to me that
from __future__ import print_function, with_statement
changes the way Python parses the following source. However, PEP 236 assumes that this is the window syntax for the compiler function. Can someone confirm that trying to override / extend __future__ not the correct solution to my problem?
source share