[pypy-svn] r22003 - pypy/dist/pypy/module/recparser

adim at codespeak.net adim at codespeak.net
Thu Jan 12 09:50:36 CET 2006


Author: adim
Date: Thu Jan 12 09:50:35 2006
New Revision: 22003

Modified:
   pypy/dist/pypy/module/recparser/__init__.py
   pypy/dist/pypy/module/recparser/pyparser.py
Log:
provide a small utility function in the parser module to
generate the ast from source code



Modified: pypy/dist/pypy/module/recparser/__init__.py
==============================================================================
--- pypy/dist/pypy/module/recparser/__init__.py	(original)
+++ pypy/dist/pypy/module/recparser/__init__.py	Thu Jan 12 09:50:35 2006
@@ -44,6 +44,7 @@
 ##         #'compilest'    : 'pyparser.compilest',
 
          # PyPy extension
+	 'source2ast' : "pyparser.source2ast",
          'decode_string_literal': 'pyparser.decode_string_literal',
          'install_compiler_hook' : 'pypy.interpreter.pycompiler.install_compiler_hook',
          'rules' : 'pypy.interpreter.pyparser.pythonparse.grammar_rules',

Modified: pypy/dist/pypy/module/recparser/pyparser.py
==============================================================================
--- pypy/dist/pypy/module/recparser/pyparser.py	(original)
+++ pypy/dist/pypy/module/recparser/pyparser.py	Thu Jan 12 09:50:35 2006
@@ -200,6 +200,18 @@
     return space.wrap( STType(space, syntaxtree) )
 
 
+def source2ast(space, source):
+    from pypy.interpreter.pyparser.pythonutil import AstBuilder, PYTHON_PARSER
+    builder = AstBuilder(space=space)
+    PYTHON_PARSER.parse_source(source, 'file_input', builder)
+    ast_tree = builder.rule_stack[-1]
+    return space.wrap(ast_tree)
+source2ast.unwrap_spec = [ObjSpace, str]
+
+
+
+
+
 def decode_string_literal(space, s, w_encoding=None):
     from pypy.interpreter.pyparser.parsestring import parsestr
     if space.is_true(w_encoding):



More information about the Pypy-commit mailing list