Move reader macro utils to base.
[iolib/alendvai.git] / base / reader.lisp
blobff5b7d38830f703119d9da895a30fdd93b07298d
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; --- Reader utils
4 ;;;
6 (in-package :iolib.base)
8 ;; Reader macros
10 (defgeneric enable-reader-macro* (name))
12 (defgeneric disable-reader-macro* (name))
14 (defmacro enable-reader-macro (name)
15 `(eval-when (:compile-toplevel)
16 (enable-reader-macro* ,name)))
18 (defmacro disable-reader-macro (name)
19 `(eval-when (:compile-toplevel)
20 (disable-reader-macro* ,name)))
22 (defun save-old-readtable (symbol readtable)
23 (setf (getf (symbol-plist symbol) 'old-readtable) readtable))
25 (defun get-old-readtable (symbol)
26 (getf (symbol-plist symbol) 'old-readtable))
28 (defmethod enable-reader-macro* :before ((name symbol))
29 (save-old-readtable name *readtable*)
30 (setf *readtable* (copy-readtable)))
32 (defmethod disable-reader-macro* ((name symbol))
33 (assert (readtablep (get-old-readtable name)))
34 (setf *readtable* (get-old-readtable name))
35 (save-old-readtable name nil))
37 (defmacro define-syntax (name &body body)
38 `(defmethod enable-reader-macro* ((name (eql ',name)))
39 ,@body))