Skip to content

Instantly share code, notes, and snippets.

@enomado
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enomado/f7c1e6702ae2fb03156c to your computer and use it in GitHub Desktop.
Save enomado/f7c1e6702ae2fb03156c to your computer and use it in GitHub Desktop.
import py
import tokenize
import token
import StringIO
from pypy.interpreter.pyparser import parser, metaparser, pygram, pyparse
from pypy.interpreter.pyparser.test.test_metaparser import MyGrammar
from pypy.interpreter.pyparser import pytokenizer
from pprint import pprint
from pypy.interpreter.astcompiler.astbuilder import ASTBuilder
from pypy.objspace.fake.objspace import FakeObjSpace
space = FakeObjSpace()
p = pyparse.PythonParser(space)
info = pyparse.CompileInfo("<test>", 'exec')
code = """
a = (1,"" "", lambda x: 1, ""\\
'')
"""
cst = p.parse_source(code, info)
t = ASTBuilder(space, cst, info)
q = t.build_ast()
def traverse(node):
while(node.children):
node = node.children[-1]
return node
print q
import IPython; IPython.embed()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment