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) (#.sb!xc:char-code-limit)))
17 ;;; constants for readtable character attributes. These are all as in
19 (def!constant +char-attr-whitespace+ 0)
20 (def!constant +char-attr-terminating-macro+ 1)
21 (def!constant +char-attr-escape+ 2)
22 (def!constant +char-attr-constituent+ 3)
23 (def!constant +char-attr-constituent-dot+ 4)
24 (def!constant +char-attr-constituent-expt+ 5)
25 (def!constant +char-attr-constituent-slash+ 6)
26 (def!constant +char-attr-constituent-digit+ 7)
27 (def!constant +char-attr-constituent-sign+ 8)
28 ;; the "9" entry intentionally left blank for some reason -- WHN 19990806
30 ;; appropriated by CSR 2004-03-16
31 (def!constant +char-attr-constituent-decimal-digit+ 9)
32 (def!constant +char-attr-multiple-escape+ 10)
33 (def!constant +char-attr-package-delimiter+ 11)
34 (def!constant +char-attr-delimiter+ 12) ; (a fake for READ-UNQUALIFIED-TOKEN)
36 (sb!xc:defstruct (readtable (:conc-name nil)
37 (:predicate readtablep)
38 ;; ANSI requires a CL:COPY-READTABLE to do
39 ;; a deep copy, so the DEFSTRUCT-generated
40 ;; default is not suitable.
43 "A READTABLE is a data structure that maps characters into syntax
44 types for the Common Lisp expression reader."
45 ;; The CHARACTER-ATTRIBUTE-TABLE is a vector of CHAR-CODE-LIMIT
46 ;; integers for describing the character type. Conceptually, there
47 ;; are 4 distinct "primary" character attributes:
48 ;; +CHAR-ATTR-WHITESPACE+, +CHAR-ATTR-TERMINATING-MACRO+,
49 ;; +CHAR-ATTR-ESCAPE+, and +CHAR-ATTR-CONSTITUENT+. Non-terminating
50 ;; macros (such as the symbol reader) have the attribute
51 ;; +CHAR-ATTR-CONSTITUENT+.
53 ;; In order to make READ-TOKEN fast, all this information is stored
54 ;; in the character attribute table by having different varieties of
56 (character-attribute-table
57 (make-array sb!xc:char-code-limit
58 :element-type '(unsigned-byte 8)
59 :initial-element +char-attr-constituent+)
60 :type attribute-table)
61 ;; The CHARACTER-MACRO-TABLE is a vector of CHAR-CODE-LIMIT
62 ;; functions. One of these functions called with appropriate
63 ;; arguments whenever any non-WHITESPACE character is encountered
64 ;; inside READ-PRESERVING-WHITESPACE. These functions are used to
65 ;; implement user-defined read-macros, system read-macros, and the
66 ;; number-symbol reader.
67 (character-macro-table
68 (make-array sb!xc:char-code-limit :initial-element #'undefined-macro-char)
69 :type (simple-vector #.sb!xc:char-code-limit))
70 ;; an alist from dispatch characters to vectors of CHAR-CODE-LIMIT
71 ;; functions, for use in defining dispatching macros (like #-macro)
72 (dispatch-tables () :type list)
73 (readtable-case :upcase :type (member :upcase :downcase :preserve :invert)))