From 1961b4b237083f4cfac9ca6b249c1d6cb665d149 Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Tue, 14 Jul 2026 17:29:02 +0200 Subject: Initial (refactor) --- util/doc-check.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 util/doc-check.py (limited to 'util/doc-check.py') 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 +# +# 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 $", 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}") +] -- cgit v1.2.1