mirror of https://github.com/YosysHQ/icestorm.git
icebox: Give useful error messages for .hlc parsing errors
This commit is contained in:
parent
5cea17ea88
commit
7e4689d3f5
|
|
@ -971,20 +971,26 @@ 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()
|
||||||
if not fields:
|
try:
|
||||||
pass # empty line
|
if not fields:
|
||||||
elif fields == ['}']:
|
pass # empty line
|
||||||
stack.pop()
|
elif fields == ['}']:
|
||||||
if not stack:
|
stack.pop()
|
||||||
raise ParseError
|
if not stack:
|
||||||
elif fields[-1] == '{':
|
raise ParseError
|
||||||
stack.append(stack[-1].new_block(fields[:-1]))
|
elif fields[-1] == '{':
|
||||||
else:
|
stack.append(stack[-1].new_block(fields[:-1]))
|
||||||
stack[-1].read(fields)
|
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:
|
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()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue