forked from Timi16/soroban-debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_duplicates.py
More file actions
36 lines (29 loc) · 1.1 KB
/
Copy pathfix_duplicates.py
File metadata and controls
36 lines (29 loc) · 1.1 KB
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
import os
import re
def fix_duplicates(filename):
with open(filename, 'r', encoding='utf-8') as f:
content = f.read()
# regex to find struct literals and their contents
struct_pattern = re.compile(r'(DynamicTraceEvent\s*\{)(.*?)(\})', re.DOTALL)
def repl_struct(match):
prefix = match.group(1)
body = match.group(2)
suffix = match.group(3)
lines = body.split('\n')
seen_fields = set()
new_lines = []
for line in lines:
field_match = re.search(r'^\s*([a-zA-Z0-9_]+):', line)
if field_match:
field = field_match.group(1)
if field in seen_fields:
continue
seen_fields.add(field)
new_lines.append(line)
return prefix + '\n'.join(new_lines) + suffix
new_content = struct_pattern.sub(repl_struct, content)
with open(filename, 'w', encoding='utf-8') as f:
f.write(new_content)
if __name__ == '__main__':
fix_duplicates('src/analyzer/security.rs')
fix_duplicates('src/runtime/executor.rs')