Commit 26ab046a251c9dc61b799c5eabb7a12f769f3b41

Thomas de Grivel 2013-12-23T10:29:37

Avoid spreading some NILs when reading templates.

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)