readtable.lisp 2.16 KB
Newer Older
Liam M. Healy's avatar
Liam M. Healy committed
1
2
;; Define a new readtable
;; Liam Healy 2014-09-28 22:27:28EDT readtable.lisp
Liam M. Healy's avatar
Liam M. Healy committed
3
;; Time-stamp: <2015-04-17 17:44:34EDT readtable.lisp>
Liam M. Healy's avatar
Liam M. Healy committed
4

5
;; Copyright 2014, 2015 Liam M. Healy
Liam M. Healy's avatar
Liam M. Healy committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
;; Distributed under the terms of the GNU General Public License
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

(in-package :antik)
Liam M. Healy's avatar
Liam M. Healy committed
22
(export '(set-reader set-reader-in-file))
Liam M. Healy's avatar
Liam M. Healy committed
23

24
(named-readtables:defreadtable :antik
Liam M. Healy's avatar
Liam M. Healy committed
25
  (:merge :standard)
26
  (:macro-char #\# :dispatch))
27
28
29

(defun set-reader (&optional (readtable t) (default-float 'double-float))
  "If readtable is true, set the reader to enable the three Antik reader macros #_ (physical dimension quantity), #d (date/time), #m (grid). Set the reader to interpret float literals without an exponent marker to be the type specified. If nil, leave as-is."
Liam M. Healy's avatar
Liam M. Healy committed
30
  (when readtable (named-readtables:in-readtable :antik))
31
32
33
  (when default-float
    (setf *read-default-float-format* default-float)
    #+allegro (tpl:setq-default *read-default-float-format* default-float)))
Liam M. Healy's avatar
Liam M. Healy committed
34
35
36
37
38
39
40
41

(defmacro set-reader-in-file (&optional (readtable t) (default-float 'double-float))
  "If readtable is true, set the reader to enable the three Antik reader macros #_ (physical dimension quantity), #d (date/time), #m (grid). Set the reader to interpret float literals without an exponent marker to be the type specified. If nil, leave as-is."
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     ,@(when readtable `((named-readtables:in-readtable :antik)))
     ,@(when default-float
	 `((setf *read-default-float-format* ',default-float)
	  #+allegro (tpl:setq-default *read-default-float-format* ,default-float)))))