I\'m looking to write a Python import filter or preprocessor for source files that are essentially Python with extra language elements. The goal is to read the source file, pars
The first thing that comes to mind is lib2to3. It is a complete pure-Python implementation of a Python parser. It reads a Python grammar file and parses Python source files according to this grammar. It offers a great infrastructure for performing AST manipulations and writing back nicely formatted Python code -- after all it's purpose is to transform between two Python-like languages with slightly different grammars.
Unfortunately it's lacking documentation and doesn't guarantee a stable interface. There are projects that build on top of lib2to3
nevertheless, and the source code is quite readable. If API stability is an issue, you can just fork it.