Commits

Carl Friedrich Bolz committed 13cac96

ouch, fix off-by one error in error messages

Comments (0)

Files changed (6)

lib-python/2.7/sre_compile.py

File contents unchanged.

lib-python/2.7/sre_constants.py

File contents unchanged.

lib-python/2.7/sre_parse.py

File contents unchanged.

rpython/rlib/parsing/deterministic.py

         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")

rpython/rlib/parsing/parsing.py

         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 + "^")

rpython/rlib/parsing/test/test_parseerrors.py

         msg = excinfo.value.nice_error_message("<stdin>")
         print msg
         assert msg == """\
-  File <stdin>, line 2
+  File <stdin>, line 3
     'type': 'SCRIPT',$#
                      ^
 LexerError"""
         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 '['"""