[pypy-svn] r79890 - in pypy/trunk/pypy: interpreter/pyparser module/exceptions
arigo at codespeak.net
arigo at codespeak.net
Wed Dec 8 14:06:17 CET 2010
Author: arigo
Date: Wed Dec 8 14:06:15 2010
New Revision: 79890
Modified:
pypy/trunk/pypy/interpreter/pyparser/error.py
pypy/trunk/pypy/interpreter/pyparser/pytokenizer.py
pypy/trunk/pypy/module/exceptions/interp_exceptions.py
Log:
Fix for test_compiler. All we need is to make sure that in case more
input is expected because of an opening parenthesis or tripe-quote is
not closed so far, then str(SyntaxError()) is different for the
different SyntaxErrors we get when adding a blank line after the input.
So I made these SyntaxErrors report "lines x-y" instead of just "line
x", where "x" is the line where the opening parenthesis was found, and
"y" is the last line in the file.
Modified: pypy/trunk/pypy/interpreter/pyparser/error.py
==============================================================================
--- pypy/trunk/pypy/interpreter/pyparser/error.py (original)
+++ pypy/trunk/pypy/interpreter/pyparser/error.py Wed Dec 8 14:06:15 2010
@@ -2,19 +2,22 @@
class SyntaxError(Exception):
"""Base class for exceptions raised by the parser."""
- def __init__(self, msg, lineno=0, offset=0, text=None, filename=None):
+ def __init__(self, msg, lineno=0, offset=0, text=None, filename=None,
+ lastlineno=0):
self.msg = msg
self.lineno = lineno
self.offset = offset
self.text = text
self.filename = filename
+ self.lastlineno = lastlineno
def wrap_info(self, space):
return space.newtuple([space.wrap(self.msg),
space.newtuple([space.wrap(self.filename),
space.wrap(self.lineno),
space.wrap(self.offset),
- space.wrap(self.text)])])
+ space.wrap(self.text),
+ space.wrap(self.lastlineno)])])
def __str__(self):
return "%s at pos (%d, %d) in %r" % (self.__class__.__name__,
@@ -33,8 +36,9 @@
class TokenError(SyntaxError):
- def __init__(self, msg, line, lineno, column, tokens):
- SyntaxError.__init__(self, msg, lineno, column, line)
+ def __init__(self, msg, line, lineno, column, tokens, lastlineno=0):
+ SyntaxError.__init__(self, msg, lineno, column, line,
+ lastlineno=lastlineno)
self.tokens = tokens
class TokenIndentationError(IndentationError):
Modified: pypy/trunk/pypy/interpreter/pyparser/pytokenizer.py
==============================================================================
--- pypy/trunk/pypy/interpreter/pyparser/pytokenizer.py (original)
+++ pypy/trunk/pypy/interpreter/pyparser/pytokenizer.py Wed Dec 8 14:06:15 2010
@@ -95,7 +95,7 @@
if not line:
raise TokenError("EOF while scanning triple-quoted string",
strstart[2], strstart[0], strstart[1]+1,
- token_list)
+ token_list, lnum)
endmatch = endDFA.recognize(line)
if endmatch >= 0:
pos = end = endmatch
@@ -148,12 +148,12 @@
else: # continued statement
if not line:
- start = 0
if parenlev > 0:
- lnum, start, line = parenlevstart
- start += 1
+ lnum1, start1, line1 = parenlevstart
+ raise TokenError("parenthesis is never closed", line1,
+ lnum1, start1 + 1, token_list, lnum)
raise TokenError("EOF in multi-line statement", line,
- lnum, start, token_list)
+ lnum, 0, token_list)
continued = 0
while pos < max:
Modified: pypy/trunk/pypy/module/exceptions/interp_exceptions.py
==============================================================================
--- pypy/trunk/pypy/module/exceptions/interp_exceptions.py (original)
+++ pypy/trunk/pypy/module/exceptions/interp_exceptions.py Wed Dec 8 14:06:15 2010
@@ -452,6 +452,7 @@
self.w_text = space.w_None
self.w_msg = space.wrap('')
self.w_print_file_and_line = space.w_None # what's that?
+ self.w_lastlineno = space.w_None # this is a pypy extension
W_BaseException.__init__(self, space)
def descr_init(self, space, args_w):
@@ -459,11 +460,12 @@
if len(args_w) > 0:
self.w_msg = args_w[0]
if len(args_w) == 2:
- values_w = space.fixedview(args_w[1], 4)
- self.w_filename = values_w[0]
- self.w_lineno = values_w[1]
- self.w_offset = values_w[2]
- self.w_text = values_w[3]
+ values_w = space.fixedview(args_w[1])
+ if len(values_w) > 0: self.w_filename = values_w[0]
+ if len(values_w) > 1: self.w_lineno = values_w[1]
+ if len(values_w) > 2: self.w_offset = values_w[2]
+ if len(values_w) > 3: self.w_text = values_w[3]
+ if len(values_w) > 4: self.w_lastlineno = values_w[4]
W_BaseException.descr_init(self, space, args_w)
descr_init.unwrap_spec = ['self', ObjSpace, 'args_w']
@@ -472,18 +474,24 @@
if type(self.msg) is not str:
return str(self.msg)
+ lineno = None
buffer = self.msg
have_filename = type(self.filename) is str
- have_lineno = type(self.lineno) is int
+ if type(self.lineno) is int:
+ if (type(self.lastlineno) is int and
+ self.lastlineno > self.lineno):
+ lineno = 'lines %d-%d' % (self.lineno, self.lastlineno)
+ else:
+ lineno = 'line %d' % (self.lineno,)
if have_filename:
import os
fname = os.path.basename(self.filename or "???")
- if have_lineno:
- buffer = "%s (%s, line %ld)" % (self.msg, fname, self.lineno)
+ if lineno:
+ buffer = "%s (%s, %s)" % (self.msg, fname, lineno)
else:
buffer ="%s (%s)" % (self.msg, fname)
- elif have_lineno:
- buffer = "%s (line %ld)" % (self.msg, self.lineno)
+ elif lineno:
+ buffer = "%s (%s)" % (self.msg, lineno)
return buffer
""")
@@ -504,6 +512,7 @@
text = readwrite_attrproperty_w('w_text', W_SyntaxError),
print_file_and_line = readwrite_attrproperty_w('w_print_file_and_line',
W_SyntaxError),
+ lastlineno = readwrite_attrproperty_w('w_lastlineno', W_SyntaxError),
)
W_FutureWarning = _new_exception('FutureWarning', W_Warning,
More information about the Pypy-commit
mailing list