Files
memex/projects/check-parens/README.org
Amr Gharbeia 4c55f135fb check-parens: use SBCL reader for 100% accurate paren validation
Replace Python regex-based string/comment stripper with SBCL's actual
reader. For each lisp block, feeds the code to read-from-string in a
loop (reading all forms). Correctly classifies: package errors (not a
paren problem), reader errors (extra/missing closes), EOF (missing
closes Handles all Common Lisp reader edge cases: character literals
(#\( #\) #\;), block comments, string escaping
2026-05-13 12:17:02 -04:00

44 lines
1.1 KiB
Org Mode

#+TITLE: check-parens
#+FILETAGS: :tool:lisp:org:
Standalone parentheseis checker for Lisp source blocks in Org files.
Scans all ~#+begin_src lisp … #+end_src~ blocks in an Org file, strips
string and comment content, and reports unbalanced parentheses per block.
== Usage
#+begin_src shell
check-parens <file.org> [<file.org> ...]
check-parens -v <file.org>
#+end_src
Exit 0 if all blocks are balanced and terminated, 1 otherwise.
== Output
~file.org: OK~ — all blocks balanced
~file.org: Block at line 27: +2 (missing 2 closes) — near …~
~file.org: Block at line 103: unterminated — no matching #+end_src~
The ~-v~ flag prints the full block content for each issue.
== Integration
Pre-commit hook:
#+begin_src shell
cat > .git/hooks/pre-commit <<'HOOK'
#!/bin/sh
for f in $(git diff --cached --name-only --diff-filter=ACM | grep '\.org$'); do
projects/check-parens/check-parens "$f" || exit 1
done
HOOK
chmod +x .git/hooks/pre-commit
#+end_src
== Dependencies
Python 3 + SBCL (for the reader-based validation).
SBCL must be at `/usr/bin/sbcl` (the default path).