diff options
| author | Paul Oliver <contact@pauloliver.dev> | 2026-07-14 17:29:02 +0200 |
|---|---|---|
| committer | Paul Oliver <contact@pauloliver.dev> | 2026-08-30 16:24:48 +0200 |
| commit | 1961b4b237083f4cfac9ca6b249c1d6cb665d149 (patch) | |
| tree | fd9fc8260360e2ac30be9747ca558bcfc824a4c4 /util | |
Diffstat (limited to 'util')
| -rwxr-xr-x | util/doc-check.py | 43 |
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}") +] |
