[pypy-svn] r12123 - pypy/dist/pypy/module/recparser
adim at codespeak.net
adim at codespeak.net
Mon May 9 18:28:29 CEST 2005
Author: adim
Date: Mon May 9 18:28:29 2005
New Revision: 12123
Added:
pypy/dist/pypy/module/recparser/compat.py
Modified:
pypy/dist/pypy/module/recparser/__init__.py
pypy/dist/pypy/module/recparser/pyparser.py
pypy/dist/pypy/module/recparser/syntaxtree.py
Log:
- added basic implementation of ast2tuple()
- added compat layer for CPython's parser module
- fixed missing line number in SyntaxNode.totuple()
Modified: pypy/dist/pypy/module/recparser/__init__.py
==============================================================================
--- pypy/dist/pypy/module/recparser/__init__.py (original)
+++ pypy/dist/pypy/module/recparser/__init__.py Mon May 9 18:28:29 2005
@@ -23,6 +23,7 @@
'suite' : 'pyparser.suite',
'expr' : 'pyparser.expr',
'STType' : 'pyparser.STType',
+ 'ast2tuple' : 'pyparser.ast2tuple',
# 'ASTType' : 'pyparser.STType',
# 'sequence2st' : 'pyparser.sequence2st',
#'eval_input' : 'pyparser.eval_input',
Added: pypy/dist/pypy/module/recparser/compat.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/recparser/compat.py Mon May 9 18:28:29 2005
@@ -0,0 +1,18 @@
+"""Compatibility layer for CPython's parser module"""
+
+from pythonparse import parse_python_source
+from pypy.module.recparser import PYTHON_PARSER
+from compiler import transformer, compile as pycompile
+
+def suite( source ):
+ builder = parse_python_source( source, PYTHON_PARSER, "file_input" )
+ return builder.stack[-1]
+
+def expr( source ):
+ builder = parse_python_source( source, PYTHON_PARSER, "eval_input" )
+ return builder.stack[-1]
+
+def ast2tuple(node, line_info=False):
+ """Quick dummy implementation of parser.ast2tuple(tree) function"""
+ tuples = node.totuple(line_info)
+ return tuples
Modified: pypy/dist/pypy/module/recparser/pyparser.py
==============================================================================
--- pypy/dist/pypy/module/recparser/pyparser.py (original)
+++ pypy/dist/pypy/module/recparser/pyparser.py Mon May 9 18:28:29 2005
@@ -111,4 +111,9 @@
expr.unwrap_spec = [ObjSpace, str]
+def ast2tuple(space, node, line_info=False):
+ """Quick dummy implementation of parser.ast2tuple(tree) function"""
+ tuples = node.totuple(line_info)
+ return space.wrap(tuples)
+ast2tuple.unwrap_spec = [ObjSpace, STType, bool]
Modified: pypy/dist/pypy/module/recparser/syntaxtree.py
==============================================================================
--- pypy/dist/pypy/module/recparser/syntaxtree.py (original)
+++ pypy/dist/pypy/module/recparser/syntaxtree.py Mon May 9 18:28:29 2005
@@ -116,7 +116,7 @@
def totuple(self, lineno=False ):
symvalue = SYMBOLS.get( self.name, (0,self.name) )
l = [ symvalue ]
- l += [node.totuple() for node in self.nodes]
+ l += [node.totuple(lineno) for node in self.nodes]
return tuple(l)
More information about the Pypy-commit
mailing list