3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 (in-package "SB!IMPL")
14 (sb!xc:deftype attribute-table ()
15 '(simple-array (unsigned-byte 8) (#.char-code-limit)))
17 ;;; constants for readtable character attributes. These are all as in
19 (defconstant +char-attr-whitespace+ 0)
20 (defconstant +char-attr-terminating-macro+ 1)
21 (defconstant +char-attr-escape+ 2)
22 (defconstant +char-attr-constituent+ 3)
23 (defconstant +char-attr-constituent-dot+ 4)
24 (defconstant +char-attr-constituent-expt+ 5)
25 (defconstant +char-attr-constituent-slash+ 6)
26 (defconstant +char-attr-constituent-digit+ 7)
27 (defconstant +char-attr-constituent-sign+ 8)
28 ;; the "9" entry intentionally left blank for some reason -- WHN 19990806
29 (defconstant +char-attr-multiple-escape+ 10)
30 (defconstant +char-attr-package-delimiter+ 11)
31 (defconstant +char-attr-delimiter+ 12) ; (a fake for READ-UNQUALIFIED-TOKEN)
33 (sb!xc:defstruct (readtable (:conc-name nil)
34 (:predicate readtablep))
36 "A READTABLE is a data structure that maps characters into syntax
37 types for the Common Lisp expression reader."
38 ;; The CHARACTER-ATTRIBUTE-TABLE is a vector of CHAR-CODE-LIMIT
39 ;; integers for describing the character type. Conceptually, there
40 ;; are 4 distinct "primary" character attributes:
41 ;; +CHAR-ATTR-WHITESPACE+, +CHAR-ATTR-TERMINATING-MACRO+,
42 ;; +CHAR-ATTR-ESCAPE+, and +CHAR-ATTR-CONSTITUENT+. Non-terminating
43 ;; macros (such as the symbol reader) have the attribute
44 ;; +CHAR-ATTR-CONSTITUENT+.
46 ;; In order to make READ-TOKEN fast, all this information is stored
47 ;; in the character attribute table by having different varieties of
49 (character-attribute-table
50 (make-array char-code-limit
51 :element-type '(unsigned-byte 8)
52 :initial-element +char-attr-constituent+)
53 :type attribute-table)
54 ;; The CHARACTER-MACRO-TABLE is a vector of CHAR-CODE-LIMIT
55 ;; functions. One of these functions called with appropriate
56 ;; arguments whenever any non-WHITESPACE character is encountered
57 ;; inside READ-PRESERVING-WHITESPACE. These functions are used to
58 ;; implement user-defined read-macros, system read-macros, and the
59 ;; number-symbol reader.
60 (character-macro-table
61 (make-array char-code-limit :initial-element #'undefined-macro-char)
62 :type (simple-vector #.char-code-limit))
63 ;; an alist from dispatch characters to vectors of CHAR-CODE-LIMIT
64 ;; functions, for use in defining dispatching macros (like #-macro)
65 (dispatch-tables () :type list)
66 (readtable-case :upcase :type (member :upcase :downcase :preserve :invert)))