我想将纯 Python 代码解析为某些类的实例列表,这些类代表原始代码的各个部分。
一个例子:
>>> text = '''
... for x in range(100):
... print x
... '''
>>> tree = parse(text)
>>> print tree
Tree( ForLoop(x,Range(100), [Stmt(Print(x))]) )
# here ForLoop, Range, Stmt, Print are all custom classes