import re import sys def fix_documentation(file_path): with open(file_path, 'r') as f: content = f.read() # Pattern to match undocumented public structs struct_pattern = r'^(pub struct \w+)' # Pattern to match undocumented public enums enum_pattern = r'^(pub enum \w+)' # Pattern to match undocumented public fields field_pattern = r'^(\s+)(pub \w+: [^,]+),' lines = content.split('\n') result = [] i = 0 while i < len(lines): line = lines[i] # Check if this is an undocumented public struct/enum if re.match(r'^pub (struct|enum) \w+', line) and (i == 0 or not lines[i-1].strip().startswith('///')): # Extract the name for documentation name = re.search(r'pub (struct|enum) (\w+)', line).group(2) kind = re.search(r'pub (struct|enum) (\w+)', line).group(1) # Add basic documentation result.append(f'/// {name}') result.append(f'/// ') result.append(f'/// TODO: Add detailed documentation for this {kind}') # Check if this is an undocumented public field elif re.match(r'^\s+pub \w+:', line) and (i == 0 or not lines[i-1].strip().startswith('///')): # Extract field name field_match = re.search(r'pub (\w+):', line) if field_match: field_name = field_match.group(1) indent = re.match(r'^(\s+)', line).group(1) result.append(f'{indent}/// {field_name.replace("_", " ").title()}') result.append(line) i += 1 return '\n'.join(result) if __name__ == "__main__": if len(sys.argv) != 2: print("Usage: python fix_docs.py ") sys.exit(1) file_path = sys.argv[1] fixed_content = fix_documentation(file_path) with open(file_path, 'w') as f: f.write(fixed_content) print(f"Fixed documentation in {file_path}")