-
Notifications
You must be signed in to change notification settings - Fork 28
/
lang.py
60 lines (53 loc) · 1.59 KB
/
lang.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from scoring import (
run_tests,
score_func,
score_func_code,
score_func_whole,
short_verifier_feedback,
verifier_feedback,
filter_code,
filter_code_whole,
run_unittests,
code_of_msg,
)
def can_be_solution(
msg: str, min_lines: int, check_func=None, check_string=None, unittests=None
) -> bool:
if not (msg.count("```") % 2 == 0):
return False
v = filter_code(msg)
r = v.count("\n") >= min_lines
if r and check_func:
r = check_func(v)
if r and check_string:
print("FINAL CHECK")
print(v + check_string)
r = check_code(v + check_string)["status"] == 0
if r and unittests:
print("FINAL UNITTEST")
r = run_unittests(v, unittests) == 0
return r
def can_be_solution_whole(
msg: str, min_lines: int, check_func=None, check_string=None
) -> bool:
if not (msg.count("```") % 2 == 0):
return False
vs = filter_code_whole(msg)
for v in vs:
if can_be_solution("```" + v + "```", min_lines, check_func, check_string):
return True
return False
def find_largest_new_block(old_text: str, text: str) -> str:
return find_largest_new_block_code(
filter_code(old_text + "```").strip(), filter_code(text + "```").strip()
)
def find_largest_new_block_code(old_code: str, code: str) -> str:
while len(old_code) < len(code):
r = check_code(code)
if r["status"] == 0:
return code
try:
code = code[0 : code.rindex(stop_word)].strip()
except ValueError:
return None
return None