Commit deee3a75 authored by Vladimír Štill's avatar Vladimír Štill
Browse files

evalweb: Fix error handling in convert

parent f629eae4
......@@ -68,10 +68,11 @@ def compare() -> str:
error="Nebyl zadán vstupní formalismus.")
checker = WebChecker(student_string=student_string, task=student_type)
try:
result = checker.compare(teacher_string=teacher_string,
teacher_type=teacher_type)
if not isinstance(result, bool):
return render_template('parsing_error.html')
except ParsingError as ex:
return render_template('parsing_error.html', error=str(ex))
extra_word_ce, missing_word_ce, inf = None, None, None
if not result and checker.eq is not None: # languages not equivalent
......@@ -113,23 +114,26 @@ def compare() -> str:
def convert() -> str:
student_form = TypeForm(prefix='student_form')
task_form = ConvertForm(prefix='task_form')
student_area = ""
convert_args = {"student_form": student_form,
"task_form": task_form,
"student_area": ""}
if request.method == 'POST' and 'submit_button' in request.form:
student_string = request.form['student_string']
student_type = student_form.make.data
task = task_form.make.data
student_area = student_string
convert_args["student_area"] = student_string
if student_string == "":
return render_template('parsing_error.html',
error="Nebyl zadán vstupní formalismus.")
return render_template('convert.html',
error="Nebyl zadán vstupní formalismus.",
**convert_args)
checker = WebChecker(student_string=student_string, task=task)
try:
output = checker.convert(student_type=student_type)
except ParsingError:
return render_template('parsing_error.html')
except ParsingError as ex:
return render_template('convert.html', error=ex, **convert_args)
student = Language(string=student_string, task=student_type)
is_task = student.gen_is_task(task=task)
......@@ -144,10 +148,9 @@ def convert() -> str:
if request.method == 'POST' and 'example_button' in request.form:
student_type = student_form.make.data
if student_type in convert_examples:
student_area = convert_examples[student_type]
convert_args["student_area"] = convert_examples[student_type]
return render_template('convert.html', student_form=student_form,
task_form=task_form, student_area=student_area)
return render_template('convert.html', **convert_args)
@bp.route('/userref')
......
......@@ -168,3 +168,8 @@ code, pre {
pre code {
padding: 0;
}
.error {
background-color: #f99;
padding: 0.4rem;
}
......@@ -16,6 +16,11 @@
<div>
<div style="width:400px; float:right;">
<textarea style="width:400px;" name="student_string" id="student_string">{{ student_area }}</textarea>
{% if error is defined %}
<div class="error">
{{error}}
</div>
{% endif %}
</div>
{{ student_form.hidden_tag() }}
<div style="float:left;">{{ student_form.make(style="list-style:none") }}</div>
......
......@@ -67,15 +67,11 @@ class WebChecker:
# nearly equivalent to dfa_task in fja_checker (for IS ROPOTs)
def dfa_task(self, teacher_type: str, teacher_string: str,
task: str, student_string: str) -> bool:
try:
teacher = Language(string=teacher_string, task=teacher_type)
student = Language(string=student_string, task=self.task)
# only for task checking
student_solution = transform(student_string, task)
except ParsingError as ex: # Parsing error, don't continue
return ex.args
self.teacher = teacher
self.student = student
self.is_task = teacher.gen_is_task(task=self.task)
......@@ -109,19 +105,12 @@ class WebChecker:
return False
def compare(self, teacher_string: str, teacher_type: str) -> bool:
# signal.alarm(50) # from fja_checker: here would kill the web
try:
return self.dfa_task(teacher_type=teacher_type,
teacher_string=teacher_string,
task=self.task,
student_string=self.student_string)
except ParsingError as ex:
return ex.args
# raise ParsingError(ex.args)
def convert(self, student_type: str) -> str:
try:
parser = Parser()
if self.task in {"DFA", "TOT", "MIN"}:
dfa = dfa_transform(self.student_string, student_type)
......@@ -145,13 +134,6 @@ class WebChecker:
return parser.reggrammar_to_str(nfa.nfa_to_reggrammar()
.eliminate_useless())
except ParsingError as ex:
return ex.args # FIXME
# raise ParsingError(ex.args)
except Exception as ex:
print("Error inside of web checker:", ex.args)
def relation(self, eq: bool) -> str:
assert self.teacher is not None
assert self.student is not None
......
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