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

arigo at codespeak.net arigo at codespeak.net
Tue Dec 7 15:21:37 CET 2010


Author: arigo
Date: Tue Dec  7 15:21:35 2010
New Revision: 79866

Modified:
   pypy/trunk/pypy/interpreter/pyparser/pytokenizer.py
   pypy/trunk/pypy/interpreter/pyparser/test/test_pyparse.py
Log:
issue563 testing

On multi-line EOF SyntaxErrors, report the start line instead of the EOF line.


Modified: pypy/trunk/pypy/interpreter/pyparser/pytokenizer.py
==============================================================================
--- pypy/trunk/pypy/interpreter/pyparser/pytokenizer.py	(original)
+++ pypy/trunk/pypy/interpreter/pyparser/pytokenizer.py	Tue Dec  7 15:21:35 2010
@@ -78,6 +78,7 @@
     contline = None
     indents = [0]
     last_comment = ''
+    parenlevstart = (0, 0, "")
 
     # make the annotator happy
     endDFA = automata.DFA([], [])
@@ -85,7 +86,7 @@
     line = ''
     pos = 0
     lines.append("")
-    strstart = (0, 0)
+    strstart = (0, 0, "")
     for line in lines:
         lnum = lnum + 1
         pos, max = 0, len(line)
@@ -93,7 +94,8 @@
         if contstr:
             if not line:
                 raise TokenError("EOF while scanning triple-quoted string",
-                                 line, lnum-1, 0, token_list)
+                                 strstart[2], strstart[0], strstart[1],
+                                 token_list)
             endmatch = endDFA.recognize(line)
             if endmatch >= 0:
                 pos = end = endmatch
@@ -146,8 +148,11 @@
 
         else:                                  # continued statement
             if not line:
+                start = 0
+                if parenlev > 0:
+                    lnum, start, line = parenlevstart
                 raise TokenError("EOF in multi-line statement", line,
-                                 lnum, 0, token_list)
+                                 lnum, start, token_list)
             continued = 0
 
         while pos < max:
@@ -187,7 +192,7 @@
                         token_list.append(tok)
                         last_comment = ''
                     else:
-                        strstart = (lnum, start)
+                        strstart = (lnum, start, line)
                         contstr = line[start:]
                         contline = line
                         break
@@ -195,7 +200,7 @@
                     token[:2] in single_quoted or \
                     token[:3] in single_quoted:
                     if token[-1] == '\n':                  # continued string
-                        strstart = (lnum, start)
+                        strstart = (lnum, start, line)
                         endDFA = (endDFAs[initial] or endDFAs[token[1]] or
                                    endDFAs[token[2]])
                         contstr, needcont = line[start:], 1
@@ -212,6 +217,8 @@
                     continued = 1
                 else:
                     if initial in '([{':
+                        if parenlev == 0:
+                            parenlevstart = (lnum, start, line)
                         parenlev = parenlev + 1
                     elif initial in ')]}':
                         parenlev = parenlev - 1

Modified: pypy/trunk/pypy/interpreter/pyparser/test/test_pyparse.py
==============================================================================
--- pypy/trunk/pypy/interpreter/pyparser/test/test_pyparse.py	(original)
+++ pypy/trunk/pypy/interpreter/pyparser/test/test_pyparse.py	Tue Dec  7 15:21:35 2010
@@ -64,12 +64,20 @@
         assert exc.lineno == 1
         assert exc.offset == 5
         assert exc.text.startswith("name another for")
-        exc = py.test.raises(SyntaxError, parse, "\"blah").value
+        exc = py.test.raises(SyntaxError, parse, "x = \"blah\n\n\n").value
         assert exc.msg == "EOL while scanning single-quoted string"
-        exc = py.test.raises(SyntaxError, parse, "'''\n").value
+        assert exc.lineno == 1
+        assert exc.offset == 4
+        exc = py.test.raises(SyntaxError, parse, "x = '''\n\n\n").value
         assert exc.msg == "EOF while scanning triple-quoted string"
+        assert exc.lineno == 1
+        assert exc.offset == 4
         for input in ("())", "(()", "((", "))"):
             py.test.raises(SyntaxError, parse, input)
+        exc = py.test.raises(SyntaxError, parse, "x = (\n\n(),\n(),").value
+        assert exc.msg == "EOF in multi-line statement"
+        assert exc.lineno == 1
+        assert exc.offset == 4
 
     def test_is(self):
         self.parse("x is y")



More information about the Pypy-commit mailing list