Commit aaa587be authored by Kateřina Sloupová's avatar Kateřina Sloupová
Browse files

web tweaks for parsing error and empty input

parent 0f5aad35
Loading
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
from flask import Blueprint, render_template, request
from flask_wtf import FlaskForm
from wtforms import RadioField
from lib.parsing.parser import ParsingError
from evalweb.web_checker import WebChecker, Language
from evalweb.examples import examples, convert_examples

@@ -57,10 +58,13 @@ def compare():
        student_area = student_string
        teacher_area = teacher_string

        if student_string == "" or teacher_string == "":
            return render_template('parsing_error.html', error="Nebyl zadán vstupní formalismus.")

        checker = WebChecker(student_string=student_string, task=student_type)
        result = checker.compare(teacher_string=teacher_string, teacher_type=teacher_type)
        if not isinstance(result, bool):
            return render_template('parsing_error.html', error=result)
            return render_template('parsing_error.html')

        extra_word_ce, missing_word_ce, inf = None, None, None
        if not result and checker.eq is not None:  # languages aren't equivalent
@@ -97,8 +101,14 @@ def convert():
        task = task_form.make.data
        student_area = student_string

        if student_string == "":
            return render_template('parsing_error.html', error="Nebyl zadán vstupní formalismus.")

        checker = WebChecker(student_string=student_string, task=task)
        try:
            output = checker.convert(student_type=student_type)
        except ParsingError as ex:
            return render_template('parsing_error.html')

        student = Language(string=student_string, task=student_type)
        is_task = student.gen_is_task(task=task)
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
    <title>FJA eval</title>
</head>
<body>
<!doctype html>

<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">

<nav>
+3 −3
Original line number Diff line number Diff line
@@ -108,8 +108,8 @@ class WebChecker:
            return self.dfa_task(teacher_type=teacher_type, teacher_string=teacher_string,
                                 task=self.task, student_string=self.student_string)

        except Exception as ex:
            print("Error inside of web checker:", ex.args)
        except ParsingError as ex:
            raise ParsingError(ex.args)


    def convert(self, student_type):
@@ -139,7 +139,7 @@ class WebChecker:
                return parser.reggrammar_to_str(nfa.nfa_to_reggrammar().eliminate_useless())

        except ParsingError as ex:
            return("Chyba při parsování.")
            raise ParsingError(ex.args)

        except Exception as ex:
            print("Error inside of web checker:", ex.args)
+3 −3
Original line number Diff line number Diff line
@@ -355,7 +355,7 @@ class DFA:
    def one_of(collection: Set[type_var]) -> type_var:
        return next(iter(collection))

    def is_empty(self) -> IsEmptyResult:
    def is_empty(self) -> IsEmptyResult:  # 52, 2.74, 2.76
        completed: Set[State] = set()
        stack: List[State] = [self.init]

@@ -426,12 +426,12 @@ class DFA:
        return IsEmptyResult(''.join(reversed(word)), False)

    # Ha!
    def is_universal(self):
    def is_universal(self):  # 52, 2.74
        return self.complement().is_empty()

    # returns: True or fst_empty: what IS in first language and NOT in second, snd_empty: analogically)
    @staticmethod
    def is_equivalent(fst: DFA, snd: DFA) -> IsEquivalentResult:
    def is_equivalent(fst: DFA, snd: DFA) -> IsEquivalentResult:  # 52, 2.77
        fst_empty = DFA.intersection(fst, snd.complement()).is_empty()
        snd_empty = DFA.intersection(fst.complement(), snd).is_empty()