Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
fja
eval
Commits
81728fc1
Commit
81728fc1
authored
Apr 03, 2021
by
Vladimír Štill
Browse files
checker: Allow rendering parts of the output also with html formatting
parent
e43db9f2
Changes
1
Hide whitespace changes
Inline
Side-by-side
fja_checker/__main__.py
View file @
81728fc1
...
...
@@ -5,14 +5,35 @@ from lib.checker import get_task, dfa_transform, nfa_transform, check_task, chec
import
sys
import
signal
import
traceback
from
typing
import
Any
render_html
:
bool
=
False
def
wrap
(
text
:
str
,
tag
:
str
,
**
options
:
str
)
->
str
:
if
render_html
:
front
=
f
"<
{
tag
}
"
front
+=
" "
if
options
else
""
front
+=
" "
.
join
(
f
'
{
k
}
="
{
v
}
"'
for
k
,
v
in
options
.
items
())
+
">"
return
f
"
{
front
}{
text
}
</
{
tag
}
>"
return
text
def
paragraph
(
*
args
:
Any
)
->
str
:
return
wrap
(
' '
.
join
(
str
(
a
)
for
a
in
args
),
"p"
)
def
code
(
val
:
str
)
->
str
:
return
wrap
(
val
,
"code"
)
def
print_extra_word_ce
(
student_word
):
print
(
"Příklad slova, které je ve studentově řešení a není v zadaném jazyce:
"
,
student_word
)
print
(
paragraph
(
"Příklad slova, které je ve studentově řešení a není v zadaném jazyce:"
,
code
(
student_word
)
))
def
print_missing_word_ce
(
teacher_word
):
print
(
"Příklad slova, které chybí ve studentově řešení a je v zadaném jazyce:
"
,
teacher_word
)
print
(
paragraph
(
"Příklad slova, které chybí ve studentově řešení a je v zadaném jazyce:"
,
code
(
teacher_word
)
))
def
dfa_task
(
teacher_type
,
teacher_string
,
task
,
student_string
):
...
...
@@ -20,7 +41,7 @@ def dfa_task(teacher_type, teacher_string, task, student_string):
student_solution
=
dfa_transform
(
student_string
,
task
)
teacher_solution
=
dfa_transform
(
teacher_string
,
teacher_type
)
except
ParsingError
as
ex
:
print
(
"Nastala chyba při parsování:"
,
ex
)
print
(
paragraph
(
"Nastala chyba při parsování:"
,
ex
)
)
traceback
.
print_exc
(
file
=
sys
.
stderr
)
exit_incorrect
()
...
...
@@ -35,7 +56,7 @@ def dfa_task(teacher_type, teacher_string, task, student_string):
alphabets
=
check_alphabets
(
student_alpha
=
student_solution
.
characters
,
teacher_alpha
=
teacher_solution
.
characters
,
task
=
task
)
if
alphabets
!=
""
:
print
(
alphabets
)
print
(
paragraph
(
alphabets
)
)
exit_incorrect
()
result
=
reg
.
DFA
.
is_equivalent
(
student_solution
,
teacher_solution
)
...
...
@@ -49,26 +70,26 @@ def dfa_task(teacher_type, teacher_string, task, student_string):
student_word
,
teacher_word
=
result
.
left_counterexample
,
result
.
right_counterexample
if
student_word
is
None
:
print
(
"Studentovo řešení je podmnožinou zadaného jazyka."
)
print
(
paragraph
(
"Studentovo řešení je podmnožinou zadaného jazyka."
)
)
else
:
print_extra_word_ce
(
student_word
)
if
teacher_word
is
None
:
print
(
"Studentovo řešení je nadmnožinou zadaného jazyka."
)
print
(
paragraph
(
"Studentovo řešení je nadmnožinou zadaného jazyka."
)
)
else
:
print_missing_word_ce
(
teacher_word
)
if
result
.
inf
is
not
None
:
print
(
"Rozdíl porovnávaných jazyků je nekonečný."
)
print
(
paragraph
(
"Rozdíl porovnávaných jazyků je nekonečný."
)
)
else
:
print
(
"Rozdíl porovnávaných jazyků je konečný."
)
print
(
paragraph
(
"Rozdíl porovnávaných jazyků je konečný."
)
)
exit_incorrect
()
def
exit_cfl_ok_but_invalid_constraint
(
msg
:
str
)
->
None
:
print
(
"Gramatika generuje zadaný jazyk, ale nesplňuje podmínky
"
f
"zadání:
{
msg
}
"
)
print
(
paragraph
(
"Gramatika generuje zadaný jazyk, ale nesplňuje podmínky"
f
"zadání:
{
msg
}
"
)
)
exit
(
1
)
...
...
@@ -82,13 +103,13 @@ def cfg_task(teacher_type: str, teacher_string: str, task: str,
try
:
teacher_solution
=
parser
.
str_to_cfg
(
teacher_string
)
except
ParsingError
as
message
:
print
(
f
"Error parsing teacher's solution:
{
message
}
"
)
print
(
paragraph
(
f
"Error parsing teacher's solution:
{
message
}
"
)
)
exit
(
1
)
try
:
student_solution
=
parser
.
str_to_cfg
(
student_string
)
except
ParsingError
as
message
:
print
(
f
"Error parsing student's solution:
{
message
}
"
)
print
(
paragraph
(
f
"Error parsing student's solution:
{
message
}
"
)
)
exit
(
1
)
check_empty
(
student_solution
=
student_solution
,
...
...
@@ -132,8 +153,12 @@ def cfg_task(teacher_type: str, teacher_string: str, task: str,
def
main
():
signal
.
alarm
(
50
)
global
render_html
if
sys
.
argv
[
1
]
==
"--html"
:
render_html
=
True
# Get string with student's solution.
with
open
(
sys
.
argv
[
1
])
as
student_file
:
with
open
(
sys
.
argv
[
1
+
render_html
])
as
student_file
:
student_string
=
student_file
.
read
()
# Get string with teacher's solution and type of the task.
...
...
@@ -153,11 +178,11 @@ def main():
cfg_task
(
teacher_type
=
teacher_type
,
teacher_string
=
teacher_string
,
task
=
task
,
student_string
=
student_string
)
else
:
print
(
f
"Invalid question type
{
task_prefix
}
"
)
print
(
paragraph
(
f
"Invalid question type
{
task_prefix
}
"
)
)
exit
(
1
)
except
Exception
as
ex
:
print
(
"Error inside of fja_checker:"
,
ex
.
args
)
print
(
paragraph
(
"Error inside of fja_checker:"
,
ex
.
args
)
)
traceback
.
print_exc
(
file
=
sys
.
stderr
)
exit
(
1
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment