-
Notifications
You must be signed in to change notification settings - Fork 25
/
lang.py
107 lines (97 loc) · 2.52 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from lang_config import LANG
run_tests = False
if LANG == "Dafny":
from dafny import (
score_func,
score_func_whole,
verifier_feedback,
short_verifier_feedback,
filter_code,
filter_code_whole,
check_code,
)
elif LANG == "Coq":
from coq import (
score_func,
score_func_whole,
verifier_feedback,
short_verifier_feedback,
filter_code,
filter_code_whole,
check_code,
)
elif LANG == "Lean4":
from lean import (
score_func,
verifier_feedback,
filter_code,
check_code,
)
elif LANG == "Rust":
from rust import (
score_func,
verifier_feedback,
filter_code,
check_code,
)
elif LANG == "Scala":
from scala import (
score_func,
verifier_feedback,
filter_code,
check_code,
)
elif LANG == "Python":
from python import (
score_func,
score_func_whole,
verifier_feedback,
filter_code,
filter_code_whole,
check_code,
run_unittests,
)
run_tests = True
else:
assert False
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