Commit 24251ddc authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Handle better syntax errors

parent 4c1024fd
......@@ -4097,25 +4097,34 @@ def parse_pr(files=None, string=None):
errors.extend(err)
warnings.extend(warn)
# At the end when common tree is complete, perform the parsing
og_ast, err, warn = pr_file(common_tree)
for error in err:
errors.append([error] if type(error) is not list else error)
for warning in warn:
warnings.append([warning] if type(warning) is not list else warning)
# Post-parsing: additional semantic checks
# check that all NEXTSTATEs have a correspondingly defined STATE
# (except the '-' state, which means "stay in the same state')
for process in og_ast.processes:
for ns in [t.inputString.lower() for t in process.terminators
if t.kind == 'next_state']:
if not ns in [s.lower() for s in
process.mapping.viewkeys()] + ['-']:
t_x, t_y = t.pos_x or 0, t.pos_y or 0
errors.append(['State definition missing: ' + ns.upper(),
[t_x, t_y],
['PROCESS {}'.format(process.processName)]])
# TODO: do the same with JOIN/LABEL
# If syntax errors were found, stop the process
if errors:
errors.append(['Syntax errors were found by the parser, you must '
'fix them before the model can be edited', [0, 0], ['']])
og_ast = ogAST.AST()
else:
# At the end when common tree is complete, perform the parsing
og_ast, err, warn = pr_file(common_tree)
for error in err:
errors.append([error] if type(error) is not list else error)
for warning in warn:
warnings.append([warning]
if type(warning) is not list else warning)
# Post-parsing: additional semantic checks
# check that all NEXTSTATEs have a correspondingly defined STATE
# (except the '-' state, which means "stay in the same state')
for process in og_ast.processes:
for ns in [t.inputString.lower() for t in process.terminators
if t.kind == 'next_state']:
if not ns in [s.lower() for s in
process.mapping.viewkeys()] + ['-']:
t_x, t_y = t.pos_x or 0, t.pos_y or 0
errors.append(['State definition missing: ' + ns.upper(),
[t_x, t_y],
['PROCESS {}'.format(process.processName)]])
# TODO: do the same with JOIN/LABEL
return og_ast, warnings, errors
......
......@@ -1494,8 +1494,9 @@ class SDL_View(QtGui.QGraphicsView, object):
self.filename = process.filename
self.readonly_pr = ast.pr_files - {self.filename}
except ValueError:
LOG.error('Cannot load more than one process at a time')
return
LOG.error('Cannot load process')
process = ogAST.Process()
process.processName = "SyntaxError"
try:
syst, = ast.systems
block, = syst.blocks
......@@ -1509,7 +1510,10 @@ class SDL_View(QtGui.QGraphicsView, object):
LOG.debug('Parsing complete. Summary, found ' + str(len(warnings)) +
' warnings and ' + str(len(errors)) + ' errors')
self.log_errors(errors, warnings)
self.scene().render_everything(block)
try:
self.scene().render_everything(block)
except AttributeError:
pass
self.toolbar.update_menu(self.scene())
self.wrapping_window.setWindowTitle('block ' +
process.processName + '[*]')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment