[pypy-svn] r65779 - in pypy/branch/parser-compiler/pypy/interpreter: astcompiler/test pyparser pyparser/test

benjamin at codespeak.net benjamin at codespeak.net
Mon Jun 15 00:51:15 CEST 2009


Author: benjamin
Date: Mon Jun 15 00:51:11 2009
New Revision: 65779

Modified:
   pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py
   pypy/branch/parser-compiler/pypy/interpreter/pyparser/pyparse.py
   pypy/branch/parser-compiler/pypy/interpreter/pyparser/test/test_pyparse.py
Log:
pass the space the to the PythonParser

Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py	Mon Jun 15 00:51:11 2009
@@ -2,7 +2,7 @@
 import string
 import py
 from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.pyparser import pyparse, pygram
+from pypy.interpreter.pyparser import pyparse
 from pypy.interpreter.pyparser.error import SyntaxError
 from pypy.interpreter.astcompiler.astbuilder import ast_from_node
 from pypy.interpreter.astcompiler import ast2 as ast
@@ -11,7 +11,7 @@
 class TestAstBuilder:
 
     def setup_class(cls):
-        cls.parser = pyparse.PythonParser(pygram.python_grammar)
+        cls.parser = pyparse.PythonParser(cls.space)
 
     def get_ast(self, source, p_mode="exec"):
         tree = self.parser.parse_source(source, p_mode)

Modified: pypy/branch/parser-compiler/pypy/interpreter/pyparser/pyparse.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/pyparser/pyparse.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/pyparser/pyparse.py	Mon Jun 15 00:51:11 2009
@@ -64,6 +64,10 @@
 
 class PythonParser(parser.Parser):
 
+    def __init__(self, space, grammar=pygram.python_grammar):
+        parser.Parser.__init__(self, grammar)
+        self.space = space
+
     def parse_source(self, textsrc, mode="exec", flags=0):
         """Parse a python source according to goal"""
         # Detect source encoding.
@@ -79,12 +83,12 @@
             enc = _normalize_encoding(_check_for_encoding(textsrc))
             if enc is not None and enc not in ('utf-8', 'iso-8859-1'):
                 try:
-                    textsrc = recode_to_utf8(builder.space, textsrc, enc)
+                    textsrc = recode_to_utf8(self.space, textsrc, enc)
                 except OperationError, e:
                     # if the codec is not found, LookupError is raised.  we
                     # check using 'is_w' not to mask potential IndexError or
                     # KeyError
-                    space = builder.space
+                    space = self.space
                     if space.is_w(e.w_type, space.w_LookupError):
                         raise SyntaxError("Unknown encoding: %s" % enc)
                     raise

Modified: pypy/branch/parser-compiler/pypy/interpreter/pyparser/test/test_pyparse.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/pyparser/test/test_pyparse.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/pyparser/test/test_pyparse.py	Mon Jun 15 00:51:11 2009
@@ -1,5 +1,5 @@
 import py
-from pypy.interpreter.pyparser import pyparse, pygram
+from pypy.interpreter.pyparser import pyparse
 from pypy.interpreter.pyparser.pygram import syms, tokens
 from pypy.interpreter.pyparser.error import SyntaxError, IndentationError
 
@@ -7,7 +7,7 @@
 class TestPythonParser:
 
     def setup_class(self):
-        self.parser = pyparse.PythonParser(pygram.python_grammar)
+        self.parser = pyparse.PythonParser(self.space)
 
     def test_clear_state(self):
         assert self.parser.root is None



More information about the Pypy-commit mailing list