import re
import glob
def fix_doc_line(line):
if not line.lstrip().startswith('///'):
return line
pattern1 = r'(\s)([a-zA-Z_][a-zA-Z0-9_]*\(\))(\s)'
line = re.sub(pattern1, r'\1`\2`\3', line)
pattern2 = r'(\s)([a-z_][a-z0-9_]*_[a-z0-9_]+)(\s|[.,;)\]])'
line = re.sub(pattern2, r'\1`\2`\3', line)
pattern3 = r'(\s)([A-Z][a-zA-Z0-9]*[A-Z][a-zA-Z0-9]*)(\s)'
line = re.sub(pattern3, r'\1`\2`\3', line)
return line
rust_files = glob.glob('src/**/*.rs', recursive=True)
total_changes = 0
for file_path in rust_files:
with open(file_path, 'r') as f:
lines = f.readlines()
new_lines = []
file_changes = 0
for line in lines:
new_line = fix_doc_line(line)
if new_line != line:
file_changes += 1
new_lines.append(new_line)
if file_changes > 0:
with open(file_path, 'w') as f:
f.writelines(new_lines)
print(f"✓ {file_path}: {file_changes} lines updated")
total_changes += file_changes
print(f"\nTotal: {total_changes} doc comments updated")