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.
This commit is contained in:
Sei Lisa 2016-05-07 02:42:29 +02:00
parent 697e80cb16
commit 95bd3209be

View file

@ -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')