From 95bd3209be45b7ced92c4fb1545c9175748e1a2b Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Sat, 7 May 2016 02:42:29 +0200 Subject: [PATCH] Fix reporting the last line on error if it doesn't end in \n. If the last line of the file didn't end in LF, and an error was reported right in that line, two characters would be missing from that line in the output. Fixed. --- main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 86ee201..3d2f7a9 100755 --- a/main.py +++ b/main.py @@ -30,8 +30,10 @@ VERSION = '0.2.0beta' def ReportError(script, e): - sys.stderr.write(script[fieldpos(script, '\n', e.lno): - fieldpos(script, '\n', e.lno+1)-1] + '\n') + lastpos = fieldpos(script, '\n', e.lno+1)-1 + assert lastpos != -1 + if lastpos < -1: lastpos = len(script) # may hit EOF + sys.stderr.write(script[fieldpos(script, '\n', e.lno):lastpos] + '\n') sys.stderr.write(' ' * e.cno + '^\n') sys.stderr.write(e[0] + '\n')