From b9e5a3d416682411b55f3a4ac4e8da741928d547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E4=B8=80=E9=B8=A3?= <1000000008@qq.com> Date: Wed, 28 Oct 2026 23:59:06 -0400 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=85=B7=EF=BC=9A=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=20C++=20=E6=8B=AC=E5=8F=B7=E9=85=8D=E5=B9=B3=E8=AF=AD=E6=B3=95?= =?UTF-8?q?=E8=87=AA=E6=A3=80=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/syntax_sanity.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tools/syntax_sanity.py diff --git a/tools/syntax_sanity.py b/tools/syntax_sanity.py new file mode 100644 index 0000000..cf12fc6 --- /dev/null +++ b/tools/syntax_sanity.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +"""Rough brace/paren balance sanity check for edited C++ files.""" +import os +import re +import sys + +os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), + "..", "terminal", "kiosk-shell")) + +FILES = [ + "src/main_window.cpp", + "src/main_window.h", + "src/desktop_list_page.cpp", + "src/desktop_list_page.h", + "src/desktop_service.cpp", + "src/desktop_service.h", + "src/desktop_session.h", + "src/moonlight_session.cpp", + "src/moonlight_session.h", + "src/login_page.cpp", + "src/login_page.h", + "src/state_machine.cpp", + "src/state_machine.h", +] + +fail = False +for f in FILES: + src = open(f, encoding="utf-8").read() + src2 = re.sub(r"//[^\n]*", "", src) + src2 = re.sub(r'"(?:\\.|[^"\\])*"', '""', src2) + src2 = re.sub(r"'(?:\\.|[^'\\])*'", "''", src2) + counts = {c: src2.count(c) for c in "{}()"} + ok = counts["{"] == counts["}"] and counts["("] == counts[")"] + print(f, counts, "OK" if ok else "MISMATCH") + if not ok: + fail = True + +sys.exit(1 if fail else 0)