[pypy-commit] pypy default: Test and fix for issue852.
arigo
noreply at buildbot.pypy.org
Sat Sep 3 12:41:00 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r47039:4de034d3fb88
Date: 2011-09-03 12:40 +0200
http://bitbucket.org/pypy/pypy/changeset/4de034d3fb88/
Log: Test and fix for issue852.
diff --git a/pypy/interpreter/pyparser/future.py b/pypy/interpreter/pyparser/future.py
--- a/pypy/interpreter/pyparser/future.py
+++ b/pypy/interpreter/pyparser/future.py
@@ -109,25 +109,19 @@
self.getc() == self.getc(+2)):
self.pos += 3
while 1: # Deal with a triple quoted docstring
- if self.getc() == '\\':
- self.pos += 2
+ c = self.getc()
+ if c == '\\':
+ self.pos += 1
+ self._skip_next_char_from_docstring()
+ elif c != endchar:
+ self._skip_next_char_from_docstring()
else:
- c = self.getc()
- if c != endchar:
- self.pos += 1
- if c == '\n':
- self.atbol()
- elif c == '\r':
- if self.getc() == '\n':
- self.pos += 1
- self.atbol()
- else:
- self.pos += 1
- if (self.getc() == endchar and
- self.getc(+1) == endchar):
- self.pos += 2
- self.consume_empty_line()
- break
+ self.pos += 1
+ if (self.getc() == endchar and
+ self.getc(+1) == endchar):
+ self.pos += 2
+ self.consume_empty_line()
+ break
else: # Deal with a single quoted docstring
self.pos += 1
@@ -138,17 +132,21 @@
self.consume_empty_line()
return
elif c == '\\':
- # Deal with linefeeds
- if self.getc() != '\r':
- self.pos += 1
- else:
- self.pos += 1
- if self.getc() == '\n':
- self.pos += 1
+ self._skip_next_char_from_docstring()
elif c in '\r\n':
# Syntax error
return
+ def _skip_next_char_from_docstring(self):
+ c = self.getc()
+ self.pos += 1
+ if c == '\n':
+ self.atbol()
+ elif c == '\r':
+ if self.getc() == '\n':
+ self.pos += 1
+ self.atbol()
+
def consume_continuation(self):
c = self.getc()
if c in '\n\r':
diff --git a/pypy/interpreter/pyparser/test/test_futureautomaton.py b/pypy/interpreter/pyparser/test/test_futureautomaton.py
--- a/pypy/interpreter/pyparser/test/test_futureautomaton.py
+++ b/pypy/interpreter/pyparser/test/test_futureautomaton.py
@@ -221,6 +221,14 @@
assert f.lineno == 3
assert f.col_offset == 0
+def test_lots_of_continuation_lines():
+ s = "\\\n\\\n\\\n\\\n\\\n\\\n\nfrom __future__ import with_statement\n"
+ f = run(s)
+ assert f.pos == len(s)
+ assert f.flags == fut.CO_FUTURE_WITH_STATEMENT
+ assert f.lineno == 8
+ assert f.col_offset == 0
+
# This looks like a bug in cpython parser
# and would require extensive modifications
# to future.py in order to emulate the same behaviour
@@ -239,3 +247,19 @@
raise AssertionError('IndentationError not raised')
assert f.lineno == 2
assert f.col_offset == 0
+
+def test_continuation_lines_in_docstring_single_quoted():
+ s = '"\\\n\\\n\\\n\\\n\\\n\\\n"\nfrom __future__ import division\n'
+ f = run(s)
+ assert f.pos == len(s)
+ assert f.flags == fut.CO_FUTURE_DIVISION
+ assert f.lineno == 8
+ assert f.col_offset == 0
+
+def test_continuation_lines_in_docstring_triple_quoted():
+ s = '"""\\\n\\\n\\\n\\\n\\\n\\\n"""\nfrom __future__ import division\n'
+ f = run(s)
+ assert f.pos == len(s)
+ assert f.flags == fut.CO_FUTURE_DIVISION
+ assert f.lineno == 8
+ assert f.col_offset == 0
More information about the pypy-commit
mailing list