13
I'm looking to write a Python import filter or preprocessor for source files that are essentially Python with extra language elements, to read the file, parse to an abstract syntax tree, apply transforms (implement the new parts of the language), and write valid Python code which can be consumed by CPython.
I want to write this in Python and am looking for the best parser for the task. The parser built-in to Python is not appropriate because it requires the source files to be actual Python, which these are not. There are tons of parsers or parser generators that work with Python, but which is the best for my needs?
My requirements:
- Written in Python or has Python bindings.
- Comes with a Python grammar that I can tweak or can consume tweak-able Python grammar available elsewhere such as http://docs.python.org/reference/grammar.html.
- Can re-serialize the AST after transforming it.
- Should not be horrific API-wise.