Commit 3f9328d9 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Improve robustness

parent 3dc2ee66
...@@ -2719,6 +2719,9 @@ def input_part(root, parent, context): ...@@ -2719,6 +2719,9 @@ def input_part(root, parent, context):
inputnames = [c for c in child.getChildren() inputnames = [c for c in child.getChildren()
if c.type != lexer.PARAMS] if c.type != lexer.PARAMS]
for inputname in inputnames: for inputname in inputnames:
if inputname.text is None:
# syntax error (CommonErrorNode) - already caught
continue
for inp_sig in context.input_signals: for inp_sig in context.input_signals:
if inp_sig['name'].lower() == inputname.text.lower(): if inp_sig['name'].lower() == inputname.text.lower():
i.inputlist.append(inp_sig['name']) i.inputlist.append(inp_sig['name'])
...@@ -2745,7 +2748,8 @@ def input_part(root, parent, context): ...@@ -2745,7 +2748,8 @@ def input_part(root, parent, context):
len(inputparams[0]) == 1: len(inputparams[0]) == 1:
user_param, = inputparams[0] user_param, = inputparams[0]
try: try:
user_param_type = find_variable_type(user_param.text, context) user_param_type = find_variable_type(user_param.text,
context)
try: try:
compare_types(sig_param_type, user_param_type) compare_types(sig_param_type, user_param_type)
except TypeError as err: except TypeError as err:
...@@ -2789,9 +2793,12 @@ def input_part(root, parent, context): ...@@ -2789,9 +2793,12 @@ def input_part(root, parent, context):
i.comment, _, _ = end(child) i.comment, _, _ = end(child)
elif child.type == lexer.HYPERLINK: elif child.type == lexer.HYPERLINK:
i.hyperlink = child.getChild(0).toString()[1:-1] i.hyperlink = child.getChild(0).toString()[1:-1]
elif child.type == 0:
# Syntax error caught by the parser, no need to report again
pass
else: else:
warnings.append('Unsupported INPUT child type: ' + warnings.append('Unsupported INPUT child type: {}'
str(child.type)) .format(child.type))
# At the end of the input parsing, get the the list of terminators that # At the end of the input parsing, get the the list of terminators that
# follow the input transition by making a diff with the list at process # follow the input transition by making a diff with the list at process
# level (we counted the number of terminators before parsing the input) # level (we counted the number of terminators before parsing the input)
...@@ -2878,6 +2885,9 @@ def state(root, parent, context): ...@@ -2878,6 +2885,9 @@ def state(root, parent, context):
state_def.comment, _, _ = end(child) state_def.comment, _, _ = end(child)
elif child.type == lexer.HYPERLINK: elif child.type == lexer.HYPERLINK:
state_def.hyperlink = child.getChild(0).toString()[1:-1] state_def.hyperlink = child.getChild(0).toString()[1:-1]
elif child.type == 0:
# Parser error, already caught
pass
else: else:
stwarn.append('Unsupported STATE definition child type: ' + stwarn.append('Unsupported STATE definition child type: ' +
str(child.type)) str(child.type))
...@@ -3079,9 +3089,11 @@ def outputbody(root, context): ...@@ -3079,9 +3089,11 @@ def outputbody(root, context):
elif child.type == lexer.TO: elif child.type == lexer.TO:
pass pass
# TODO: better support of TO primitive # TODO: better support of TO primitive
elif child.type == 0:
# syntax error already caught by the parser
pass
else: else:
warnings.append('Unsupported output body type:' + warnings.append('Unsupported child type: {}'.format(child.type))
str(child.type))
# Check/set the type of each param # Check/set the type of each param
try: try:
check_call(body.get('outputName', '').lower(), check_call(body.get('outputName', '').lower(),
...@@ -3121,9 +3133,10 @@ def output(root, parent, out_ast=None, context=None): ...@@ -3121,9 +3133,10 @@ def output(root, parent, out_ast=None, context=None):
out_ast.comment, _, _ = end(child) out_ast.comment, _, _ = end(child)
elif child.type == lexer.HYPERLINK: elif child.type == lexer.HYPERLINK:
out_ast.hyperlink = child.getChild(0).toString()[1:-1] out_ast.hyperlink = child.getChild(0).toString()[1:-1]
elif child.type == 0:
pass
else: else:
warnings.append('Unsupported output child type: ' + warnings.append('Unsupported child type: {}'.format(child.type))
str(child.type))
# Report errors with symbol coordinates # Report errors with symbol coordinates
errors = [[e, [out_ast.pos_x or 0, out_ast.pos_y or 0], []] errors = [[e, [out_ast.pos_x or 0, out_ast.pos_y or 0], []]
for e in errors] for e in errors]
...@@ -3869,9 +3882,10 @@ def task_body(root, context): ...@@ -3869,9 +3882,10 @@ def task_body(root, context):
errors.extend(err) errors.extend(err)
warnings.extend(warn) warnings.extend(warn)
body.elems.append(forloop) body.elems.append(forloop)
elif child.type == 0:
pass
else: else:
warnings.append('Unsupported child type in task body: ' + warnings.append('Unsupported task child: {}'.format(child.type))
str(child.type))
if not body: if not body:
body = ogAST.TaskAssign() body = ogAST.TaskAssign()
return body, errors, warnings return body, errors, warnings
...@@ -4102,34 +4116,32 @@ def parse_pr(files=None, string=None): ...@@ -4102,34 +4116,32 @@ def parse_pr(files=None, string=None):
errors.extend(err) errors.extend(err)
warnings.extend(warn) warnings.extend(warn)
# If syntax errors were found, stop the process # If syntax errors were found, raise an alarm and try to continue anyway
if errors: if errors:
errors.append(['Syntax errors were found by the parser, you must ' errors.append(['You should fix the syntax errors to make sure '
'fix them before the model can be edited', [0, 0], ['']]) 'no information is lost when loading the model', [0, 0], ['- -']])
og_ast = ogAST.AST() #og_ast = ogAST.AST()
else: # At the end when common tree is complete, perform the parsing
og_ast, err, warn = pr_file(common_tree)
# At the end when common tree is complete, perform the parsing for error in err:
og_ast, err, warn = pr_file(common_tree) errors.append([error] if type(error) is not list else error)
for error in err: for warning in warn:
errors.append([error] if type(error) is not list else error) warnings.append([warning]
for warning in warn: if type(warning) is not list else warning)
warnings.append([warning] # Post-parsing: additional semantic checks
if type(warning) is not list else warning) # check that all NEXTSTATEs have a correspondingly defined STATE
# Post-parsing: additional semantic checks # (except the '-' state, which means "stay in the same state')
# check that all NEXTSTATEs have a correspondingly defined STATE for process in og_ast.processes:
# (except the '-' state, which means "stay in the same state') for ns in [t.inputString.lower() for t in process.terminators
for process in og_ast.processes: if t.kind == 'next_state']:
for ns in [t.inputString.lower() for t in process.terminators if not ns in [s.lower() for s in
if t.kind == 'next_state']: process.mapping.viewkeys()] + ['-']:
if not ns in [s.lower() for s in t_x, t_y = t.pos_x or 0, t.pos_y or 0
process.mapping.viewkeys()] + ['-']: errors.append(['State definition missing: ' + ns.upper(),
t_x, t_y = t.pos_x or 0, t.pos_y or 0 [t_x, t_y],
errors.append(['State definition missing: ' + ns.upper(), ['PROCESS {}'.format(process.processName)]])
[t_x, t_y], # TODO: do the same with JOIN/LABEL
['PROCESS {}'.format(process.processName)]])
# TODO: do the same with JOIN/LABEL
return og_ast, warnings, errors return og_ast, warnings, errors
......
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