[pypy-svn] r16619 - in pypy/dist/pypy/interpreter: pyparser test

arigo at codespeak.net arigo at codespeak.net
Fri Aug 26 14:33:09 CEST 2005


Author: arigo
Date: Fri Aug 26 14:33:07 2005
New Revision: 16619

Modified:
   pypy/dist/pypy/interpreter/pyparser/pythonlexer.py
   pypy/dist/pypy/interpreter/test/test_compiler.py
Log:
Complain in the tokenizer when parenthesis nesting level become negative.
Helps with the following interactive sessions:

>>>> )
.... 
.... 
.... 
.... (




Modified: pypy/dist/pypy/interpreter/pyparser/pythonlexer.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/pythonlexer.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/pythonlexer.py	Fri Aug 26 14:33:07 2005
@@ -273,6 +273,9 @@
                         parenlev = parenlev + 1
                     elif initial in ')]}':
                         parenlev = parenlev - 1
+                        if parenlev < 0:
+                            raise TokenError("unmatched '%s'" % initial, line,
+                                             (lnum-1, 0), token_list)
                     if token in pytoken.tok_punct:
                         tok = Token(pytoken.tok_punct[token])
                     else:

Modified: pypy/dist/pypy/interpreter/test/test_compiler.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_compiler.py	(original)
+++ pypy/dist/pypy/interpreter/test/test_compiler.py	Fri Aug 26 14:33:07 2005
@@ -47,6 +47,8 @@
             space = self.space
             space.raises_w(space.w_SyntaxError, self.compiler.compile_command,
                            'if 1:\n  x x', '?', mode, 0)
+            space.raises_w(space.w_SyntaxError, self.compiler.compile_command,
+                           ')', '?', mode, 0)
 
     def test_getcodeflags(self):
         code = self.compiler.compile('from __future__ import division\n',



More information about the Pypy-commit mailing list