summaryrefslogtreecommitdiff
path: root/util/doc-check.py
diff options
context:
space:
mode:
Diffstat (limited to 'util/doc-check.py')
-rwxr-xr-xutil/doc-check.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/util/doc-check.py b/util/doc-check.py
new file mode 100755
index 0000000..1f4351b
--- /dev/null
+++ b/util/doc-check.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env -S PYTHONDONTWRITEBYTECODE=1 python
+
+# file : util/doc-check.py
+# project : Salis-VM
+# author : Paul Oliver <contact@pauloliver.dev>
+#
+# Simple utility to check file sections match indices.
+# Enforced indexing style is inspired by ImGui.
+
+import pathlib
+import re
+
+def check_pattern(pattern, content, path):
+ if not re.findall(pattern, content, re.MULTILINE):
+ raise RuntimeError(f"Could not find pattern: '{pattern}' in '{path}'")
+
+def check_path(path, doc_prefix):
+ with open(path, "r") as f:
+ content = f.read()
+
+ check_pattern(fr"^{doc_prefix} file : {path}$", content, path)
+ check_pattern(fr"^{doc_prefix} project : Salis-VM$", content, path)
+ check_pattern(fr"^{doc_prefix} author : Paul Oliver <contact@pauloliver.dev>$", content, path)
+
+ entries = [s.strip() for s in re.findall(fr"^\s*{doc_prefix} \[section\] .*$", content, re.MULTILINE)]
+ entries_index = entries[len(entries) // 2:]
+ entries_content = entries[:len(entries) // 2]
+
+ if entries_index != entries_content:
+ raise RuntimeError(f"Index/section mismatch in: '{path}': {entries_index} != {entries_content}")
+
+prefix_map = {
+ "#": ("py", ),
+ "//": ("c", "cpp", "h"),
+ ";": ("asm", ),
+}
+
+[
+ check_path(path, f"\\s*{prefix}")
+ for prefix, extensions in prefix_map.items()
+ for extension in extensions
+ for path in pathlib.Path(".").rglob(f"*.{extension}")
+]