add line numbers to syntax error messages

This commit is contained in:
randomuser 2021-11-23 11:32:55 -06:00
parent 41565af01f
commit c6e5bd376c
1 changed files with 5 additions and 4 deletions

View File

@ -40,8 +40,10 @@ class RecordCollection():
def _fromFile(self, fd):
lines = [i.rstrip() for i in fd.readlines()]
current = Record()
cl = 0
for i in lines:
cl += 1
ind = i[0:2] == ' '
if ind:
@ -49,13 +51,12 @@ class RecordCollection():
try:
current[spl[0]] = spl[1]
except IndexError:
# TODO: maybe add line numbers?
raise FileParsingError(f"error parsing '{i}'")
raise FileParsingError(f"error parsing '{i}' @ {cl}")
else:
try:
if i[-1] != ":":
raise FileParsingError(f"colon must be on last character of '{i}'")
raise FileParsingError(f"colon must be on last character of '{i}' @ {cl}")
name = i.split(' ')[1][0:-1]
except IndexError:
current = Record()
@ -74,7 +75,7 @@ class RecordCollection():
# TODO: add more precise error checking
if not len(inherit) == len(inherit_order):
raise FileParsingError("len(inherit) != len(inherit_order)")
raise FileParsingError("len(inherit) != len(inherit_order) @ {cl}")
for j, k in zip(
inherit,