[pypy-svn] r61354 - in pypy/trunk/pypy/module/recparser: . test

fijal at codespeak.net fijal at codespeak.net
Mon Jan 26 15:15:22 CET 2009


Author: fijal
Date: Mon Jan 26 15:15:22 2009
New Revision: 61354

Modified:
   pypy/trunk/pypy/module/recparser/pyparser.py
   pypy/trunk/pypy/module/recparser/test/test_parser.py
Log:
another pile of hacks - always generate code and just throw it away
(don't cache) for the reason of catching syntax errors. the rationale
behind it is that we don't care about module's performance
and we do want it to be compliant


Modified: pypy/trunk/pypy/module/recparser/pyparser.py
==============================================================================
--- pypy/trunk/pypy/module/recparser/pyparser.py	(original)
+++ pypy/trunk/pypy/module/recparser/pyparser.py	Mon Jan 26 15:15:22 2009
@@ -8,7 +8,7 @@
 from pypy.interpreter.typedef import interp_attrproperty, GetSetProperty
 from pypy.interpreter.pycode import PyCode
 from pypy.interpreter.pyparser.syntaxtree import TokenNode, SyntaxNode, AbstractSyntaxVisitor
-from pypy.interpreter.pyparser.error import SyntaxError
+from pypy.interpreter.pyparser.error import SyntaxError, IndentationError
 from pypy.interpreter.pyparser import grammar, symbol, pytoken
 from pypy.interpreter.pyparser.future import getFutures
 from pypy.interpreter.argument import Arguments
@@ -172,7 +172,15 @@
     builder.space = space
     try:
         parser.parse_source(source, mode, builder, flags)
-        return builder.stack[-1]
+        st = builder.stack[-1]
+        # we compile it to bytecode anyway.
+        # the side effect of this is that we grab exceptions
+        # on our way.
+        STType(space, st).descr_compile(space)
+        return st
+    except IndentationError, e:
+        raise OperationError(space.w_IndentationError,
+                             e.wrap_info(space, '<string>'))        
     except SyntaxError, e:
         raise OperationError(space.w_SyntaxError,
                              e.wrap_info(space, '<string>'))

Modified: pypy/trunk/pypy/module/recparser/test/test_parser.py
==============================================================================
--- pypy/trunk/pypy/module/recparser/test/test_parser.py	(original)
+++ pypy/trunk/pypy/module/recparser/test/test_parser.py	Mon Jan 26 15:15:22 2009
@@ -53,3 +53,11 @@
         import parser
         raises(SyntaxError, parser.source2ast, "\xDE\xDA")
 
+    def test_later_error(self):
+        import parser
+        x = """if:
+        def f(x):
+            x
+             y
+        """
+        raises(SyntaxError, parser.suite, x)



More information about the Pypy-commit mailing list