[pypy-svn] r59575 - in pypy/trunk/pypy/interpreter: pyparser test

arigo at codespeak.net arigo at codespeak.net
Thu Oct 30 17:19:40 CET 2008


Author: arigo
Date: Thu Oct 30 17:19:39 2008
New Revision: 59575

Modified:
   pypy/trunk/pypy/interpreter/pyparser/pythonlexer.py
   pypy/trunk/pypy/interpreter/test/test_syntax.py
Log:
(antocuni, arigo)
Two tests and one fix for now: giving SyntaxError a non-completely-bogus
.text attribute, in order to get non-completely-bogus tracebacks.


Modified: pypy/trunk/pypy/interpreter/pyparser/pythonlexer.py
==============================================================================
--- pypy/trunk/pypy/interpreter/pyparser/pythonlexer.py	(original)
+++ pypy/trunk/pypy/interpreter/pyparser/pythonlexer.py	Thu Oct 30 17:19:39 2008
@@ -310,8 +310,9 @@
             raise StopIteration
         tok, line, lnum, pos = self.token_stack[self.stack_pos]
         self.stack_pos += 1
-        self._current_line = line
-        self._lineno = max(self._lineno, lnum)
+        if lnum > self._lineno:
+            self._current_line = line
+            self._lineno = lnum
         self._token_lnum = lnum
         self._offset = pos
         return tok

Modified: pypy/trunk/pypy/interpreter/test/test_syntax.py
==============================================================================
--- pypy/trunk/pypy/interpreter/test/test_syntax.py	(original)
+++ pypy/trunk/pypy/interpreter/test/test_syntax.py	Thu Oct 30 17:19:39 2008
@@ -583,6 +583,35 @@
         """
         exec s
 
+class AppTestSyntaxError:
+
+    def test_grammar_error_location(self):
+        try:
+            exec """if 1:
+                class Foo:
+                    bla
+                    a b c d e
+                    bar
+            """
+        except SyntaxError, e:
+            assert e.lineno == 4
+            assert e.text.endswith('a b c d e\n')
+        else:
+            raise Exception("no SyntaxError??")
+
+    def test_astbuilder_error_location(self):
+        skip("in-progress")
+        program = "(1, 2) += (3, 4)\n"
+        try:
+            exec program
+        except SyntaxError, e:
+            assert e.lineno == 1
+            assert e.text is None
+            assert e.offset is None
+        else:
+            raise Exception("no SyntaxError??")
+
+
 if __name__ == '__main__':
     # only to check on top of CPython (you need 2.4)
     from py.test import raises



More information about the Pypy-commit mailing list