[pypy-svn] r11478 - in pypy/dist/pypy/module/recparser: . test
adim at codespeak.net
adim at codespeak.net
Tue Apr 26 15:17:34 CEST 2005
Author: adim
Date: Tue Apr 26 15:17:34 2005
New Revision: 11478
Modified:
pypy/dist/pypy/module/recparser/pythonparse.py
pypy/dist/pypy/module/recparser/pythonutil.py
pypy/dist/pypy/module/recparser/test/test_samples.py
Log:
moved pypy_parse from pythonutil to pythoparse and fixed related imports
Modified: pypy/dist/pypy/module/recparser/pythonparse.py
==============================================================================
--- pypy/dist/pypy/module/recparser/pythonparse.py (original)
+++ pypy/dist/pypy/module/recparser/pythonparse.py Tue Apr 26 15:17:34 2005
@@ -5,7 +5,6 @@
import sys
import pythonutil
-
def parse_python_source( textsrc, gram, goal ):
"""Parse a python source according to goal"""
target = gram.rules[goal]
@@ -33,6 +32,22 @@
"""Parse a python file"""
return parse_python_source( textsrc, gram, "eval_input" )
+def pypy_parse(filename):
+ """parse <filename> using PyPy's parser module and return nested tuples
+ """
+ pyf = file(filename)
+ builder = parse_file_input(pyf, pythonutil.python_grammar())
+ pyf.close()
+ if builder.stack:
+ # print builder.stack[-1]
+ root_node = builder.stack[-1]
+ nested_tuples = root_node.totuple()
+ if hasattr(builder, '_source_encoding'):
+ return (323, nested_tuples, builder._source_encoding)
+ else:
+ return nested_tuples
+ return None # XXX raise an exception instead
+
if __name__ == "__main__":
if len(sys.argv) < 2:
print "python parse.py [-d N] test_file.py"
@@ -44,6 +59,6 @@
test_file = sys.argv[1]
print "-"*20
print
- print "pyparse \n", pythonutil.pypy_parse(test_file)
+ print "pyparse \n", pypy_parse(test_file)
print "parser \n", pythonutil.python_parse(test_file)
Modified: pypy/dist/pypy/module/recparser/pythonutil.py
==============================================================================
--- pypy/dist/pypy/module/recparser/pythonutil.py (original)
+++ pypy/dist/pypy/module/recparser/pythonutil.py Tue Apr 26 15:17:34 2005
@@ -1,7 +1,5 @@
-__all__ = [ "parse_file_input", "parse_single_input", "parse_eval_input",
- "python_grammar", "PYTHON_GRAMMAR" ]
+__all__ = ["python_grammar", "PYTHON_GRAMMAR" ]
-from pythonparse import parse_file_input, parse_single_input, parse_eval_input
import os
import sys
@@ -35,26 +33,3 @@
import parser
tp2 = parser.suite(pyf.read())
return tp2.totuple()
-
-
-def _get_encoding(builder):
- if hasattr(builder, '_source_encoding'):
- return builder._source_encoding
- return None
-
-def pypy_parse(filename):
- """parse <filename> using PyPy's parser module and return nested tuples
- """
- pyf = file(filename)
- builder = parse_file_input(pyf, python_grammar())
- pyf.close()
- if builder.stack:
- # print builder.stack[-1]
- root_node = builder.stack[-1]
- nested_tuples = root_node.totuple()
- source_encoding = _get_encoding(builder)
- if source_encoding is None:
- return nested_tuples
- else:
- return (323, nested_tuples, source_encoding)
- return None # XXX raise an exception instead
Modified: pypy/dist/pypy/module/recparser/test/test_samples.py
==============================================================================
--- pypy/dist/pypy/module/recparser/test/test_samples.py (original)
+++ pypy/dist/pypy/module/recparser/test/test_samples.py Tue Apr 26 15:17:34 2005
@@ -1,6 +1,7 @@
"""test module for CPython / PyPy nested tuples comparison"""
import os, os.path as osp
-from pypy.module.recparser.pythonutil import python_parse, pypy_parse
+from pypy.module.recparser.pythonutil import python_parse
+from pypy.module.recparser.pythonparse import pypy_parse
from pprint import pprint
from pypy.module.recparser import grammar
grammar.DEBUG = False
More information about the Pypy-commit
mailing list