Avoid spreading some NILs when reading templates.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
diff --git a/template.lisp b/template.lisp
index f7865f6..50701f1 100644
--- a/template.lisp
+++ b/template.lisp
@@ -66,9 +66,14 @@
(flet ((read-plain (stream &optional char)
(declare (ignore char))
(let ((plain (with-output-to-string (out)
- (loop for c = (peek-char nil stream nil #\«)
+ (loop for c = (peek-char nil stream nil #\« t)
until (char= #\« c)
do (write-char (read-char stream) out)))))
+ (when (and *nested*
+ (char= #\« (peek-char nil stream nil #\Z t)))
+ (read-char stream t nil t)
+ (unless (char= #\Space (peek-char nil stream t nil t))
+ (unread-char #\« stream)))
(unless (= 0 (length plain))
(if *writing*
plain
@@ -81,14 +86,14 @@
( #\$ (car (push (the symbol var) *template-vars*))))))
(dispatch-template-eval (stream c n)
(declare (ignore c n))
- (unless *nested* (let ((*nested* t)) (read stream t nil t))))
+ (assert (not *nested*) nil "Template parse error: Nested « ")
+ (let ((*nested* t)) (read stream t nil t)))
(dispatch-template-eval-print (stream c n)
(declare (ignore c n))
- (if *writing*
- (error "Template parse error: Nested «=")
- (let ((*nested* t)
- (*writing* t))
- `(princ ,(read stream t nil t) *template-output*)))))
+ (assert (not *writing*) () "Template parse error: Nested «=")
+ (let ((*nested* t)
+ (*writing* t))
+ `(princ ,(read stream t nil t) *template-output*))))
(let ((rt (copy-readtable nil)))
(make-dispatch-macro-character #\« t rt)
(set-dispatch-macro-character #\« #\Space #'dispatch-template-eval rt)