-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexandre Hanot
committed
Oct 10, 2023
1 parent
30318d1
commit 222fd23
Showing
3 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import os | ||
import fileinput | ||
import re | ||
|
||
a = re.compile(r"^#\[derive\((\s*[a-zA-Z0-9_]+\s*,)*(\s*[a-zA-Z0-9_]+\s*)\)]$") | ||
|
||
special = [ | ||
"Copy", | ||
"Clone", | ||
"Default", | ||
"Debug", | ||
"PartialEq", | ||
"Eq", | ||
"PartialOrd", | ||
"Ord", | ||
"Serialize", | ||
"Deserialize", | ||
] | ||
|
||
special = {x: i for i, x in enumerate(special)} | ||
|
||
for root, dirs, files in os.walk("."): | ||
if "target" in root: | ||
continue | ||
for name in files: | ||
path = root + os.sep + name | ||
|
||
if name.endswith(".rs"): | ||
print(path) | ||
for line in fileinput.input(path, inplace=True): | ||
if a.match(line): | ||
derives = line[9:-3] | ||
derives = [ | ||
(special.get(x.strip(), 100), x.strip()) | ||
for x in derives.split(",") | ||
] | ||
derives.sort() | ||
line = "#[derive(" + ", ".join(x[1] for x in derives) + ")]" | ||
print(line) | ||
else: | ||
print(line, end="") |