X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=lml.cl;h=96da5827cb4231b6aa75239eca84049c91928309;hb=0338c7108d71df744c3c60b225481a3b849e9b37;hp=6ad713cf9890c74339bdb98f80e1d7da6f14f730;hpb=0aef7827d849a0662274cb0eb6a532c2adf0165f;p=lml.git diff --git a/lml.cl b/lml.cl index 6ad713c..96da582 100644 --- a/lml.cl +++ b/lml.cl @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Aug 2002 ;;;; -;;;; $Id: lml.cl,v 1.8 2002/09/16 09:45:50 kevin Exp $ +;;;; $Id: lml.cl,v 1.12 2002/09/16 10:11:25 kevin Exp $ ;;;; ;;;; This file, part of LML, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -201,10 +201,15 @@ (html :xmlns "http://www.w3.org/1999/xhtml" ,@body))) +(defun new-string () + (make-array 1024 :fill-pointer 0 :adjustable t :element-type 'character)) + (set-macro-character #\[ #'(lambda (stream char) (declare (ignore char)) - (let ((curr-string (make-array 1024 :fill-pointer 0 :adjustable t :element-type 'character)) + (let ((forms '()) + (curr-string (new-string)) + (paren-level 0) (got-comma nil)) (do ((ch (read-char stream t nil t) (read-char stream t nil t))) ((eql ch #\])) @@ -212,21 +217,30 @@ (if (eql ch #\() ;; Starting top-level ,( (progn - (lml-print curr-string) - (setf (fill-pointer curr-string) 0) + (push `(lml-print ,curr-string) forms) + (setq curr-string (new-string)) (setq got-comma nil) (vector-push #\( curr-string) (do ((ch (read-char stream t nil t) (Read-char stream t nil t))) - ((eql ch #\))) + ((and (eql ch #\)) (zerop paren-level))) (when (eql ch #\]) (format *trace-output* "Syntax error reading #\]") (return nil)) + (case ch + (#\( + (incf paren-level)) + (#\) + (decf paren-level))) (vector-push-extend ch curr-string)) (vector-push-extend #\) curr-string) - (let ((result (eval (read-from-string curr-string)))) - (when result - (lml-print result))) - (setf (fill-pointer curr-string) 0)) + (let ((eval-string (read-from-string curr-string)) + (res (gensym))) + (push + `(let ((,res ,eval-string)) + (when ,res + (lml-print ,res))) + forms)) + (setq curr-string (new-string))) ;; read comma, then non #\( char (progn (unless (eql ch #\,) @@ -239,7 +253,7 @@ (progn (setq got-comma nil) (vector-push-extend ch curr-string))))) - (lml-print curr-string)) - t)) + (push `(lml-print ,curr-string) forms) + `(progn ,@(nreverse forms)))))