icebox: Give useful error messages for .hlc parsing errors

This commit is contained in:
Roland Lutz 2017-08-27 22:14:38 +02:00
parent 5cea17ea88
commit 7e4689d3f5
1 changed files with 18 additions and 12 deletions

View File

@ -971,8 +971,9 @@ class IOBlock:
def main1(path): def main1(path):
f = open(path, 'r') f = open(path, 'r')
stack = [Main()] stack = [Main()]
for line in f: for i, line in enumerate(f):
fields = line.split('#')[0].split() fields = line.split('#')[0].split()
try:
if not fields: if not fields:
pass # empty line pass # empty line
elif fields == ['}']: elif fields == ['}']:
@ -983,8 +984,13 @@ def main1(path):
stack.append(stack[-1].new_block(fields[:-1])) stack.append(stack[-1].new_block(fields[:-1]))
else: else:
stack[-1].read(fields) stack[-1].read(fields)
except ParseError:
sys.stderr.write("Parse error in line %d:\n" % (i + 1))
sys.stderr.write(line)
sys.exit(1)
if len(stack) != 1: if len(stack) != 1:
raise ParseError sys.stderr.write("Parse error: unexpected end of file")
sys.exit(1)
f.close() f.close()
stack[0].writeout() stack[0].writeout()