Implement reader macros (#;, #|...|, #', #name) and #z3 demo
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 11m13s

Reader macros in parser.sx spec, Python parser.py, and hand-written sx.js:
- #; datum comment: read and discard next expression
- #|...|  raw string: no escape processing
- #' quote shorthand: (quote expr)
- #name extensible dispatch: registered handler transforms next expression

#z3 reader macro demo (reader_z3.py): translates define-primitive
declarations from primitives.sx into SMT-LIB verification conditions.
Same source, two interpretations — bootstrappers compile to executable
code, #z3 extracts proof obligations.

48 parser tests (SX spec + Python), all passing. Rebootstrapped JS+Python.
Demo page at /plans/reader-macro-demo with side-by-side examples.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-08 20:21:40 +00:00
parent 56589a81b2
commit 03ba8e58e5
12 changed files with 7625 additions and 26 deletions

View File

@@ -220,3 +220,40 @@
(deftest "roundtrip nested"
(assert-equal "(a (b c))"
(sx-serialize (first (sx-parse "(a (b c))"))))))
;; --------------------------------------------------------------------------
;; Reader macros
;; --------------------------------------------------------------------------
(defsuite "reader-macros"
(deftest "datum comment discards expr"
(assert-equal (list 42) (sx-parse "#;(ignored) 42")))
(deftest "datum comment in list"
(assert-equal (list (list 1 3)) (sx-parse "(1 #;2 3)")))
(deftest "datum comment discards nested"
(assert-equal (list 99) (sx-parse "#;(a (b c) d) 99")))
(deftest "raw string basic"
(assert-equal (list "hello") (sx-parse "#|hello|")))
(deftest "raw string with quotes"
(assert-equal (list "say \"hi\"") (sx-parse "#|say \"hi\"|")))
(deftest "raw string with backslashes"
(assert-equal (list "a\\nb") (sx-parse "#|a\\nb|")))
(deftest "raw string empty"
(assert-equal (list "") (sx-parse "#||")))
(deftest "quote shorthand symbol"
(let ((result (first (sx-parse "#'foo"))))
(assert-equal "quote" (symbol-name (first result)))
(assert-equal "foo" (symbol-name (nth result 1)))))
(deftest "quote shorthand list"
(let ((result (first (sx-parse "#'(1 2 3)"))))
(assert-equal "quote" (symbol-name (first result)))
(assert-equal (list 1 2 3) (nth result 1)))))