From 7e4689d3f50b0a8322ec74879202377ef1159d57 Mon Sep 17 00:00:00 2001 From: Roland Lutz Date: Sun, 27 Aug 2017 22:14:38 +0200 Subject: icebox: Give useful error messages for .hlc parsing errors --- icebox/icebox_hlc2asc.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/icebox/icebox_hlc2asc.py b/icebox/icebox_hlc2asc.py index 54d6722..71211e0 100755 --- a/icebox/icebox_hlc2asc.py +++ b/icebox/icebox_hlc2asc.py @@ -971,20 +971,26 @@ class IOBlock: def main1(path): f = open(path, 'r') stack = [Main()] - for line in f: + for i, line in enumerate(f): fields = line.split('#')[0].split() - if not fields: - pass # empty line - elif fields == ['}']: - stack.pop() - if not stack: - raise ParseError - elif fields[-1] == '{': - stack.append(stack[-1].new_block(fields[:-1])) - else: - stack[-1].read(fields) + try: + if not fields: + pass # empty line + elif fields == ['}']: + stack.pop() + if not stack: + raise ParseError + elif fields[-1] == '{': + stack.append(stack[-1].new_block(fields[:-1])) + else: + 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: - raise ParseError + sys.stderr.write("Parse error: unexpected end of file") + sys.exit(1) f.close() stack[0].writeout() -- cgit v1.2.3