Skip to content

Instantly share code, notes, and snippets.

@faithandbrave
Created June 11, 2024 13:46
Show Gist options
  • Save faithandbrave/37cd895161f18aa619400f6ae2e70b31 to your computer and use it in GitHub Desktop.
Save faithandbrave/37cd895161f18aa619400f6ae2e70b31 to your computer and use it in GitHub Desktop.
import glob
import re
def split_compiler_line(line: str) -> (bool, str, [str]):
compilers = [
"- [Clang](/implementation.md#clang):",
"- [GCC](/implementation.md#gcc):",
"- [ICC](/implementation.md#icc):",
"- [Visual C++](/implementation.md#visual_cpp):",
]
for compiler in compilers:
if line.startswith(compiler):
return True, compiler, line[len(compiler):].strip().split(", ")
return False, "", ""
def compiler_emoji(data: str) -> str:
new_data = data
for line in data.splitlines():
is_comp, compiler, versions = split_compiler_line(line)
if not is_comp:
continue
if len(versions) == 0:
continue
if len(versions) == 1 and versions[0] in ("?", "??", "???", "", "未実装"):
continue
mark = "[mark verified]"
if len(versions) == 1:
patterns = [
r"\((.*?)時点で実装なし\)",
r"\((.*?)の時点では未実装\)",
r"\((.*?)時点で実装していない\)",
r"\((.*?) 現在未実装\)",
r"\((.*?) 現在未対応\)",
r"\?\?((.*?) の時点で未実装)",
]
for pattern in patterns:
m = re.match(pattern, versions[0])
if m:
versions = [m.group(1)]
mark = "[mark noimpl]"
break
new_versions = []
for version in versions:
new_versions.append("{} {}".format(version, mark))
new_versions_str = ", ".join(new_versions)
new_line = "{} {}".format(
compiler,
new_versions_str
)
new_data = new_data.replace(line, new_line)
return new_data
for path in glob.glob("site/**/*.md", recursive=True):
with open(path, 'r') as f:
data = f.read()
old = data
data = compiler_emoji(data)
if old != data and old != (data + "\n") and (old + "\n") != data:
print("hit {}".format(path))
with open(path, 'w') as f:
f.write(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment