Author: Carl Friedrich Bolz <[email protected]>
Branch:
Changeset: r67113:13cac9640162
Date: 2013-09-27 13:46 +0200
http://bitbucket.org/pypy/pypy/changeset/13cac9640162/
Log: ouch, fix off-by one error in error messages
diff --git a/rpython/rlib/parsing/deterministic.py
b/rpython/rlib/parsing/deterministic.py
--- a/rpython/rlib/parsing/deterministic.py
+++ b/rpython/rlib/parsing/deterministic.py
@@ -60,7 +60,8 @@
self.args = (input, state, source_pos)
def nice_error_message(self, filename="<unknown>"):
- result = [" File %s, line %s" % (filename, self.source_pos.lineno)]
+ # + 1 is because source_pos is 0-based and humans 1-based
+ result = [" File %s, line %s" % (filename, self.source_pos.lineno +
1)]
result.append(self.input.split("\n")[self.source_pos.lineno])
result.append(" " * self.source_pos.columnno + "^")
result.append("LexerError")
diff --git a/rpython/rlib/parsing/parsing.py b/rpython/rlib/parsing/parsing.py
--- a/rpython/rlib/parsing/parsing.py
+++ b/rpython/rlib/parsing/parsing.py
@@ -47,7 +47,8 @@
self.args = (source_pos, errorinformation)
def nice_error_message(self, filename="<unknown>", source=""):
- result = [" File %s, line %s" % (filename, self.source_pos.lineno)]
+ # + 1 is because source_pos is 0-based and humans 1-based
+ result = [" File %s, line %s" % (filename, self.source_pos.lineno +
1)]
if source:
result.append(source.split("\n")[self.source_pos.lineno])
result.append(" " * self.source_pos.columnno + "^")
diff --git a/rpython/rlib/parsing/test/test_parseerrors.py
b/rpython/rlib/parsing/test/test_parseerrors.py
--- a/rpython/rlib/parsing/test/test_parseerrors.py
+++ b/rpython/rlib/parsing/test/test_parseerrors.py
@@ -31,7 +31,7 @@
msg = excinfo.value.nice_error_message("<stdin>")
print msg
assert msg == """\
- File <stdin>, line 2
+ File <stdin>, line 3
'type': 'SCRIPT',$#
^
LexerError"""
@@ -51,7 +51,7 @@
msg = excinfo.value.nice_error_message("<stdin>", source)
print msg
assert msg == """\
- File <stdin>, line 4
+ File <stdin>, line 5
'length':: '1',
^
ParseError: expected '{', 'QUOTED_STRING' or '['"""
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit