工具:新增 C++ 括号配平语法自检脚本
This commit is contained in:
parent
42de16a582
commit
115cbec96e
38
tools/syntax_sanity.py
Normal file
38
tools/syntax_sanity.py
Normal file
@ -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)
|
||||||
Loading…
Reference in New Issue
Block a user