[Openmcl-devel] modify lisp reader such that :: is disallowed

Ron Garret ron at awun.net
Thu Jun 11 18:15:40 UTC 2009


On Jun 11, 2009, at 10:20 AM, Taoufik Dachraoui wrote:

> they did it for java

Yes, but they were starting with a clean slate and with sandboxing as  
an explicit design goal before they ever wrote a line of code.  You  
are starting with twenty years worth of legacy code and design that  
didn't take security into account at all.  The Java folks also had Guy  
Steele on their team.  And even then they still, as you yourself  
pointed out, did not solve all the security issues.

> I will not be disappointed if I learn something.

That's the spirit!  So since you seem to have the right attitude, I'll  
go ahead and show you what I came up with when I tried noodling around  
with this a long time ago.  My goal when I wrote this code was not  
security, but to co-opt the colon for other syntactic purposes having  
to do with esoteric language design issues.  This code was just an  
experiment, nowhere near ready for prime-time, but you may find it  
useful nonetheless.

(defun symbol-charp (c)
   (and (not (digit-char-p c *read-base*))
        (or (alpha-char-p c)
            (find c ":_ at ."))))

(defun symbol-cont-charp (c)
   (or (digit-char-p c *read-base*) (symbol-charp c) (find c "-")))

(defun colon-reader (s ch)
   (let ((chars (list ch)) ch2)
     (loop do (setf ch2 (read-char s nil nil))
       while (symbol-cont-charp ch2)
       do (push ch2 chars))
     (if ch2 (unread-char ch2 s))
     (intern (string-upcase (coerce (nreverse chars) 'string)))))

(let ((*readtable*
        (let* ((rt (copy-readtable nil)))
          (loop for i from 0 to 255
            do (let ((ch (code-char i)))
                 (when (symbol-charp ch)
                   (set-macro-character ch 'colon-reader t rt))))
          rt)))
   (let ((*read-base* 16))
     (dolist (x (read-from-string
                 "(abc .a a: a.b a[1] 1a -1a 1z -1z \"string\"  
def:ghi  ; comment
                  klm::opq 123 1.23 1.23e4 1.23d4 #xabc)"))
       (print (list x (type-of x))))))

rg




More information about the Openmcl-devel mailing list