-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcoqwc.py
56 lines (49 loc) · 1.4 KB
/
coqwc.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
import re
import sys
def analyze_coq_file(file_path):
try:
with open(file_path, 'r') as file:
content = file.read()
except FileNotFoundError:
print(f"Error: File '{file_path}' not found.")
return
# Remove comments from the content
content = re.sub(r'\(\*.*?\*\)', '', content, flags=re.DOTALL)
# Patterns for specs/proofs
spec_pattern = (
r'\b(Definition|'
r'Fixpoint|'
r'Inductive|'
r'Record|'
r'CoInductive|'
r'Lemma|'
r'Theorem|'
r'Obligation|'
r'Next Obligation|'
r'Class|'
r'Import|'
r'Export|'
r'Context|'
r'Notation|'
r'Parameter|'
r'Hypothesis|'
r'Section|'
r'Instance)\b'
)
proof_pattern = r'Proof\.(.*?)Qed\.'
# Count definitions and lemmas
specs = re.findall(spec_pattern, content)
# Count proof steps
proofs = re.findall(proof_pattern, content, re.DOTALL)
proof_steps = sum(proof.count('.') + proof.count(';') for proof in proofs)
# Print results
print(f"File: {file_path}")
print(f"Spec Instructions: {len(specs)}")
print(f"Proof Instructions: {proof_steps}")
if __name__ == "__main__":
# Ensure the script is run with a file argument
if len(sys.argv) != 2:
print("Usage: python3 coqwc.py <file_name.v>")
else:
file_path = sys.argv[1]
analyze_coq_file(file_path)