fix(parser): Correctly handle DOS new lines in 'line' rules

Do not consider the trailing `\r` of a line a part of it.
This commit is contained in:
Adrien Vergé
2019-03-25 18:44:45 +01:00
parent 2a66ec2e5e
commit fec2c2fba7
6 changed files with 58 additions and 12 deletions

View File

@@ -77,7 +77,10 @@ def line_generator(buffer):
cur = 0
next = buffer.find('\n')
while next != -1:
yield Line(line_no, buffer, start=cur, end=next)
if next > 0 and buffer[next - 1] == '\r':
yield Line(line_no, buffer, start=cur, end=next - 1)
else:
yield Line(line_no, buffer, start=cur, end=next)
cur = next + 1
next = buffer.find('\n', cur)
line_no += 1